-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermutations_test.go
72 lines (67 loc) · 1.21 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
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"reflect"
"testing"
)
func Test_permString(t *testing.T) {
type args struct {
src string
left int
}
tests := []struct {
name string
args args
want []string
}{
{
name: "test-01",
args: args{
src: "abc",
left: 0,
},
want: []string{"abc", "acb", "bac", "bca", "cba", "cab"},
},
{
name: "test-02",
args: args{
src: "qwe",
left: 0,
},
want: []string{"qwe", "qew", "wqe", "weq", "ewq", "eqw"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := permString(tt.args.src, tt.args.left); !reflect.DeepEqual(got, tt.want) {
t.Errorf("permString() = %v, want %v", got, tt.want)
}
})
}
}
func Test_permInt(t *testing.T) {
type args struct {
v []int
i int
}
tests := []struct {
name string
args args
want [][]int
}{
{
name: "test-03",
args: args{
v: []int{1, 2, 3},
i: 0,
},
want: [][]int{{1, 2, 3}, {2, 1, 3}, {3, 2, 1}, {2, 3, 1}, {3, 1, 2}, {1, 3, 2}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := permInt(tt.args.v, tt.args.i); !reflect.DeepEqual(got, tt.want) {
t.Errorf("permInt() = %v, want %v", got, tt.want)
}
})
}
}