learn-go-with-tests/iteration/repeat_test.go

28 lines
387 B
Go
Raw Permalink Normal View History

2025-02-02 02:18:14 +00:00
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
}