Skip to content

Commit

Permalink
Created an adder function and implented a test.
Browse files Browse the repository at this point in the history
I also learned about how to use the example functionality to test code.
Finally, I learned about godocs and how to make my own!
  • Loading branch information
vedicpanda committed May 25, 2023
1 parent fa139ea commit 31ee7bb
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Integers/adder.go
Original file line number Diff line number Diff line change
@@ -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
}
24 changes: 24 additions & 0 deletions Integers/adder_test.go
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=

0 comments on commit 31ee7bb

Please sign in to comment.