diff --git a/testing/go.mod b/testing/helloworld/go.mod similarity index 61% rename from testing/go.mod rename to testing/helloworld/go.mod index f3d0661..fc2d902 100644 --- a/testing/go.mod +++ b/testing/helloworld/go.mod @@ -1,3 +1,3 @@ module main.go -go 1.25.5 +go 1.24.5 diff --git a/testing/hello_test.go b/testing/helloworld/hello_test.go similarity index 100% rename from testing/hello_test.go rename to testing/helloworld/hello_test.go diff --git a/testing/main.go b/testing/helloworld/main.go similarity index 100% rename from testing/main.go rename to testing/helloworld/main.go diff --git a/testing/iterations/Makefile b/testing/iterations/Makefile new file mode 100644 index 0000000..ea60b79 --- /dev/null +++ b/testing/iterations/Makefile @@ -0,0 +1,12 @@ +all: run + +build: + go build -o kek + +run: test + go run main.go +test: + go test + +clean: + rm kek diff --git a/testing/iterations/go.mod b/testing/iterations/go.mod new file mode 100644 index 0000000..fc2d902 --- /dev/null +++ b/testing/iterations/go.mod @@ -0,0 +1,3 @@ +module main.go + +go 1.24.5 diff --git a/testing/iterations/main.go b/testing/iterations/main.go new file mode 100644 index 0000000..cbb1b0c --- /dev/null +++ b/testing/iterations/main.go @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" +) + +const iterCycles = 5 + +func Repeat(char string) string { + var repeated string + for i := 0; i < iterCycles; i++ { + repeated += char + } + return repeated +} + +func main() { + fmt.Println(Repeat("kek")) +} diff --git a/testing/iterations/repeated_test.go b/testing/iterations/repeated_test.go new file mode 100644 index 0000000..eec617e --- /dev/null +++ b/testing/iterations/repeated_test.go @@ -0,0 +1,23 @@ +package main + +import "testing" + +func TestRepeat(t *testing.T) { + got := Repeat("a") + want := "aaaaa" + + assertionCheck(t, got, want) +} + +func BenchmarkRepeat(b *testing.B) { + for b.Loop() { + Repeat("a") + } +} + +func assertionCheck(t testing.TB, got, want string) { + t.Helper() + if got != want { + t.Errorf("got %q want %q", got, want) + } +}