-
Notifications
You must be signed in to change notification settings - Fork 0
/
day2_test.go
74 lines (57 loc) · 1.58 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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestDay2Part1PolicyChecker(t *testing.T) {
checker := day2Part1PolicyChecker
policy := passwordPolicy{1, 3, 'a'}
firstLine := checker("abcde", policy)
assert.True(t, firstLine)
policy = passwordPolicy{1, 3, 'b'}
secondLine := checker("cdefg", policy)
assert.False(t, secondLine)
policy = passwordPolicy{2, 9, 'c'}
thirdLine := checker("ccccccccc", policy)
assert.True(t, thirdLine)
}
func TestDay2Part2PolicyChecker(t *testing.T) {
checker := day2Part2PolicyChecker
policy := passwordPolicy{1, 3, 'a'}
firstPassword := checker("abcde", policy)
assert.True(t, firstPassword)
policy = passwordPolicy{1, 3, 'b'}
secondPassword := checker("cdefg", policy)
assert.False(t, secondPassword)
policy = passwordPolicy{2, 9, 'c'}
thirdPassword := checker("ccccccccc", policy)
assert.False(t, thirdPassword)
}
func BenchmarkDay2(b *testing.B) {
b.Run("part1", d2p1)
b.Run("part2", d2p2)
}
func d2p1(b *testing.B) {
checker := day2Part1PolicyChecker
policy1 := passwordPolicy{1, 3, 'a'}
policy2 := passwordPolicy{1, 3, 'b'}
policy3 := passwordPolicy{2, 9, 'c'}
b.ResetTimer()
for i := 0; i < b.N; i++ {
checker("abcde", policy1)
checker("cdefg", policy2)
checker("ccccccccc", policy3)
}
}
func d2p2(b *testing.B) {
checker := day2Part2PolicyChecker
policy1 := passwordPolicy{1, 3, 'a'}
policy2 := passwordPolicy{1, 3, 'b'}
policy3 := passwordPolicy{2, 9, 'c'}
b.ResetTimer()
for i := 0; i < b.N; i++ {
checker("abcde", policy1)
checker("cdefg", policy2)
checker("ccccccccc", policy3)
}
}