-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_day03ii.py
31 lines (24 loc) · 1.48 KB
/
test_day03ii.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import unittest
from day_03ii import oxygen_generator_rating, co2_scrubber_rating, life_support_rating
INPUT_PATH = './fixtures/day-03.txt'
class TestDay03Part2(unittest.TestCase):
def setUp(self):
with open(INPUT_PATH, 'r') as report:
self.report = [line.strip() for line in report]
def test_example(self):
bin_str_report = ['00100', '11110', '10110', '10111', '10101', '01111', '00111', '11100', '10000', '11001', '00010', '01010']
report = self.__strs_to_binary(bin_str_report)
self.assertEqual(life_support_rating(report, len(bin_str_report[0])), 230)
def test_actual(self):
report = self.__strs_to_binary(self.report)
self.assertEqual(life_support_rating(report, len(self.report[0])), 5736383)
def test_oxygen_generator_rating(self):
bin_str_report = ['00100', '11110', '10110', '10111', '10101', '01111', '00111', '11100', '10000', '11001', '00010', '01010']
report = self.__strs_to_binary(bin_str_report)
self.assertEqual(oxygen_generator_rating(report, len(bin_str_report[-1])), 23)
def test_co2_scrubber_rating(self):
bin_str_report = ['00100', '11110', '10110', '10111', '10101', '01111', '00111', '11100', '10000', '11001', '00010', '01010']
report = self.__strs_to_binary(bin_str_report)
self.assertEqual(co2_scrubber_rating(report, len(bin_str_report[-1])), 10)
def __strs_to_binary(self, strings):
return [int(f'0b{bin_str}', 2) for bin_str in strings]