2024-09-10 19:15:12 +00:00
|
|
|
package sum
|
|
|
|
|
2024-09-10 19:34:27 +00:00
|
|
|
import (
|
2024-09-10 19:40:56 +00:00
|
|
|
"reflect"
|
2024-09-10 19:34:27 +00:00
|
|
|
"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}
|
2024-09-10 19:40:56 +00:00
|
|
|
|
|
|
|
// NOTE: check if any two variables are the same
|
|
|
|
if !reflect.DeepEqual(got, exp) {
|
2024-09-10 19:34:27 +00:00
|
|
|
t.Errorf("got %d, expected %d", got, exp)
|
|
|
|
}
|
2024-09-10 19:15:12 +00:00
|
|
|
}
|