From ff881930f5597746bbc727725b567daee6da30d3 Mon Sep 17 00:00:00 2001 From: Sebastian Steger Date: Wed, 20 Aug 2025 09:20:37 +0000 Subject: [PATCH] implement myMath module --- go/03-modules/go.mod | 5 +++++ go/03-modules/go.sum | 2 ++ go/03-modules/main.go | 16 +++++++++++++- go/03-modules/myMath/math_test.go | 35 +++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 go/03-modules/go.mod create mode 100644 go/03-modules/go.sum create mode 100644 go/03-modules/myMath/math_test.go diff --git a/go/03-modules/go.mod b/go/03-modules/go.mod new file mode 100644 index 0000000..b93913c --- /dev/null +++ b/go/03-modules/go.mod @@ -0,0 +1,5 @@ +module gitty.informatik.hs-mannheim.de/steger/pr3-code/go/03-modules/myMath + +go 1.25.0 + +require github.com/google/uuid v1.6.0 diff --git a/go/03-modules/go.sum b/go/03-modules/go.sum new file mode 100644 index 0000000..7790d7c --- /dev/null +++ b/go/03-modules/go.sum @@ -0,0 +1,2 @@ +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= diff --git a/go/03-modules/main.go b/go/03-modules/main.go index 7905807..ab01282 100644 --- a/go/03-modules/main.go +++ b/go/03-modules/main.go @@ -1,5 +1,19 @@ package main -func main() { +import ( + "fmt" + mm "gitty.informatik.hs-mannheim.de/steger/pr3-code/go/03-modules/myMath" + //_ "gitty.informatik.hs-mannheim.de/steger/pr3-code/go/03-modules/myMath" + + "github.com/google/uuid" + //run go get github.com/google/uuid + //or go mod tidy => go.sum +) + +func main() { + fmt.Println(mm.Add(1, 2)) + + id := uuid.New() + fmt.Println("Generated UUID:", id) } diff --git a/go/03-modules/myMath/math_test.go b/go/03-modules/myMath/math_test.go new file mode 100644 index 0000000..cf3fe11 --- /dev/null +++ b/go/03-modules/myMath/math_test.go @@ -0,0 +1,35 @@ +package myMath_test + +import ( + "testing" + + "gitty.informatik.hs-mannheim.de/steger/pr3-code/go/03-modules/myMath" +) + +func TestAdd(t *testing.T) { + sum := myMath.Add(2, 3) + if sum != 5 { + t.Errorf("Add(2,3) = %v, want %v", sum, 5) + } +} + +func TestMin(t *testing.T) { + type args struct { + in0 int + in1 int + } + tests := []struct { + name string + args args + want int + }{ + {"first greater", args{3, 2}, 2}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := myMath.Min(tt.args.in0, tt.args.in1); got != tt.want { + t.Errorf("Min() = %v, want %v", got, tt.want) + } + }) + } +}