import unittest import os class Day1(unittest.TestCase): inputfile = os.path.join(os.path.dirname(__file__), "input/day1_input") def calc_fuel(self, mass): fuel = mass // 3 - 2 return fuel + self.calc_fuel(fuel) if fuel > 0 else 0 def test_day1a(self): fuel = 0 with open(self.inputfile) as fp: for _, line in enumerate(fp): fuel += int(line) // 3 - 2 self.assertEqual(fuel, 3402609) def test_day1b(self): with open(self.inputfile) as fp: for _, line in enumerate(fp): sumfuel = 0 while line: sumfuel += self.calc_fuel(int(line)) line = fp.readline() self.assertEqual(sumfuel, 5101025)