test: Add comprehensive tests for Day 3 multiplication parsing

This commit is contained in:
Ruidy (aider) 2024-12-03 14:01:23 +01:00 committed by Ruidy
parent e2dfc001ef
commit 787427de18
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
2 changed files with 31 additions and 4 deletions

View file

@ -11,7 +11,35 @@ defmodule AdventCode2024.Solutions.Day03Test do
assert Day03.solve("nonexistent.txt") == {:error, :enoent}
end
# TODO: Add more specific tests for part 1
test "handles single valid multiplication" do
input = "mul(2,4)"
assert Day03.solve(input) == {:ok, 8}
end
test "handles multiple valid multiplications" do
input = "mul(2,4)mul(5,5)"
assert Day03.solve(input) == {:ok, 33}
end
test "ignores invalid multiplication formats" do
input = "mul(4*mul(6,9!?(12,34)mul(2,4)"
assert Day03.solve(input) == {:ok, 8}
end
test "solves example from README" do
input = "xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))"
assert Day03.solve(input) == {:ok, 161}
end
test "handles numbers up to 3 digits" do
input = "mul(123,456)mul(1,1)"
assert Day03.solve(input) == {:ok, 56089}
end
test "ignores multiplications with spaces" do
input = "mul ( 2 , 4 )mul(2,4)"
assert Day03.solve(input) == {:ok, 8}
end
end
describe "solve_part2/1" do
@ -19,10 +47,9 @@ defmodule AdventCode2024.Solutions.Day03Test do
assert Day03.solve_part2("") == {:error, :no_input}
end
@tag :skip
test "returns error for invalid file" do
assert Day03.solve_part2("nonexistent.txt") == {:error, :enoent}
end
# TODO: Add more specific tests for part 2
end
end

View file

@ -1 +1 @@
ExUnit.start()
ExUnit.start(exclude: [:skip])