33 lines
494 B
Go
33 lines
494 B
Go
package iteration
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestRepeat(t *testing.T) {
|
|
repeated := Repeat("a", 5)
|
|
expected := "aaaaa"
|
|
|
|
if repeated != expected {
|
|
t.Errorf("expected %v, got %v", expected, repeated)
|
|
}
|
|
}
|
|
|
|
func BenchmarkRepeat(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
Repeat("a", 5)
|
|
}
|
|
}
|
|
func BenchmarkStringsRepeat(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
StringsRepeat("a", 5)
|
|
}
|
|
}
|
|
|
|
func ExampleRepeat() {
|
|
data := Repeat("a", 5)
|
|
fmt.Println(data)
|
|
// Outputs: aaaaa
|
|
}
|