iteration
This commit is contained in:
parent
fbb4226a84
commit
ef3c63d7f4
11
iteration/repeat.go
Normal file
11
iteration/repeat.go
Normal file
@ -0,0 +1,11 @@
|
||||
package iteration
|
||||
|
||||
const repeatCount = 5
|
||||
|
||||
func Repeat(character string) string {
|
||||
var repeated string
|
||||
for i := 0; i < repeatCount; i++ {
|
||||
repeated += character
|
||||
}
|
||||
return repeated
|
||||
}
|
18
iteration/repeat_test.go
Normal file
18
iteration/repeat_test.go
Normal file
@ -0,0 +1,18 @@
|
||||
package iteration
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestRepeat(t *testing.T) {
|
||||
repeated := Repeat("a")
|
||||
expected := "aaaaa"
|
||||
|
||||
if repeated != expected {
|
||||
t.Errorf("expected %q but got %q", expected, repeated)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkRepeat(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
Repeat("a")
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user