go-by-test/iteration/iter_test.go

28 lines
409 B
Go

package iteration
import (
"fmt"
"testing"
)
func ExampleRepeat() {
repeated := Repeat("ab", 5)
fmt.Println(repeated)
// Output: ababababab
}
func TestRepeat(t *testing.T) {
repeated := Repeat("a", 5)
expected := "aaaaa"
if repeated != expected {
t.Errorf("expected %q but got %q", expected, repeated)
}
}
func BenchmarkRepeat(b *testing.B) {
for i := 0; i < b.N; i++ {
Repeat("a", 5)
}
}