day 1 - part 2 - refactoring

This commit is contained in:
Stanislas Jouffroy 2024-12-02 16:21:56 +01:00
parent 5f492b3f66
commit eac54767b5
10 changed files with 5 additions and 5 deletions

View file

@ -0,0 +1,6 @@
3 4
4 3
2 5
1 3
3 9
3 3

View file

@ -0,0 +1,15 @@
from pathlib import Path
from aoc_2024.day1 import common
TEST_FILE = Path(__file__).parent / "test-data"
def test_get_lists():
assert common.get_lists(TEST_FILE)[0] == [3, 4, 2, 1, 3, 3]
assert common.get_lists(TEST_FILE)[1] == [4, 3, 5, 3, 9, 3]
def test_get_sorted_lists():
assert common.get_ordered_lists(TEST_FILE)[0] == [1, 2, 3, 3, 3, 4]
assert common.get_ordered_lists(TEST_FILE)[1] == [3, 3, 3, 4, 5, 9]

View file

View file

@ -0,0 +1,14 @@
from pathlib import Path
from aoc_2024.day1 import part1
def test_compute_distance():
list1 = [1, 2, 3, 3, 3, 4]
list2 = [3, 3, 3, 4, 5, 9]
assert part1.compute_distance(list1, list2) == 11
def test_main():
test_file = Path(__file__).parent / "test-data"
assert part1.main(test_file) == 11

View file

@ -0,0 +1,14 @@
from pathlib import Path
from aoc_2024.day1 import part2
def test_compute_similarity_score():
dict1 = {1: 1, 2: 1, 3: 3, 4: 1}
dict2 = {3: 3, 4: 1, 5: 1, 9: 1}
assert part2.compute_similarity_score(dict1, dict2) == 31
def test_main():
test_file = Path(__file__).parent / "test-data"
assert part2.main(test_file) == 31