Add python script

This commit is contained in:
2026-05-19 17:09:13 -04:00
parent 5fa829a544
commit 9f445b666d
6 changed files with 148 additions and 0 deletions

32
day2/test_day2.py Normal file
View File

@@ -0,0 +1,32 @@
import os
import unittest
from day2 import aoc_2024_day2
class TestDay2(unittest.TestCase):
def _count_safe_from_file(self, path):
with open(path, "r", encoding="utf-8") as f:
reports = aoc_2024_day2.parse_reports(f)
return aoc_2024_day2.count_safe(reports)
def _case_path(self, filename):
here = os.path.dirname(__file__)
return os.path.join(here, "test_cases", filename)
def test_sample(self):
self.assertEqual(self._count_safe_from_file(self._case_path("sample.txt")), 2)
def test_all_safe(self):
self.assertEqual(self._count_safe_from_file(self._case_path("all_safe.txt")), 4)
def test_all_unsafe(self):
self.assertEqual(self._count_safe_from_file(self._case_path("all_unsafe.txt")), 0)
def test_edge_cases(self):
self.assertEqual(self._count_safe_from_file(self._case_path("edge_cases.txt")), 3)
if __name__ == "__main__":
unittest.main()