learn-go-with-tests/iteration/repeat_test.go
2025-02-01 21:18:14 -05:00

27 lines
387 B
Go

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