forked from spring1843/go-dsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
permutations_test.go
32 lines (27 loc) · 1.13 KB
/
permutations_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
package backtracking
import (
"reflect"
"testing"
)
/*
TestPermutations tests solution(s) with the following signature and problem description:
func Permutations(input []int) [][]int
Given a list of integers like {1,2}, produce all possible combinations like {1,2},{2,1}.
*/
func TestPermutations(t *testing.T) {
tests := []struct {
nums []int
permutations [][]int
}{
{[]int{}, [][]int{}},
{[]int{1}, [][]int{{1}}},
{[]int{1, 2}, [][]int{{1, 2}, {2, 1}}},
{[]int{1, 2, 3}, [][]int{{1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 2, 1}, {3, 1, 2}}},
{[]int{1, 2, 3, 4}, [][]int{{1, 2, 3, 4}, {1, 2, 4, 3}, {1, 3, 2, 4}, {1, 3, 4, 2}, {1, 4, 3, 2}, {1, 4, 2, 3}, {2, 1, 3, 4}, {2, 1, 4, 3}, {2, 3, 1, 4}, {2, 3, 4, 1}, {2, 4, 3, 1}, {2, 4, 1, 3}, {3, 2, 1, 4}, {3, 2, 4, 1}, {3, 1, 2, 4}, {3, 1, 4, 2}, {3, 4, 1, 2}, {3, 4, 2, 1}, {4, 2, 3, 1}, {4, 2, 1, 3}, {4, 3, 2, 1}, {4, 3, 1, 2}, {4, 1, 3, 2}, {4, 1, 2, 3}}},
}
for i, test := range tests {
if got := Permutations(test.nums); !reflect.DeepEqual(test.permutations, got) {
t.Fatalf("Failed test case #%d. Want %#v got %#v", i, test.permutations, got)
}
}
}