go-by-test/iteration/iter_test.go

28 lines
409 B
Go
Raw Permalink Normal View History

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)
}
}
2024-09-10 11:23:32 +00:00
func BenchmarkRepeat(b *testing.B) {
for i := 0; i < b.N; i++ {
Repeat("a", 5)
2024-09-10 11:23:32 +00:00
}
}