Skip to content

Commit e2f84f3

Browse files
committed
✨ (sum_tail_test): add empty slice test case
1 parent 0ac09ff commit e2f84f3

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

arrays-and-slices/sum_test.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,22 @@ func TestSum(t *testing.T) {
3030
}
3131

3232
func TestSumAll(t *testing.T) {
33+
t.Run("make the sums of some slices", func(t *testing.T) {
34+
got := SumAll([]int{1, 2}, []int{0, 9})
35+
want := []int{3, 9}
3336

34-
got := SumAll([]int{1, 2}, []int{0, 9})
35-
want := []int{3, 9}
37+
if !reflect.DeepEqual(got, want) {
38+
t.Errorf("got %v want %v", got, want)
39+
}
40+
})
3641

37-
if !reflect.DeepEqual(got, want) {
38-
t.Errorf("got %v want %v", got, want)
39-
}
42+
t.Run("safely sum empty slices", func(t *testing.T) {
43+
got := SumAllTails([]int{}, []int{3, 4, 5})
44+
want := []int{0, 9}
45+
if !reflect.DeepEqual(got, want) {
46+
t.Errorf("got %v, want %v", got, want)
47+
}
48+
})
4049
}
4150

4251
func TestSumAllTails(t *testing.T) {

0 commit comments

Comments
 (0)