2024-09-10 11:20:33 +00:00
|
|
|
package iteration
|
|
|
|
|
2024-09-10 11:30:09 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ExampleRepeat() {
|
2024-09-10 11:32:46 +00:00
|
|
|
repeated := Repeat("ab", 5)
|
2024-09-10 11:30:09 +00:00
|
|
|
fmt.Println(repeated)
|
|
|
|
// Output: ababababab
|
|
|
|
}
|
2024-09-10 11:20:33 +00:00
|
|
|
|
|
|
|
func TestRepeat(t *testing.T) {
|
2024-09-10 11:32:46 +00:00
|
|
|
repeated := Repeat("a", 5)
|
2024-09-10 11:20:33 +00:00
|
|
|
expected := "aaaaa"
|
|
|
|
|
|
|
|
if repeated != expected {
|
|
|
|
t.Errorf("expected %q but got %q", expected, repeated)
|
|
|
|
}
|
|
|
|
}
|
2024-09-10 11:23:32 +00:00
|
|
|
|
|
|
|
func BenchmarkRepeat(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
2024-09-10 11:32:46 +00:00
|
|
|
Repeat("a", 5)
|
2024-09-10 11:23:32 +00:00
|
|
|
}
|
|
|
|
}
|