def test_cmd01_position(self): code = Intcode([1, 9, 10, 3, 2, 3, 11, 0, 99, 30, 40, 50], 9, 10) operation = f'{code.program[code.pointer]:>05}' code.parm3, code.parm2, code.parm1 = map(int, tuple(operation[0:3])) code.cmd01() assert code.program == [1, 9, 10, 70, 2, 3, 11, 0, 99, 30, 40, 50] assert code.pointer == 4 assert not code.terminated
def test_cmd08_equals_false(self): code = Intcode([7, 10, 10, 3, 2, 3, 11, 0, 99, 30, 40, 50]) code.pointer = 0 operation = f'{code.program[code.pointer]:>05}' code.parm3, code.parm2, code.parm1 = map(int, tuple(operation[0:3])) code.cmd08() assert code.program == [7, 10, 10, 1, 2, 3, 11, 0, 99, 30, 40, 50] assert code.pointer == 4 assert not code.terminated
def test_cmd06_position_jump_if_false_false(self): code = Intcode([6, 7, 10, 3, 2, 3, 11, 0, 99, 30, 40, 50]) code.pointer = 0 operation = f'{code.program[code.pointer]:>05}' code.parm3, code.parm2, code.parm1 = map(int, tuple(operation[0:3])) code.cmd06() assert code.program == [6, 7, 10, 3, 2, 3, 11, 0, 99, 30, 40, 50] assert code.pointer == 40 assert not code.terminated
def test_cmd02_position(self): code = Intcode([1, 9, 10, 3, 2, 3, 11, 0, 99, 30, 40, 50], 9, 10) code.pointer = 4 operation = f'{code.program[code.pointer]:>05}' code.parm3, code.parm2, code.parm1 = map(int, tuple(operation[0:3])) code.cmd02() assert code.program == defaultdict( int, enumerate([150, 9, 10, 3, 2, 3, 11, 0, 99, 30, 40, 50])) assert code.pointer == 8 assert not code.terminated
def test_cmd07_less_than_false(self): code = Intcode([7, 10, 10, 3, 2, 3, 11, 0, 99, 30, 40, 50]) code.pointer = 0 operation = f'{code.program[code.pointer]:>05}' code.parm3, code.parm2, code.parm1 = map(int, tuple(operation[0:3])) code.cmd07() assert code.program == defaultdict( int, enumerate([7, 10, 10, 0, 2, 3, 11, 0, 99, 30, 40, 50])) assert code.pointer == 4 assert not code.terminated
def test_cmd05_position_jump_if_true_false(self): code = Intcode([5, 7, 10, 3, 2, 3, 11, 0, 99, 30, 40, 50]) code.pointer = 0 operation = f'{code.program[code.pointer]:>05}' code.parm3, code.parm2, code.parm1 = map(int, tuple(operation[0:3])) code.cmd05() assert code.program == defaultdict( int, enumerate([5, 7, 10, 3, 2, 3, 11, 0, 99, 30, 40, 50])) assert code.pointer == 3 assert not code.terminated
def test_cmd02_immediate3(self): code = Intcode([1, 9, 10, 12, 1102, 3, 11, 0, 99, 30, 40, 50], 9, 10) code.pointer = 4 operation = f'{code.program[code.pointer]:>05}' code.parm3, code.parm2, code.parm1 = map(int, tuple(operation[0:3])) code.cmd02() assert code.parm1 assert code.parm2 assert not code.parm3 assert code.program == [33, 9, 10, 12, 1102, 3, 11, 0, 99, 30, 40, 50] assert code.pointer == 8 assert not code.terminated
def test_cmd01_immediate3(self): code = Intcode([1101, 9, 10, 3, 2, 3, 11, 0, 99, 30, 40, 50], 9, 10) operation = f'{code.program[code.pointer]:>05}' code.parm3, code.parm2, code.parm1 = map(int, tuple(operation[0:3])) code.cmd01() assert code.parm1 assert code.parm2 assert not code.parm3 assert code.program == defaultdict( int, enumerate([1101, 9, 10, 19, 2, 3, 11, 0, 99, 30, 40, 50])) assert code.pointer == 4 assert not code.terminated
def test_cmd09_relative(self): code = Intcode([209, 7, 10, 3, 2, 3, 11, 13, 99, 30, 40, 50]) code.relative_base = 1 assert code.pointer == 0 operation = f'{code.program[code.pointer]:>05}' code.parm3, code.parm2, code.parm1 = map(int, tuple(operation[0:3])) code.cmd09() assert code.program == defaultdict( int, enumerate([209, 7, 10, 3, 2, 3, 11, 13, 99, 30, 40, 50])) assert code.pointer == 2 assert code.relative_base == 100 assert not code.terminated
def test_cmd03(self): code = Intcode([3, 2, 10, 12, 1102, 3, 11, 0, 99, 30, 40, 50], inp=5) code.pointer = 0 operation = f'{code.program[code.pointer]:>05}' code.parm3, code.parm2, code.parm1 = map(int, tuple(operation[0:3])) code.cmd03() assert code.inp == 5 assert not code.parm1 assert not code.parm2 assert not code.parm3 assert code.program == [3, 2, 5, 12, 1102, 3, 11, 0, 99, 30, 40, 50] assert code.pointer == 2 assert not code.terminated
def test_cmd01_relative11(self): code = Intcode([201, 9, 10, 3, 2, 3, 11, 0, 99, 30, 40, 50], 9, 10) code.relative_base = 1 operation = f'{code.program[code.pointer]:>05}' code.parm3, code.parm2, code.parm1 = map(int, tuple(operation[0:3])) code.cmd01() assert code.parm1 assert not code.parm2 assert not code.parm3 assert code.program == defaultdict( int, enumerate([201, 9, 10, 80, 2, 3, 11, 0, 99, 30, 40, 50])) assert code.pointer == 4 assert not code.terminated