def test_quine(): program = [ 109, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101, 1006, 101, 0, 99 ] c = IntComputer() c.output = Mock() result = c.run_program(program) assert c.output.call_count == 16 call_values = [call[0][0] for call in c.output.call_args_list] assert call_values == [ 109, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101, 1006, 101, 0, 99, ]
def test_offset_1(): program = [109, 19, 99] c = IntComputer() c.offset = 2000 c.output = Mock() result = c.run_program(program) assert c.offset == 2019
def test_offset_2(): program = [109, 19, 204, -34, 99] c = IntComputer() c.offset = 2000 c.output = Mock() result = c.run_program(program) assert c.offset == 2019 assert c.output.call_count == 1
def test_int_computer_with_inputs(start_memory, expected_end_memory, input_values, output_values): int_computer = IntComputer(start_memory) outputs = int_computer.run_program(inputs=input_values) assert int_computer.memory == expected_end_memory assert output_values == outputs
def get_output(noun, verb): # For a given noun and verb return the value at pos 0 of the program program = [ 1, noun, verb, 3, 1, 1, 2, 3, 1, 3, 4, 3, 1, 5, 0, 3, 2, 1, 10, 19, 1, 19, 5, 23, 2, 23, 6, 27, 1, 27, 5, 31, 2, 6, 31, 35, 1, 5, 35, 39, 2, 39, 9, 43, 1, 43, 5, 47, 1, 10, 47, 51, 1, 51, 6, 55, 1, 55, 10, 59, 1, 59, 6, 63, 2, 13, 63, 67, 1, 9, 67, 71, 2, 6, 71, 75, 1, 5, 75, 79, 1, 9, 79, 83, 2, 6, 83, 87, 1, 5, 87, 91, 2, 6, 91, 95, 2, 95, 9, 99, 1, 99, 6, 103, 1, 103, 13, 107, 2, 13, 107, 111, 2, 111, 10, 115, 1, 115, 6, 119, 1, 6, 119, 123, 2, 6, 123, 127, 1, 127, 5, 131, 2, 131, 6, 135, 1, 135, 2, 139, 1, 139, 9, 0, 99, 2, 14, 0, 0 ] int_computer = IntComputer(program) int_computer.run_program() return int_computer.memory[0]
def test_16bit_number(): program = [1102, 34915192, 34915192, 7, 4, 7, 99, 0] c = IntComputer() def output(a): assert a == 1219070632396864 c.output = output result = c.run_program(program)
def test_print_large_number(): program = [104, 1125899906842624, 99] c = IntComputer() def output(a): assert a == 1125899906842624 def input(): return 8 c.output = output c.input = input result = c.run_program(program)
def test_immediate_mode_input_less_than_8(): program = [3, 9, 7, 9, 10, 9, 4, 9, 99, -1, 8] c = IntComputer() def output(a): assert a == 0 def input(): return 8 c.output = output c.input = input result = c.run_program(program) assert result == [3, 9, 7, 9, 10, 9, 4, 9, 99, 0, 8]
def test_immediate_mode_input_equals_8(): program = [3, 9, 8, 9, 10, 9, 4, 9, 99, -1, 8] c = IntComputer() def output(a): assert a == 1 def input(): return 8 c.output = output c.input = input result = c.run_program(program) assert result == [3, 9, 8, 9, 10, 9, 4, 9, 99, 1, 8]
from main import IntComputer inputs = [5] memory = [3, 225, 1, 225, 6, 6, 1100, 1, 238, 225, 104, 0, 1101, 65, 73, 225, 1101, 37, 7, 225, 1101, 42, 58, 225, 1102, 62, 44, 224, 101, -2728, 224, 224, 4, 224, 102, 8, 223, 223, 101, 6, 224, 224, 1, 223, 224, 223, 1, 69, 126, 224, 101, -92, 224, 224, 4, 224, 1002, 223, 8, 223, 101, 7, 224, 224, 1, 223, 224, 223, 1102, 41, 84, 225, 1001, 22, 92, 224, 101, -150, 224, 224, 4, 224, 102, 8, 223, 223, 101, 3, 224, 224, 1, 224, 223, 223, 1101, 80, 65, 225, 1101, 32, 13, 224, 101, -45, 224, 224, 4, 224, 102, 8, 223, 223, 101, 1, 224, 224, 1, 224, 223, 223, 1101, 21, 18, 225, 1102, 5, 51, 225, 2, 17, 14, 224, 1001, 224, -2701, 224, 4, 224, 1002, 223, 8, 223, 101, 4, 224, 224, 1, 223, 224, 223, 101, 68, 95, 224, 101, -148, 224, 224, 4, 224, 1002, 223, 8, 223, 101, 1, 224, 224, 1, 223, 224, 223, 1102, 12, 22, 225, 102, 58, 173, 224, 1001, 224, -696, 224, 4, 224, 1002, 223, 8, 223, 1001, 224, 6, 224, 1, 223, 224, 223, 1002, 121, 62, 224, 1001, 224, -1302, 224, 4, 224, 1002, 223, 8, 223, 101, 4, 224, 224, 1, 223, 224, 223, 4, 223, 99, 0, 0, 0, 677, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1105, 0, 99999, 1105, 227, 247, 1105, 1, 99999, 1005, 227, 99999, 1005, 0, 256, 1105, 1, 99999, 1106, 227, 99999, 1106, 0, 265, 1105, 1, 99999, 1006, 0, 99999, 1006, 227, 274, 1105, 1, 99999, 1105, 1, 280, 1105, 1, 99999, 1, 225, 225, 225, 1101, 294, 0, 0, 105, 1, 0, 1105, 1, 99999, 1106, 0, 300, 1105, 1, 99999, 1, 225, 225, 225, 1101, 314, 0, 0, 106, 0, 0, 1105, 1, 99999, 1008, 226, 677, 224, 102, 2, 223, 223, 1005, 224, 329, 1001, 223, 1, 223, 7, 677, 226, 224, 102, 2, 223, 223, 1006, 224, 344, 1001, 223, 1, 223, 1007, 226, 677, 224, 1002, 223, 2, 223, 1006, 224, 359, 1001, 223, 1, 223, 1007, 677, 677, 224, 102, 2, 223, 223, 1005, 224, 374, 1001, 223, 1, 223, 108, 677, 677, 224, 102, 2, 223, 223, 1006, 224, 389, 101, 1, 223, 223, 8, 226, 677, 224, 102, 2, 223, 223, 1005, 224, 404, 101, 1, 223, 223, 7, 226, 677, 224, 1002, 223, 2, 223, 1005, 224, 419, 101, 1, 223, 223, 8, 677, 226, 224, 1002, 223, 2, 223, 1005, 224, 434, 101, 1, 223, 223, 107, 677, 677, 224, 1002, 223, 2, 223, 1006, 224, 449, 101, 1, 223, 223, 7, 677, 677, 224, 1002, 223, 2, 223, 1006, 224, 464, 101, 1, 223, 223, 1107, 226, 226, 224, 102, 2, 223, 223, 1006, 224, 479, 1001, 223, 1, 223, 1007, 226, 226, 224, 102, 2, 223, 223, 1006, 224, 494, 101, 1, 223, 223, 108, 226, 677, 224, 1002, 223, 2, 223, 1006, 224, 509, 101, 1, 223, 223, 1108, 226, 677, 224, 102, 2, 223, 223, 1006, 224, 524, 1001, 223, 1, 223, 1008, 226, 226, 224, 1002, 223, 2, 223, 1005, 224, 539, 101, 1, 223, 223, 107, 226, 226, 224, 102, 2, 223, 223, 1006, 224, 554, 101, 1, 223, 223, 8, 677, 677, 224, 102, 2, 223, 223, 1005, 224, 569, 101, 1, 223, 223, 107, 226, 677, 224, 102, 2, 223, 223, 1005, 224, 584, 101, 1, 223, 223, 1108, 226, 226, 224, 1002, 223, 2, 223, 1005, 224, 599, 1001, 223, 1, 223, 1008, 677, 677, 224, 1002, 223, 2, 223, 1005, 224, 614, 101, 1, 223, 223, 1107, 226, 677, 224, 102, 2, 223, 223, 1005, 224, 629, 101, 1, 223, 223, 1108, 677, 226, 224, 1002, 223, 2, 223, 1005, 224, 644, 1001, 223, 1, 223, 1107, 677, 226, 224, 1002, 223, 2, 223, 1006, 224, 659, 1001, 223, 1, 223, 108, 226, 226, 224, 102, 2, 223, 223, 1006, 224, 674, 101, 1, 223, 223, 4, 223, 99, 226] int_computer = IntComputer(memory) outputs = int_computer.run_program(inputs=inputs) print("Outputs:") for output in outputs: print(f"\t{output}")
109, -19, 1208, -4, 34, 63, 1005, 63, 605, 1105, 1, 611, 4, 595, 1001, 64, 1, 64, 1002, 64, 2, 64, 109, 7, 2106, 0, 8, 4, 617, 1001, 64, 1, 64, 1106, 0, 629, 1002, 64, 2, 64, 109, -8, 1205, 9, 647, 4, 635, 1001, 64, 1, 64, 1106, 0, 647, 1002, 64, 2, 64, 109, -12, 2107, 38, 3, 63, 1005, 63, 667, 1001, 64, 1, 64, 1106, 0, 669, 4, 653, 1002, 64, 2, 64, 109, -3, 2102, 1, 10, 63, 1008, 63, 34, 63, 1005, 63, 695, 4, 675, 1001, 64, 1, 64, 1105, 1, 695, 1002, 64, 2, 64, 109, 14, 21108, 43, 45, 4, 1005, 1015, 711, 1105, 1, 717, 4, 701, 1001, 64, 1, 64, 1002, 64, 2, 64, 109, 13, 1205, -4, 733, 1001, 64, 1, 64, 1105, 1, 735, 4, 723, 1002, 64, 2, 64, 109, -30, 2101, 0, 9, 63, 1008, 63, 37, 63, 1005, 63, 761, 4, 741, 1001, 64, 1, 64, 1106, 0, 761, 1002, 64, 2, 64, 109, 17, 21102, 44, 1, 1, 1008, 1012, 45, 63, 1005, 63, 785, 1001, 64, 1, 64, 1106, 0, 787, 4, 767, 1002, 64, 2, 64, 109, 5, 2101, 0, -9, 63, 1008, 63, 35, 63, 1005, 63, 811, 1001, 64, 1, 64, 1106, 0, 813, 4, 793, 1002, 64, 2, 64, 109, 2, 21107, 45, 44, -5, 1005, 1013, 833, 1001, 64, 1, 64, 1106, 0, 835, 4, 819, 1002, 64, 2, 64, 109, -2, 21101, 46, 0, -6, 1008, 1010, 44, 63, 1005, 63, 855, 1106, 0, 861, 4, 841, 1001, 64, 1, 64, 1002, 64, 2, 64, 109, 2, 21108, 47, 47, -8, 1005, 1010, 883, 4, 867, 1001, 64, 1, 64, 1106, 0, 883, 1002, 64, 2, 64, 109, 2, 2105, 1, 3, 1001, 64, 1, 64, 1106, 0, 901, 4, 889, 4, 64, 99, 21102, 27, 1, 1, 21102, 1, 915, 0, 1105, 1, 922, 21201, 1, 28815, 1, 204, 1, 99, 109, 3, 1207, -2, 3, 63, 1005, 63, 964, 21201, -2, -1, 1, 21102, 1, 942, 0, 1105, 1, 922, 21202, 1, 1, -1, 21201, -2, -3, 1, 21101, 0, 957, 0, 1105, 1, 922, 22201, 1, -1, -2, 1106, 0, 968, 21202, -2, 1, -2, 109, -3, 2106, 0, 0 ] int_computer = IntComputer(program) outputs = int_computer.run_program([1]) print("Outputs...") for output in outputs: print(f"\t{output}")
def test_int_computer(start_memory, expected_end_memory): int_computer = IntComputer(start_memory) int_computer.run_program() assert int_computer.memory == expected_end_memory
def test_conditional_operations(start_memory, inputs, outputs): int_computer = IntComputer(start_memory) actual_outputs = int_computer.run_program(inputs=inputs) assert actual_outputs == outputs
from main import IntComputer program = [ 1, 12, 2, 3, 1, 1, 2, 3, 1, 3, 4, 3, 1, 5, 0, 3, 2, 1, 10, 19, 1, 19, 5, 23, 2, 23, 6, 27, 1, 27, 5, 31, 2, 6, 31, 35, 1, 5, 35, 39, 2, 39, 9, 43, 1, 43, 5, 47, 1, 10, 47, 51, 1, 51, 6, 55, 1, 55, 10, 59, 1, 59, 6, 63, 2, 13, 63, 67, 1, 9, 67, 71, 2, 6, 71, 75, 1, 5, 75, 79, 1, 9, 79, 83, 2, 6, 83, 87, 1, 5, 87, 91, 2, 6, 91, 95, 2, 95, 9, 99, 1, 99, 6, 103, 1, 103, 13, 107, 2, 13, 107, 111, 2, 111, 10, 115, 1, 115, 6, 119, 1, 6, 119, 123, 2, 6, 123, 127, 1, 127, 5, 131, 2, 131, 6, 135, 1, 135, 2, 139, 1, 139, 9, 0, 99, 2, 14, 0, 0 ] int_computer = IntComputer(program) int_computer.run_program() print(f"Value at position 0: {int_computer.memory[0]}")