-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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!
- Loading branch information
1 parent
fa139ea
commit 31ee7bb
Showing
4 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |