go-by-test/sum/sum_test.go

28 lines
485 B
Go
Raw Normal View History

2024-09-10 19:15:12 +00:00
package sum
import "testing"
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)
}
})
t.Run("collection of any size", func(t *testing.T) {
numbers := []int{1, 2, 3}
got := Sum(numbers)
exp := 6
if got != exp {
t.Errorf("got %d, expected %d, given %v", got, exp, numbers)
}
})
2024-09-10 19:15:12 +00:00
}