def test_day2_part1(self): datas = [ ("1,9,10,3,2,3,11,0,99,30,40,50", 3500), ] for data, result in datas: with self.subTest(data=data): p = Program(data) p.execute() self.assertEqual(p._Program__memory[0], result)
def test_simple(self): p = Program("3, 1") p.send_input(42) p.step() self.assertEqual(p._Program__pos, 2) self.assertEqual(p._Program__running, True) self.assertEqual(p._Program__memory, [3, 42])
def test_day5_part2(self): datas = [ ( "3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31,1106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104,999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99", 7, 999, ), ( "3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31,1106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104,999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99", 8, 1000, ), ( "3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31,1106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104,999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99", 9, 1001, ), ] for data, data_input, result in datas: with self.subTest(data=data): p = Program(data) p.send_input(data_input) p.execute() self.assertEqual(next(p), result)
def test_immediate_result_error(self): p = Program("10001, 0, 0, 0, 99") with self.assertRaises(AssertionError): p.step()
def test_setted(self): mode = Program.get_mode(1001, 3) self.assertEqual(mode, [0, 1, 0])
def get_program(self, program_id, md5=None): program = self._cache.get_program(program_id, md5) if program is None: return None return Program.decode(program)
def test_immediate_one(self): p = Program("1002, 0, 4, 0, 99") p.step() self.assertEqual(p._Program__pos, 4) self.assertEqual(p._Program__running, True) self.assertEqual(p._Program__memory, [4008, 0, 4, 0, 99])
def test_simple(self): p = Program("2, 4, 5, 6, 1, 1, 0") p.step() self.assertEqual(p._Program__pos, 4) self.assertEqual(p._Program__running, True) self.assertEqual(p._Program__memory, [2, 4, 5, 6, 1, 1, 1])
def test_direct_true(self): p = Program("1107, 0, 1, 3") p.step() self.assertEqual(p._Program__pos, 4) self.assertEqual(p._Program__running, True) self.assertEqual(p._Program__memory, [1107, 0, 1, 1])
def test_true(self): p = Program("7, 1, 0, 3") p.step() self.assertEqual(p._Program__pos, 4) self.assertEqual(p._Program__running, True) self.assertEqual(p._Program__memory, [7, 1, 0, 1])
def test_full_setted(self): mode = Program.get_mode(11101, 3) self.assertEqual(mode, [1, 1, 1])
def test_simple_true(self): p = Program("6, 1, 0") p.step() self.assertEqual(p._Program__pos, 3) self.assertEqual(p._Program__running, True) self.assertEqual(p._Program__memory, [6, 1, 0])
def test_simple_false(self): p = Program("5, 2, 0") p.step() self.assertEqual(p._Program__pos, 3) self.assertEqual(p._Program__running, True) self.assertEqual(p._Program__memory, [5, 2, 0])
def test_direct_true(self): p = Program("1105, 1, 0") p.step() self.assertEqual(p._Program__pos, 0) self.assertEqual(p._Program__running, True) self.assertEqual(p._Program__memory, [1105, 1, 0])
def test_out_of_range(self): p = Program("98, 0, 0, 100, 99") with self.assertRaises(AssertionError): p.step()
def test_default(self): mode = Program.get_mode(1, 3) self.assertEqual(mode, [0, 0, 0])
def test_false(self): p = Program("8, 0, 1, 3") p.step() self.assertEqual(p._Program__pos, 4) self.assertEqual(p._Program__running, True) self.assertEqual(p._Program__memory, [8, 0, 1, 0])
def test_inplace(self): p = Program("2, 0, 0, 0, 99") p.step() self.assertEqual(p._Program__pos, 4) self.assertEqual(p._Program__running, True) self.assertEqual(p._Program__memory, [4, 0, 0, 0, 99])
def test_direct_false(self): p = Program("1108, 1, 0, 3") p.step() self.assertEqual(p._Program__pos, 4) self.assertEqual(p._Program__running, True) self.assertEqual(p._Program__memory, [1108, 1, 0, 0])
def test_immediate_two(self): p = Program("1102, 5, 4, 0, 99") p.step() self.assertEqual(p._Program__pos, 4) self.assertEqual(p._Program__running, True) self.assertEqual(p._Program__memory, [20, 5, 4, 0, 99])
def test_simple(self): p = Program("99") p.step() self.assertEqual(p._Program__pos, 1) self.assertEqual(p._Program__running, False) self.assertEqual(p._Program__memory, [99])
def main(): data = sys.stdin.readline() p = Program(data) p.send_input(1) p.execute() print(list(p))
def test_out_of_range(self): p = Program("1, 0, 0, 100, 99") with self.assertRaises(IndexError): p.step()