go-by-test/sum/sum_test.go

30 lines
522 B
Go

package sum
import (
"reflect"
"testing"
)
func TestSum(t *testing.T) {
t.Run("collection of 5 numbers", func(t *testing.T) {
numbers := []int{1, 2, 3, 4, 5}
got := Sum(numbers)
exp := 15
if got != exp {
t.Errorf("got %d, expected %d, given %v", got, exp, numbers)
}
})
}
func TestSumAll(t *testing.T) {
got := SumAll([]int{1, 2}, []int{0, 9})
exp := []int{3, 9}
// NOTE: check if any two variables are the same
if !reflect.DeepEqual(got, exp) {
t.Errorf("got %d, expected %d", got, exp)
}
}