Skip to content

Commit a55879b

Browse files
committed
Add tests
1 parent 8d536bf commit a55879b

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

2024/lib/day21.ex

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ defmodule Day21a do
9595
end
9696

9797
def run do
98-
File.read!(".input.txt")
98+
File.read!(".input.txt") |> run
99+
end
100+
101+
def run(input) do
102+
input
99103
|> String.split("\n")
100104
|> Enum.map(fn code ->
101105
state = ~c"AAA"
@@ -242,7 +246,11 @@ defmodule Day21b do
242246
end
243247

244248
def run do
245-
File.read!(".input.txt")
249+
File.read!(".input.txt") |> run
250+
end
251+
252+
def run(input) do
253+
input
246254
|> String.split("\n")
247255
|> Enum.map(fn code ->
248256
state = 0..25 |> Enum.map(fn _ -> ?A end)

2024/test/day21_test.exs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
defmodule Day21Test do
2+
use ExUnit.Case
3+
4+
def example, do: "029A
5+
980A
6+
179A
7+
456A
8+
379A"
9+
10+
test "Part 1 Example" do
11+
assert Day21a.run(example()) == 126_384
12+
end
13+
14+
test "Part 2 Example" do
15+
assert Day21b.run(example()) == 154_115_708_116_294
16+
end
17+
end

2024/test/test_helper.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ExUnit.start()

0 commit comments

Comments
 (0)