You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
771 B
Go

package iteration
import (
"fmt"
"testing"
)
func TestRepeat(t *testing.T) {
t.Run("repeat simple letters", func(t *testing.T) {
repeated := Repeat("a", 6)
expected := "aaaaaa"
if repeated != expected {
t.Errorf("expected %q but got %q", expected, repeated)
}
})
t.Run("repeat words letters", func(t *testing.T) {
repeated := Repeat("dog", 5)
expected := "dogdogdogdogdog"
if repeated != expected {
t.Errorf("expected %q but got %q", expected, repeated)
}
})
}
// This test demonstrates benchmark testing https://pkg.go.dev/testing#hdr-Benchmarks
func BenchmarkRepeat(b *testing.B) {
for i := 0; i < b.N; i++ {
Repeat("a", 4)
}
}
func ExampleRepeat() {
repeated := Repeat("da", 5)
fmt.Println(repeated)
// Output: dadadadada
}