From 31ee7bbcbf31d0a16128f2477322deb306fd288d Mon Sep 17 00:00:00 2001 From: Vedic Date: Thu, 25 May 2023 16:13:02 -0500 Subject: [PATCH] Created an adder function and implented a test. I also learned about how to use the example functionality to test code. Finally, I learned about godocs and how to make my own! --- Integers/adder.go | 6 ++++++ Integers/adder_test.go | 24 ++++++++++++++++++++++++ go.mod | 7 +++++++ go.sum | 8 ++++++++ 4 files changed, 45 insertions(+) create mode 100644 Integers/adder.go create mode 100644 Integers/adder_test.go create mode 100644 go.sum diff --git a/Integers/adder.go b/Integers/adder.go new file mode 100644 index 0000000..810fa05 --- /dev/null +++ b/Integers/adder.go @@ -0,0 +1,6 @@ +package integers + +// Add takes two integers and returns the sum of them. +func Add(x, y int) int { + return x + y +} diff --git a/Integers/adder_test.go b/Integers/adder_test.go new file mode 100644 index 0000000..4a35c7d --- /dev/null +++ b/Integers/adder_test.go @@ -0,0 +1,24 @@ +package integers //using the package integers to group all of the integer manipulation functions together +//packages should be lowercase because there are still OS' that can't deal with mixed cases lol + +import ( + "fmt" + "testing" +) + +func TestAdder(t *testing.T) { + sum := Add(2, 2) + expected := 4 + if sum != expected { + t.Errorf("expected '%d' but got '%d'", expected, sum) + } +} + +// You can have Examples as part of the test suite +// if you wanted to see which tests are being executed use the -v tag +// Examples won't run without the //Output: 6 comment +func ExampleAdd() { + sum := Add(1, 5) + fmt.Println(sum) + //Output: 6 +} diff --git a/go.mod b/go.mod index da6c43d..a05839e 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,10 @@ module hello go 1.20 + +require ( + github.com/yuin/goldmark v1.4.13 // indirect + golang.org/x/mod v0.10.0 // indirect + golang.org/x/sys v0.8.0 // indirect + golang.org/x/tools v0.9.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..bd06f25 --- /dev/null +++ b/go.sum @@ -0,0 +1,8 @@ +github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= +golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/tools v0.9.1 h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo= +golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=