Add integers package
This commit is contained in:
1 parent
323f4aa606
commit
c37e1c26e1
2 files changed
+27
No files matched your search
@@ -0,0 +1,6 @@
|
||||
package integers
|
||||
|
||||
// Add takes two integers and return the sum of them.
|
||||
func Add(a, b int) int {
|
||||
return a + b
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package integers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAdder(t *testing.T) {
|
||||
sum := Add(2, 2)
|
||||
expected := 4
|
||||
|
||||
if sum != expected {
|
||||
t.Errorf("expected %v, got %v", expected, sum)
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleAdd() {
|
||||
sum := Add(1, 5)
|
||||
fmt.Println(sum)
|
||||
// Output: 6
|
||||
}
|
||||
Reference in new issue
Block a user