Files
misc/day2/test_day2.py
2026-05-19 17:09:13 -04:00

33 lines
959 B
Python

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()