forked from spring1843/go-dsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
equal_sum_subarrays_test.go
37 lines (32 loc) · 984 Bytes
/
equal_sum_subarrays_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
37
package array
import (
"reflect"
"testing"
)
/*
TestEqualSumSubArrays tests solution(s) with the following signature and problem description:
func EqualSubArrays(list []int) [][]int
Given an list of integers A, return two sub-arrays with equal sums without changing the
order of the elements in the list.
*/
func TestEqualSumSubArrays(t *testing.T) {
tests := []struct {
list []int
subArrays [][]int
}{
{[]int{}, [][]int{}},
{[]int{1}, [][]int{}},
{[]int{1, 2, 2, 3}, [][]int{}},
{[]int{1, 2, 3}, [][]int{{1, 2}, {3}}},
{[]int{2, 3, 5}, [][]int{{2, 3}, {5}}},
{[]int{1, 7, 3, 5}, [][]int{{1, 7}, {3, 5}}},
{[]int{-4, 1, 1, 1, 1}, [][]int{}},
{[]int{4, 1, 1, 1, 1}, [][]int{{4}, {1, 1, 1, 1}}},
{[]int{1, 1, 1, 1, 4}, [][]int{{1, 1, 1, 1}, {4}}},
}
for i, test := range tests {
if got := EqualSubArrays(test.list); !reflect.DeepEqual(got, test.subArrays) {
t.Fatalf("Failed test case #%d. Want %#v got %#v", i, test.subArrays, got)
}
}
}