-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
56 lines (52 loc) · 1.2 KB
/
main_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
package main
import (
"testing"
)
func TestValid(t *testing.T) {
for n, tc := range []struct {
in string
out bool
}{
{"aa bb cc dd ee", true},
{"aa bb cc dd aa", false},
{"aa bb cc dd aaa", true},
} {
if got, want := valid(tc.in), tc.out; got != want {
t.Errorf("[%d] valid(%q) = %t, want %t", n, tc.in, got, want)
}
}
}
func TestValidWithAnagramCheck(t *testing.T) {
for n, tc := range []struct {
in string
out bool
}{
{"abcde fghij", true},
{"abcde xyz ecdab", false},
{"a ab abc abd abf abj", true},
{"iiii oiii ooii oooi oooo", true},
{"oiii ioii iioi iiio", false},
} {
if got, want := validWithAnagramCheck(tc.in), tc.out; got != want {
t.Errorf("[%d] validWithAnagramCheck(%q) = %t, want %t", n, tc.in, got, want)
}
}
}
func TestLetterOrderIndependentHash(t *testing.T) {
for n, tc := range []struct {
in string
out string
}{
{"", ""},
{"abc", "a1b1c1"},
{"cba", "a1b1c1"},
{"aabbcc", "a2b2c2"},
{"ccbbaa", "a2b2c2"},
{"acbbca", "a2b2c2"},
{"aaaaaaaaaabc", "a10b1c1"},
} {
if got, want := letterOrderIndependentHash(tc.in), tc.out; got != want {
t.Errorf("[%d] letterOrderIndependentHash(%q) = %q, want %q", n, tc.in, got, want)
}
}
}