|
| 1 | +import pytest |
| 2 | + |
| 3 | +from advent_of_code.year_2025.day_02 import ( |
| 4 | + check_id_valid, |
| 5 | + convert_range_string_to_pair, |
| 6 | + find_invalid_ids_in_range_string, |
| 7 | + parse_input, |
| 8 | + solve, |
| 9 | + sum_invalid_ids, |
| 10 | +) |
| 11 | + |
| 12 | + |
| 13 | +@pytest.mark.parametrize( |
| 14 | + "input, expected_output", |
| 15 | + [ |
| 16 | + [ |
| 17 | + [ |
| 18 | + "11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124" # noqa: E501 |
| 19 | + ], |
| 20 | + (1227775554, None), |
| 21 | + ], |
| 22 | + ], |
| 23 | +) |
| 24 | +def test_solver(input, expected_output): |
| 25 | + print(f"day_02_test_input:{input}") |
| 26 | + input_parsed = parse_input(input) |
| 27 | + print(f"input_parsed:{input_parsed}") |
| 28 | + result = solve(input_parsed) |
| 29 | + assert result == expected_output |
| 30 | + |
| 31 | + |
| 32 | +@pytest.mark.parametrize( |
| 33 | + "input, expected_invalid_ids", |
| 34 | + [ |
| 35 | + ["11-22", [11, 22]], |
| 36 | + ["95-115", [99]], |
| 37 | + ["998-1012", [1010]], |
| 38 | + ["1188511880-1188511890", [1188511885]], |
| 39 | + ["222220-222224", [222222]], |
| 40 | + ["1698522-1698528", []], |
| 41 | + ["446443-446449", [446446]], |
| 42 | + ["38593856-38593862", [38593859]], |
| 43 | + ["565653-565659", []], |
| 44 | + ["824824821-824824827", []], |
| 45 | + ["2121212118-2121212124", []], |
| 46 | + ], |
| 47 | +) |
| 48 | +def test_find_invalid_ids_in_range_string(input, expected_invalid_ids): |
| 49 | + assert expected_invalid_ids == find_invalid_ids_in_range_string(input) |
| 50 | + |
| 51 | + |
| 52 | +@pytest.mark.parametrize( |
| 53 | + "input, expected_output", |
| 54 | + [ |
| 55 | + ([1, 2, 3], 6), |
| 56 | + ], |
| 57 | +) |
| 58 | +def test_sum_invalid_ids(input, expected_output): |
| 59 | + assert expected_output == sum_invalid_ids(input) |
| 60 | + |
| 61 | + |
| 62 | +@pytest.mark.parametrize( |
| 63 | + "input, expected_pair", |
| 64 | + [ |
| 65 | + ("11-22", (11, 22)), |
| 66 | + ("95-115", (95, 115)), |
| 67 | + ("998-1012", (998, 1012)), |
| 68 | + ("1188511880-1188511890", (1188511880, 1188511890)), |
| 69 | + ], |
| 70 | +) |
| 71 | +def test_convert_range_string_to_pair(input, expected_pair): |
| 72 | + assert expected_pair == convert_range_string_to_pair(input) |
| 73 | + |
| 74 | + |
| 75 | +@pytest.mark.parametrize( |
| 76 | + "input, is_valid", |
| 77 | + [("11", False), ("12", True), ("22", False), ("998", True), ("1010", False)], |
| 78 | +) |
| 79 | +def test_check_id_valid(input, is_valid): |
| 80 | + assert is_valid == check_id_valid(input) |
0 commit comments