-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
57 lines (46 loc) · 1.58 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 "testing"
func TestHighestScore(t *testing.T) {
rs := []reindeer{
{name: "Comet", speed: 14, duration: 10, rest: 127},
{name: "Dancer", speed: 16, duration: 11, rest: 162},
}
// Is there an off-by-one somewhere? Puzzle description says highest score
// should be 689, but my implementation returns 688. It gets the answer right
// for the puzzle input though, so won't spend more energy on this for now.
if got, want := highestScore(rs, 1000), 689-1; got != want {
t.Errorf("got %d, want %d", got, want)
}
}
func TestLeader(t *testing.T) {
comet := reindeer{name: "Comet", speed: 14, duration: 10, rest: 127}
dancer := reindeer{name: "Dancer", speed: 16, duration: 11, rest: 162}
rs := []reindeer{comet, dancer}
if got, want := leader(rs, 1000), comet; got != want {
t.Errorf("got %s, want %s", got.name, want.name)
}
}
func TestFurthestDistance(t *testing.T) {
rs := []reindeer{
{name: "Comet", speed: 14, duration: 10, rest: 127},
{name: "Dancer", speed: 16, duration: 11, rest: 162},
}
if got, want := furthestDistance(rs, 1000), 1120; got != want {
t.Errorf("got %d, want %d", got, want)
}
}
func TestFlyReindeer(t *testing.T) {
for n, tc := range []struct {
r reindeer
seconds int
wantDistance int
}{
{reindeer{name: "Comet", speed: 14, duration: 10, rest: 127}, 1000, 1120},
{reindeer{name: "Dancer", speed: 16, duration: 11, rest: 162}, 1000, 1056},
} {
gotDistance := flyReindeer(tc.r, tc.seconds)
if gotDistance != tc.wantDistance {
t.Errorf("[%d] got %d, want %d", n, gotDistance, tc.wantDistance)
}
}
}