-
Notifications
You must be signed in to change notification settings - Fork 3
/
elixir_day13_test.exs
131 lines (102 loc) · 3.15 KB
/
elixir_day13_test.exs
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
defmodule ElixirDay13Test do
use ExUnit.Case
doctest ElixirDay13
alias ElixirDay13.Parse
test "Parses a file" do
got = Parse.parse_file("../input_small.txt")
want = %{
0 => %{depth: 3, scanner: 0, delta: 1},
1 => %{depth: 2, scanner: 0, delta: 1},
4 => %{depth: 4, scanner: 0, delta: 1},
6 => %{depth: 4, scanner: 0, delta: 1}
}
assert got == want
end
test "Advance_Scanners Basic" do
scanners = %{
0 => %{depth: 99, scanner: 0, delta: 1},
1 => %{depth: 2, scanner: 0, delta: 1}
}
advanced_once = scanners |> ElixirDay13.advance_scanners()
advanced_twice = advanced_once |> ElixirDay13.advance_scanners()
assert advanced_once[0].scanner == 1
assert advanced_once[1].scanner == 1
assert advanced_twice[0].scanner == 2
# Depth = 2, scanner is mod 2, resets to 0
assert advanced_twice[1].scanner == 0
end
test "advance_scanners_n" do
scanners = %{
0 => %{depth: 99, scanner: 0, delta: 1},
1 => %{depth: 2, scanner: 0, delta: 1},
2 => %{depth: 3, scanner: 0, delta: 1}
}
## 2
got = scanners |> ElixirDay13.advance_scanners_n(2)
want = scanners |> ElixirDay13.advance_scanners() |> ElixirDay13.advance_scanners()
assert got == want
## 3
got = scanners |> ElixirDay13.advance_scanners_n(3)
want =
scanners
|> ElixirDay13.advance_scanners()
|> ElixirDay13.advance_scanners()
|> ElixirDay13.advance_scanners()
assert got == want
## 4
got = scanners |> ElixirDay13.advance_scanners_n(4)
want =
scanners
|> ElixirDay13.advance_scanners()
|> ElixirDay13.advance_scanners()
|> ElixirDay13.advance_scanners()
|> ElixirDay13.advance_scanners()
assert got == want
end
test "Advance_Scanners Reverse Direction" do
scanners = %{
0 => %{depth: 3, scanner: 0, delta: 1}
}
assert scanners[0].scanner == 0
scanners = ElixirDay13.advance_scanners(scanners)
assert scanners[0].scanner == 1
scanners = ElixirDay13.advance_scanners(scanners)
assert scanners[0].scanner == 2
scanners = ElixirDay13.advance_scanners(scanners)
assert scanners[0].scanner == 1
scanners = ElixirDay13.advance_scanners(scanners)
assert scanners[0].scanner == 0
scanners = ElixirDay13.advance_scanners(scanners)
assert scanners[0].scanner == 1
scanners = ElixirDay13.advance_scanners(scanners)
assert scanners[0].scanner == 2
end
test "Part 1 Examples" do
got =
Parse.parse_file("../input_small.txt")
|> ElixirDay13.trip_severity()
want = 24
assert got == want
end
test "Part 1" do
got =
Parse.parse_file("../input.txt")
|> ElixirDay13.trip_severity()
want = 2264
assert got == want
end
test "Part 2 Examples" do
got =
Parse.parse_file("../input_small.txt")
|> ElixirDay13.part2_sim()
want = 10
assert got == want
got =
Parse.parse_file("../input_small.txt")
|> ElixirDay13.part2_mod()
want = 10
assert got == want
end
## Part 2 real. Answer should be 3875838
## Currently takes two minutes, too long for an automated test.
end