-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
100 lines (88 loc) · 1.97 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
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
package day01
import (
"fmt"
"reflect"
"testing"
)
func TestParse(t *testing.T) {
examples := []struct {
given string
expect []int
}{
{"1", []int{1}},
{"1212", []int{1, 2, 1, 2}},
}
for _, example := range examples {
name := fmt.Sprintf("Testing for input %s", example.given)
t.Run(name, func(t *testing.T) {
if got := parse(example.given); !reflect.DeepEqual(got, example.expect) {
t.Errorf("Fail - expected %v, got %v", example.expect, got)
}
})
}
}
func TestSolvePart1(t *testing.T) {
examples := []struct {
given string
expect int
}{
{"1122", 3},
{"1111", 4},
{"1234", 0},
{"91212129", 9},
}
for _, example := range examples {
name := fmt.Sprintf("Testing for input %s", example.given)
t.Run(name, func(t *testing.T) {
given := parse(example.given)
size := len(given)
if got := solvePart1(given, size); got != example.expect {
t.Errorf("Fail - expected %v, got %v", example.expect, got)
}
})
}
}
func TestSolvePart2(t *testing.T) {
examples := []struct {
given string
expect int
}{
{"1212", 6},
{"1221", 0},
{"123425", 4},
{"123123", 12},
{"12131415", 4},
}
for _, example := range examples {
name := fmt.Sprintf("Testing for input %s", example.given)
t.Run(name, func(t *testing.T) {
given := parse(example.given)
size := len(given)
if got := solvePart2(given, size); got != example.expect {
t.Errorf("Fail - expected %v, got %v", example.expect, got)
}
})
}
}
func TestSolve(t *testing.T) {
solve1, solve2 := solve(input)
expect1, expect2 := 1089, 1156
if solve1 != 1089 {
t.Errorf("Fail - part 1. Expected %d, got %d", expect1, solve1)
}
if solve2 != 1156 {
t.Errorf("Fail - part 2. Expected %d, got %d", expect2, solve2)
}
}
func BenchmarkSolvePart1(b *testing.B) {
data := parse(input)
for i := 0; i < b.N; i++ {
solvePart1(data, len(data))
}
}
func BenchmarkSolvePart2(b *testing.B) {
data := parse(input)
for i := 0; i < b.N; i++ {
solvePart2(data, len(data))
}
}