Add sub
Some checks failed
ci/woodpecker/push/pr Pipeline was successful
ci/woodpecker/push/push Pipeline failed

This commit is contained in:
Torjus Håkestad 2022-01-10 13:12:13 +01:00
parent 01296bd2e6
commit e2826d30e4
2 changed files with 25 additions and 0 deletions

View File

@ -3,3 +3,7 @@ package internal
func Add(a, b int) int {
return a + b
}
func Sub(a, b int) int {
return a - b
}

View File

@ -28,3 +28,24 @@ func TestAdd(t *testing.T) {
})
}
}
func TestSub(t *testing.T) {
var tc = []struct {
A int
B int
Expected int
}{
{A: 1, B: 0, Expected: 1},
{A: 1, B: 1, Expected: 0},
{A: 0, B: -5, Expected: -5},
}
for _, test := range tc {
name := fmt.Sprintf("%d-%d", test.A, test.B)
t.Run(name, func(t *testing.T) {
result := internal.Sub(test.A, test.B)
if result != test.Expected {
t.Errorf("Got %d, expected %d", result, test.Expected)
}
})
}
}