test: Add comprehensive tests for Day 2 Part 2 Problem Dampener functionality

This commit is contained in:
Ruidy (aider) 2024-12-02 08:24:35 +01:00
parent bc2091cb79
commit d74989b5c4
No known key found for this signature in database
GPG key ID: E00F51288CB857CC

View file

@ -54,4 +54,47 @@ defmodule AdventCode2024.Solutions.Day2Test do
assert Day2.solve("not numbers") == {:error, :invalid_format} assert Day2.solve("not numbers") == {:error, :invalid_format}
end end
end end
describe "solve_part2/1" do
test "correctly identifies safe reports with Problem Dampener from example data" do
input = """
7 6 4 2 1
1 2 7 8 9
9 7 6 2 1
1 3 2 4 5
8 6 4 4 1
1 3 6 7 9
"""
assert Day2.solve_part2(input) == {:ok, 4}
end
test "identifies a report made safe by removing middle number" do
input = "1 3 2 4 5\n"
assert Day2.solve_part2(input) == {:ok, 1}
end
test "identifies a report made safe by removing duplicate number" do
input = "8 6 4 4 1\n"
assert Day2.solve_part2(input) == {:ok, 1}
end
test "identifies an already safe report without needing removal" do
input = "1 3 6 7 9\n"
assert Day2.solve_part2(input) == {:ok, 1}
end
test "identifies an unsafe report that can't be made safe" do
input = "1 2 7 8 9\n"
assert Day2.solve_part2(input) == {:ok, 0}
end
test "handles empty input for part 2" do
assert Day2.solve_part2("") == {:error, :no_valid_reports}
end
test "handles invalid input format for part 2" do
assert Day2.solve_part2("not numbers") == {:error, :invalid_format}
end
end
end end