-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06_test.go
111 lines (97 loc) · 2.52 KB
/
06_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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"os"
"testing"
)
func TestAOC2022061(t *testing.T) {
tests := []struct {
input string
preamble int
message int
}{
{
input: "mjqjpqmgbljsphdztnvjfqwrcgsmlb",
preamble: 7,
message: 19,
},
{
input: "bvwbjplbgvbhsrlpgdmjqwftvncz",
preamble: 5,
message: 23,
},
{
input: "nppdvjthqldpwncqszvftbrmjlhg",
preamble: 6,
message: 23,
},
{
input: "nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg",
preamble: 10,
message: 29,
},
{
input: "zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw",
preamble: 11,
message: 26,
},
}
for _, test := range tests {
got := AOC202206FindUnique(test.input, 4)
if got != test.preamble {
t.Errorf("AOC202206FindUnique(%s, 4) differs:\nwant: %d\ngot: %d", test.input, test.preamble, got)
}
got = AOC202206FindUniqueJump(test.input, 4)
if got != test.preamble {
t.Errorf("AOC202206FindUniqueJump(%s, 4) differs:\nwant: %d\ngot: %d", test.input, test.preamble, got)
}
got = AOC202206FindUniqueReverseJump(test.input, 4)
if got != test.preamble {
t.Errorf("AOC202206FindUniqueReverseJump(%s, 4) differs:\nwant: %d\ngot: %d", test.input, test.preamble, got)
}
got = AOC202206FindUnique(test.input, 14)
if got != test.message {
t.Errorf("AOC202206FindUnique(%s, 14) differs:\nwant: %d\ngot: %d", test.input, test.message, got)
}
got = AOC202206FindUniqueJump(test.input, 14)
if got != test.message {
t.Errorf("AOC202206FindUniqueJump(%s, 14) differs:\nwant: %d\ngot: %d", test.input, test.message, got)
}
got = AOC202206FindUniqueReverseJump(test.input, 14)
if got != test.message {
t.Errorf("AOC202206FindUniqueReverseJump(%s, 14) differs:\nwant: %d\ngot: %d", test.input, test.message, got)
}
}
}
func BenchmarkAOC202206FindUnique(b *testing.B) {
data, err := os.ReadFile("input/202206")
if err != nil {
b.Fatalf("can't open input: %v", err)
}
input := string(data)
b.ResetTimer()
for i := 0; i < b.N; i++ {
AOC202206FindUnique(input, 14)
}
}
func BenchmarkAOC202206FindUniqueJump(b *testing.B) {
data, err := os.ReadFile("input/202206")
if err != nil {
b.Fatalf("can't open input: %v", err)
}
input := string(data)
b.ResetTimer()
for i := 0; i < b.N; i++ {
AOC202206FindUniqueJump(input, 14)
}
}
func BenchmarkAOC202206FindUniqueReverseJump(b *testing.B) {
data, err := os.ReadFile("input/202206")
if err != nil {
b.Fatalf("can't open input: %v", err)
}
input := string(data)
b.ResetTimer()
for i := 0; i < b.N; i++ {
AOC202206FindUniqueReverseJump(input, 14)
}
}