From 21e4b6f35a1271c3ef94474a68065785d272e64f Mon Sep 17 00:00:00 2001 From: janic Date: Mon, 22 Aug 2022 23:48:09 +0200 Subject: [PATCH] Test --- Dockerfile | 3 +++ pkg/main.go | 14 ++++++++++++++ pkg/main_test.go | 26 ++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 Dockerfile create mode 100644 pkg/main.go create mode 100644 pkg/main_test.go diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cb96eb9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,3 @@ +FROM archlinux:latest +RUN cat /etc/os-release +ENTRYPOINT ["bash"] diff --git a/pkg/main.go b/pkg/main.go new file mode 100644 index 0000000..f8b5c05 --- /dev/null +++ b/pkg/main.go @@ -0,0 +1,14 @@ +package main + +import "fmt" + +func Calculate(x int) (result int) { + result = x + 2 + return result +} + +func main() { + fmt.Println("Go Calculate") + result := Calculate(2) + fmt.Println(result) +} diff --git a/pkg/main_test.go b/pkg/main_test.go new file mode 100644 index 0000000..0667914 --- /dev/null +++ b/pkg/main_test.go @@ -0,0 +1,26 @@ +package main + +import "testing" + +func TestCalculate(t *testing.T) { + if Calculate(2) != 4 { + t.Error("Expected 2 + 2 equal 4") + } +} + +func TestTableCalculate(t *testing.T) { + var tests = []struct { + input int + expected int + }{ + {2, 4}, + {-3, -1}, + {0, 2}, + {99989988, 99989990}, + } + for _, test := range tests { + if output := Calculate(test.input); output != test.expected { + t.Errorf("Test Failed: %d, inputted: %d expected, recieved: %d", test.input, test.expected, output) + } + } +}