day 1 - part 1 - refactoring
This commit is contained in:
parent
42f3bcc63e
commit
b844fafd78
4 changed files with 16 additions and 20 deletions
|
@ -15,14 +15,10 @@ def compute_distance(list1, list2) -> int:
|
|||
return sum([abs(item2 - item1) for item1, item2 in zip(list1, list2)])
|
||||
|
||||
|
||||
def compute(data_file: Path) -> int:
|
||||
list1, list2 = get_ordered_lists(data_file)
|
||||
return compute_distance(list1, list2)
|
||||
|
||||
|
||||
def main():
|
||||
file = Path(__file__).parent / "input-data"
|
||||
print(compute(file))
|
||||
list1, list2 = get_ordered_lists(file)
|
||||
print(compute_distance(list1, list2))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
from pathlib import Path
|
||||
|
||||
from day1 import part1
|
||||
|
||||
TEST_FILE = Path(__file__).parent / "test-data"
|
||||
|
||||
|
||||
def test_first():
|
||||
assert part1.compute(TEST_FILE) == 11
|
||||
|
||||
|
||||
def test_get_lists():
|
||||
assert part1.get_ordered_lists(TEST_FILE)[0] == [1, 2, 3, 3, 3, 4]
|
||||
assert part1.get_ordered_lists(TEST_FILE)[1] == [3, 3, 3, 4, 5, 9]
|
14
tests/2024/day1/test_part1.py
Normal file
14
tests/2024/day1/test_part1.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
from pathlib import Path
|
||||
|
||||
from day1 import part1
|
||||
|
||||
TEST_FILE = Path(__file__).parent / "test-data"
|
||||
|
||||
|
||||
def test_first():
|
||||
assert part1.compute(TEST_FILE) == 11
|
||||
|
||||
|
||||
def test_get_lists():
|
||||
assert part1.get_ordered_lists(TEST_FILE)[0] == [1, 2, 3, 3, 3, 4]
|
||||
assert part1.get_ordered_lists(TEST_FILE)[1] == [3, 3, 3, 4, 5, 9]
|
Loading…
Add table
Add a link
Reference in a new issue