Add integers module
This commit is contained in:
22
integers/adder_test.go
Normal file
22
integers/adder_test.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package integers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAdder(t *testing.T) {
|
||||||
|
sum := Add(2, 2)
|
||||||
|
// Output: 9
|
||||||
|
expected := 4
|
||||||
|
|
||||||
|
if sum != expected {
|
||||||
|
t.Errorf("expected '%d' but got '%d'", expected, sum)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Runnable example testing
|
||||||
|
func ExampleAdd() {
|
||||||
|
fmt.Println(Add(2, 4))
|
||||||
|
// Output: 6
|
||||||
|
}
|
||||||
6
integers/integers.go
Normal file
6
integers/integers.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package integers
|
||||||
|
|
||||||
|
// Add two numbers together
|
||||||
|
func Add(x, y int) int {
|
||||||
|
return x + y
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user