Complete integer chapter
This commit is contained in:
parent
f743963a8f
commit
9aa40eb2c5
6
integers/adder.go
Normal file
6
integers/adder.go
Normal file
@ -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
|
||||
}
|
21
integers/adder_test.go
Normal file
21
integers/adder_test.go
Normal file
@ -0,0 +1,21 @@
|
||||
package integers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func ExampleAdd() {
|
||||
sum := Add(1, 5)
|
||||
fmt.Println(sum)
|
||||
// Output: 6
|
||||
}
|
||||
|
||||
func TestAdder(t *testing.T) {
|
||||
sum := Add(2, 2)
|
||||
expected := 4
|
||||
|
||||
if sum != expected {
|
||||
t.Errorf("expected '%d' but got '%d'", expected, sum)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user