-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
71 lines (60 loc) · 1.44 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package day11
import (
"fmt"
"testing"
)
func TestNextPassword(t *testing.T) {
examples := []struct {
given string
expected string
}{
{"abxx", "abxy"},
{"xy", "xz"},
{"xz", "ya"},
{"ya", "yb"},
{"zzz", "aaa"},
}
for _, example := range examples {
name := fmt.Sprintf("testing for data %v", example.given)
t.Run(name, func(tt *testing.T) {
if got := nextString([]rune(example.given)); string(got) != example.expected {
tt.Errorf("Fail - expected %v but got %v", example.expected, string(got))
}
})
}
}
func TestNext(t *testing.T) {
examples := []struct {
given rune
expected rune
carry bool
}{
{'a', 'b', false},
{'c', 'd', false},
{'e', 'f', false},
{'z', 'a', true},
}
for _, example := range examples {
name := fmt.Sprintf("testing for data %v", example.given)
t.Run(name, func(tt *testing.T) {
if got, carry := nextChar(example.given); got != example.expected || carry != example.carry {
tt.Errorf("Fail - expected %v/%v but got %v/%v", example.expected, example.carry, got, carry)
}
})
}
}
func TestSolve(t *testing.T) {
solve1, solve2 := solve(input)
expected1, expected2 := "cqjxxyzz", "cqkaabcc"
if solve1 != expected1 {
t.Errorf("Fail - part 1. Expected %s, got %s", expected1, solve1)
}
if solve2 != expected2 {
t.Errorf("Fail - part 2. Expected %s, got %s", expected2, solve2)
}
}
func BenchmarkSolve(b *testing.B) {
for i := 0; i < b.N; i++ {
solve(input)
}
}