-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
57 lines (51 loc) · 1.39 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
57
package main
import (
"slices"
"testing"
)
var input = []string{
"MMMSXXMASM",
"MSAMXMSMSA",
"AMXSXMAAMM",
"MSAMASMSMX",
"XMASAMXAMM",
"XXAMMXXAMA",
"SMSMSASXSS",
"SAXAMASAAA",
"MAMMMXMMMM",
"MXMXAXMASX",
}
func TestPart1(t *testing.T) {
if got, want := part1(input), 18; got != want {
t.Errorf("got %d, want %d", got, want)
}
}
func TestPart2(t *testing.T) {
if got, want := part2(input), 9; got != want {
t.Errorf("got %d, want %d", got, want)
}
}
func TestRotate(t *testing.T) {
input := []string{
"ABCDEF",
"GHIJKL",
"MNOPQR",
}
for _, tc := range []struct {
direction int
want []string
}{
{direction: 0, want: []string{"ABCDEF", "GHIJKL", "MNOPQR"}},
{direction: 1, want: []string{"F", "EL", "DKR", "CJQ", "BIP", "AHO", "GN", "M"}},
{direction: 2, want: []string{"FLR", "EKQ", "DJP", "CIO", "BHN", "AGM"}},
{direction: 3, want: []string{"R", "LQ", "FKP", "EJO", "DIN", "CHM", "BG", "A"}},
{direction: 4, want: []string{"RQPONM", "LKJIHG", "FEDCBA"}},
{direction: 5, want: []string{"M", "NG", "OHA", "PIB", "QJC", "RKD", "LE", "F"}},
{direction: 6, want: []string{"MGA", "NHB", "OIC", "PJD", "QKE", "RLF"}},
{direction: 7, want: []string{"A", "GB", "MHC", "NID", "OJE", "PKF", "QL", "R"}},
} {
if got, want := rotate(input, tc.direction), tc.want; !slices.Equal(got, want) {
t.Errorf("[direction %d] got %v, want %v", tc.direction, got, want)
}
}
}