+2
-4
Go/iteration/repeat.go
+2
-4
Go/iteration/repeat.go
+8
-6
Go/iteration/repeat_test.go
+8
-6
Go/iteration/repeat_test.go
···
3
3
import "testing"
4
4
5
5
func TestRepeat(t *testing.T) {
6
-
repeated := Repeat("a")
7
-
expected := "aaaaa"
6
+
t.Run("should repeat the number of times passed to function", func(t *testing.T) {
7
+
repeated := Repeat("a", 3)
8
+
expected := "aaa"
8
9
9
-
if repeated != expected {
10
-
t.Errorf("expected %q but got %q", expected, repeated)
11
-
}
10
+
if repeated != expected {
11
+
t.Errorf("expected %q but got %q", expected, repeated)
12
+
}
13
+
})
12
14
}
13
15
14
16
func BenchmarkRepeat(b *testing.B) {
15
17
for i := 0; i < b.N; i++ {
16
-
Repeat("a")
18
+
Repeat("a", 5)
17
19
}
18
20
}