go-by-test/sum/sum_test.go

28 lines
471 B
Go
Raw Normal View History

2024-09-10 19:15:12 +00:00
package sum
2024-09-10 19:34:27 +00:00
import (
"slices"
"testing"
)
2024-09-10 19:15:12 +00:00
func TestSum(t *testing.T) {
2024-09-10 19:27:13 +00:00
t.Run("collection of 5 numbers", func(t *testing.T) {
numbers := []int{1, 2, 3, 4, 5}
2024-09-10 19:15:12 +00:00
2024-09-10 19:27:13 +00:00
got := Sum(numbers)
exp := 15
2024-09-10 19:15:12 +00:00
2024-09-10 19:27:13 +00:00
if got != exp {
t.Errorf("got %d, expected %d, given %v", got, exp, numbers)
}
})
2024-09-10 19:34:27 +00:00
}
2024-09-10 19:27:13 +00:00
2024-09-10 19:34:27 +00:00
func TestSumAll(t *testing.T) {
got := SumAll([]int{1, 2}, []int{0, 9})
exp := []int{3, 9}
if slices.Compare(got, exp) != 0 {
t.Errorf("got %d, expected %d", got, exp)
}
2024-09-10 19:15:12 +00:00
}