-
Notifications
You must be signed in to change notification settings - Fork 0
/
day2_test.go
93 lines (84 loc) · 1.88 KB
/
day2_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
92
93
package main
import (
"testing"
)
func TestBoxLetterCount(t *testing.T) {
testCases := []struct {
boxID string
wantTwice int
wantThrice int
}{
{"abcdef", 0, 0},
{"bababc", 1, 1},
{"abbcde", 1, 0},
{"abcccd", 0, 1},
{"aabcdd", 1, 0},
{"abcdee", 1, 0},
{"ababab", 0, 1},
}
for _, tc := range testCases {
t.Run(tc.boxID, func(t *testing.T) {
gotTwice, gotThrice := BoxLetterCount(tc.boxID)
if gotTwice != tc.wantTwice {
t.Errorf("got %d; want %d", gotTwice, tc.wantTwice)
}
if gotThrice != tc.wantThrice {
t.Errorf("got %d; want %d", gotThrice, tc.wantThrice)
}
})
}
}
func TestBoxSetCount(t *testing.T) {
testCases := []struct {
boxIDs []string
want int
}{
{[]string{"abcdef", "bababc", "abbcde", "abcccd", "aabcdd", "abcdee", "ababab"}, 12},
}
for _, tc := range testCases {
t.Run(tc.boxIDs[0], func(t *testing.T) {
got := BoxSetCount(tc.boxIDs...)
if got != tc.want {
t.Errorf("got %d; want %d", got, tc.want)
}
})
}
}
func TestBoxProximity(t *testing.T) {
testCases := []struct {
boxA string
boxB string
wantDiff int
wantSame string
}{
{"abcde", "axcye", 2, "ace"},
{"fghij", "fguij", 1, "fgij"},
}
for _, tc := range testCases {
t.Run(tc.boxA, func(t *testing.T) {
gotDiff, gotSame := BoxProximity(tc.boxA, tc.boxB)
if gotDiff != tc.wantDiff {
t.Errorf("got %d; want %d", gotDiff, tc.wantDiff)
}
if gotSame != tc.wantSame {
t.Errorf("got %s; want %s", gotSame, tc.wantSame)
}
})
}
}
func TestBoxSetProximity(t *testing.T) {
testCases := []struct {
boxIDs []string
want string
}{
{[]string{"abcde", "fghij", "klmno", "pqrst", "fguij", "axcye", "wvxyz"}, "fgij"},
}
for _, tc := range testCases {
t.Run(tc.boxIDs[0], func(t *testing.T) {
got := BoxSetProximity(tc.boxIDs...)
if got != tc.want {
t.Errorf("got %s; want %s", got, tc.want)
}
})
}
}