-
Notifications
You must be signed in to change notification settings - Fork 1
/
ispermutation_test.go
91 lines (68 loc) · 2.79 KB
/
ispermutation_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package ranges
import "testing"
func TestIsPermutation(t *testing.T) {
t.Parallel()
if !IsPermutation[int](Only[int](), Only[int]()) {
t.Error("Two empty ranges were not pemutations of each other")
}
if IsPermutation[int](Only(1), Only[int]()) {
t.Error("A non-empty range was considered a permutation of an empty one")
}
if IsPermutation[int](Only[int](), Only(1)) {
t.Error("An empty range was considered a permutation of a non-empty one")
}
if !IsPermutation[int](Only(1, 2, 3), Only(1, 2, 3)) {
t.Error("(1, 2, 3) was not considered a permutation of (1, 2, 3)")
}
if !IsPermutation[int](Only(3, 2, 1), Only(1, 2, 3)) {
t.Error("(3, 2, 1) was not considered a permutation of (1, 2, 3)")
}
if !IsPermutation[int](Only(1, 2, 3), Only(3, 2, 1)) {
t.Error("(1, 2, 3) was not considered a permutation of (3, 2, 1)")
}
if !IsPermutation[int](Only(1, 2, 3), Only(3, 2, 1)) {
t.Error("(1, 2, 3) was not considered a permutation of (3, 2, 1)")
}
if IsPermutation[int](Only(1, 2, 2, 3, 3, 3), Only(3, 2, 1)) {
t.Error("(1, 2, 2, 3, 3, 3) was considered a permutation of (3, 2, 1)")
}
if IsPermutation[int](Only(3, 2, 1), Only(1, 2, 2, 3, 3, 3)) {
t.Error("(3, 2, 1) was considered a permutation of (1, 2, 2, 3, 3, 3)")
}
if !IsPermutation[int](Only(3, 2, 1, 3, 3, 2), Only(1, 2, 2, 3, 3, 3)) {
t.Error("(3, 2, 1, 3, 3, 2) was not considered a permutation of (1, 2, 2, 3, 3, 3)")
}
}
func TestIsPermutationNoAlloc(t *testing.T) {
t.Parallel()
if !IsPermutationNoAlloc(Only[int](), Only[int]()) {
t.Error("Two empty ranges were not pemutations of each other")
}
if IsPermutationNoAlloc(Only(1), Only[int]()) {
t.Error("A non-empty range was considered a permutation of an empty one")
}
if IsPermutationNoAlloc(Only[int](), Only(1)) {
t.Error("An empty range was considered a permutation of a non-empty one")
}
if !IsPermutationNoAlloc(Only(1, 2, 3), Only(1, 2, 3)) {
t.Error("(1, 2, 3) was not considered a permutation of (1, 2, 3)")
}
if !IsPermutationNoAlloc(Only(3, 2, 1), Only(1, 2, 3)) {
t.Error("(3, 2, 1) was not considered a permutation of (1, 2, 3)")
}
if !IsPermutationNoAlloc(Only(1, 2, 3), Only(3, 2, 1)) {
t.Error("(1, 2, 3) was not considered a permutation of (3, 2, 1)")
}
if !IsPermutationNoAlloc(Only(1, 2, 3), Only(3, 2, 1)) {
t.Error("(1, 2, 3) was not considered a permutation of (3, 2, 1)")
}
if IsPermutationNoAlloc(Only(1, 2, 2, 3, 3, 3), Only(3, 2, 1)) {
t.Error("(1, 2, 2, 3, 3, 3) was considered a permutation of (3, 2, 1)")
}
if IsPermutationNoAlloc(Only(3, 2, 1), Only(1, 2, 2, 3, 3, 3)) {
t.Error("(3, 2, 1) was considered a permutation of (1, 2, 2, 3, 3, 3)")
}
if !IsPermutationNoAlloc(Only(3, 2, 1, 3, 3, 2), Only(1, 2, 2, 3, 3, 3)) {
t.Error("(3, 2, 1, 3, 3, 2) was not considered a permutation of (1, 2, 2, 3, 3, 3)")
}
}