-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperm__test.go
58 lines (55 loc) · 955 Bytes
/
perm__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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package practice
import (
"reflect"
"sort"
"testing"
)
func TestPerm(t *testing.T) {
for _, tt := range []struct {
Input string
Output []string
}{
{"a", []string{"a"}},
{"ab", []string{"ab", "ba"}},
{"abc", []string{
"abc",
"acb",
"bac",
"bca",
"cab",
"cba",
}},
} {
actual := Perm(tt.Input)
sort.Strings(actual)
if !reflect.DeepEqual(tt.Output, actual) {
t.Fatalf("Expected: %v, Actual: %v", tt.Output, actual)
}
}
}
func TestPermChan(t *testing.T) {
for _, tt := range []struct {
Input string
Output []string
}{
{"a", []string{"a"}},
{"ab", []string{"ab", "ba"}},
{"abc", []string{
"abc",
"acb",
"bac",
"bca",
"cab",
"cba",
}},
} {
actual := []string{}
for str := range PermChan(tt.Input) {
actual = append(actual, str)
}
sort.Strings(actual)
if !reflect.DeepEqual(tt.Output, actual) {
t.Fatalf("Expected: %v, Actual: %v", tt.Output, actual)
}
}
}