master
1package main
2
3import "fmt"
4import "testing"
5
6func TestRepeat(t *testing.T) {
7 t.Run("default", func(t *testing.T) {
8 repeated := Repeat("a", 5)
9 expected := "aaaaa"
10
11 if repeated != expected {
12 t.Errorf("expected %q but got %q", expected, repeated)
13 }
14 })
15
16 t.Run("custom interval", func(t *testing.T) {
17 repeated := Repeat("a", 10)
18 expected := "aaaaaaaaaa"
19
20 if repeated != expected {
21 t.Errorf("expected %q but got %q", expected, repeated)
22 }
23 })
24}
25
26func BenchmarkRepeat(b *testing.B) {
27 for i := 0; i < b.N; i++ {
28 Repeat("a", 5)
29 }
30}
31
32func ExampleRepeat() {
33 fmt.Println(Repeat("x", 10))
34 // Output: xxxxxxxxxx
35}