this repo has no description
1package main
2
3import "testing"
4
5func Test_hasSetOfN(t *testing.T) {
6 tests := []struct {
7 in []byte
8 n int
9 expect bool
10 }{
11 {[]byte("yya"), 2, true},
12 {[]byte("abbbbcdefghijaklmmmno"), 2, true},
13 {[]byte("abc"), 2, false},
14 {[]byte("abcdefghijk"), 2, false},
15 {[]byte("abbcddefghijk"), 2, true},
16 {[]byte("aaabcdefff"), 3, true},
17 {[]byte("aabcdeff"), 3, false},
18 {[]byte("abcdefff"), 3, true},
19 }
20 for i, test := range tests {
21 got := hasSetOfN(test.in, test.n)
22 if got != test.expect {
23 t.Errorf("#%d: expected %v, got %v", i, test.expect, got)
24 }
25 }
26}
27
28func Test_checksup(t *testing.T) {
29 tests := []struct {
30 in []string
31 expect int
32 }{
33 {
34 []string{
35 "abcdef",
36 "bababc",
37 "abbcde",
38 "abcccd",
39 "aabcdd",
40 "abcdee",
41 "ababab",
42 },
43 12,
44 },
45 }
46 for i, test := range tests {
47 got := checksum(test.in)
48 if got != test.expect {
49 t.Errorf("#%d: expected %v, got %v", i, test.expect, got)
50 }
51 }
52}
53
54func Test_commonIDString(t *testing.T) {
55 tests := []struct {
56 in []string
57 expect string
58 }{
59 {
60 []string{
61 "abcde",
62 "fghij",
63 "klmno",
64 "pqrst",
65 "fguij",
66 "axcye",
67 "wvxyz",
68 },
69 "fgij",
70 },
71 }
72 for i, test := range tests {
73 got, err := commonIDString(test.in)
74 if err != nil {
75 t.Errorf("#%d: err: %v", i, err)
76 }
77 if got != test.expect {
78 t.Errorf("#%d: expected %v, got %v", i, test.expect, got)
79 }
80 }
81}
82
83func Test_onlyOneMismatch(t *testing.T) {
84 tests := []struct {
85 in []string
86 expect bool
87 }{
88 {[]string{"fghij", "fguij"}, true},
89 {[]string{"fghij", "fhuij"}, false},
90 }
91 for i, test := range tests {
92 got := onlyOneMismatch(test.in[0], test.in[1])
93 if got != test.expect {
94 t.Errorf("#%d: expected %v, got %v", i, test.expect, got)
95 }
96 }
97}
98
99func Test_commonString(t *testing.T) {
100 tests := []struct {
101 in []string
102 expect string
103 }{
104 {[]string{"fghij", "fguij"}, "fgij"},
105 }
106 for i, test := range tests {
107 got := commonString(test.in[0], test.in[1])
108 if got != test.expect {
109 t.Errorf("#%d: expected %v, got %v", i, test.expect, got)
110 }
111 }
112}