Simplify interface for testing
This commit is contained in:
@@ -1,32 +1,26 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from day2 import aoc_2024_day2
|
||||
from day2_sample import count_safe_in_file
|
||||
|
||||
|
||||
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)
|
||||
self.assertEqual(count_safe_in_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)
|
||||
self.assertEqual(count_safe_in_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)
|
||||
self.assertEqual(count_safe_in_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)
|
||||
self.assertEqual(count_safe_in_file(self._case_path("edge_cases.txt")), 3)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user