forked from spring1843/go-dsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zero_sum_triplets_test.go
36 lines (31 loc) · 969 Bytes
/
zero_sum_triplets_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package array
import (
"reflect"
"testing"
)
/*
TestZeroSumTriplets tests solution(s) with the following signature and problem description:
ZeroSumTriplets(list []int) [][]int
Given an array of numbers like {1, 2, -4, 6, 3} returns unique triplets from the numbers
with sum that equals zero like {-4, 1, 3}.
*/
func TestZeroSumTriplets(t *testing.T) {
tests := []struct {
list []int
triplets [][]int
}{
{[]int{}, [][]int{}},
{[]int{1}, [][]int{}},
{[]int{1, 2}, [][]int{}},
{[]int{1, 2, 3}, [][]int{}},
{[]int{1, -4, 3}, [][]int{{-4, 1, 3}}},
{[]int{1, 2, -4, 6, 3}, [][]int{{-4, 1, 3}}},
{[]int{-1, -2, -8, 6, 2, 3}, [][]int{{-8, 2, 6}, {-2, -1, 3}}},
{[]int{1, -2, -4, 5, -2, 4, 1, 3}, [][]int{{-4, 1, 3}, {-2, -2, 4}, {-2, 1, 1}}},
}
for i, test := range tests {
if got := ZeroSumTriplets(test.list); !reflect.DeepEqual(got, test.triplets) {
t.Fatalf("Failed test case #%d. Want %#v got %#v", i, test.triplets, got)
}
}
}