def testjumponeimmode(self): m = IntCodeMachine([3, 3, 1105, -1, 9, 1101, 0, 0, 12, 4, 12, 99, 1]) with mock.patch('builtins.input', return_value=1): assert next(m.run()) == 1, 'result is not True for val != 0' m.reset() with mock.patch('builtins.input', return_value=0): assert next(m.run()) == 0, 'result is not False for val == 0'
def testjumponeposmode(self): m = IntCodeMachine( [3, 12, 6, 12, 15, 1, 13, 14, 13, 4, 13, 99, -1, 0, 1, 9]) with mock.patch('builtins.input', return_value=1): assert next(m.run()) == 1, 'result is not True for val != 0' m.reset() with mock.patch('builtins.input', return_value=0): assert next(m.run()) == 0, 'result is not False for val == 0'
def testlesseightimmode(self): m = IntCodeMachine([3, 3, 1107, -1, 8, 3, 4, 3, 99]) with mock.patch('builtins.input', return_value=1): assert next(m.run()) == 1, 'result is not True for val < 8' m.reset() with mock.patch('builtins.input', return_value=8): assert next(m.run()) == 0, 'result is not False for val == 8' m.reset() with mock.patch('builtins.input', return_value=10): assert next(m.run()) == 0, 'result is not False for val > 8'
def testequalseightposmode(self): m = IntCodeMachine([3, 9, 8, 9, 10, 9, 4, 9, 99, -1, 8]) with mock.patch('builtins.input', return_value=1): assert next(m.run()) == 0, 'result is not False for val < 8' m.reset() with mock.patch('builtins.input', return_value=8): assert next(m.run()) == 1, 'result is not True for val == 8' m.reset() with mock.patch('builtins.input', return_value=10): assert next(m.run()) == 0, 'result is not False for val > 8'
def test(self): m = IntCodeMachine([ 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 ]) with mock.patch('builtins.input', return_value=1): assert next(m.run()) == 999, 'result is not 999 for val < 8' m.reset() with mock.patch('builtins.input', return_value=8): assert next(m.run()) == 1000, 'result is not 1000 for val == 8' m.reset() with mock.patch('builtins.input', return_value=10): assert next(m.run()) == 1001, 'result is not 1001 for val > 8'
from aocd.models import Puzzle from intcode import IntCodeMachine if __name__ == '__main__': puzzle = Puzzle(year=2019, day=9) m = IntCodeMachine(list(map(int, puzzle.input_data.split(',')))) m.set_inputs([1]) puzzle.answer_a = next(m.run()) m.reset() m.set_inputs([2]) puzzle.answer_b = next(m.run())