From cfab2d02a9b82fb74288f5884c8910a16a162022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krejczinger=20=C3=81rp=C3=A1d?= Date: Sun, 15 Mar 2026 23:25:51 +0100 Subject: [PATCH] Add iteration module --- iteration/iteration.go | 12 ++++++++++++ iteration/iteration_test.go | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 iteration/iteration.go create mode 100644 iteration/iteration_test.go diff --git a/iteration/iteration.go b/iteration/iteration.go new file mode 100644 index 0000000..1a75dcc --- /dev/null +++ b/iteration/iteration.go @@ -0,0 +1,12 @@ +package iteration + +const repeatCount = 5 + +func Repeat(character string) string { + var repeated string + for range repeatCount { + repeated = repeated + character + } + + return repeated +} diff --git a/iteration/iteration_test.go b/iteration/iteration_test.go new file mode 100644 index 0000000..253fc2a --- /dev/null +++ b/iteration/iteration_test.go @@ -0,0 +1,22 @@ +package iteration + +import "testing" + +func TestRepeat(t *testing.T) { + got := Repeat("a") + want := "aaaaa" + assertResult(t, got, want) +} + +func assertResult(t testing.TB, got, want string) { + t.Helper() + if got != want { + t.Errorf("got %q want %q", got, want) + } +} + +func BenchmarkRepeat(b *testing.B) { + for b.Loop() { + Repeat("a") + } +}