Exemplo n.º 1
0
def test_opcode_6():
    opcode1 = [6, 10, 11, 99, 1102, 21, 2, 9, 99, 0, 0, 4]
    result1 = [6, 10, 11, 99, 1102, 21, 2, 9, 99, 42, 0, 4]
    opcode2 = [1106, 1, 4, 99, 1102, 21, 2, 9, 99, 0]
    result2 = [1106, 1, 4, 99, 1102, 21, 2, 9, 99, 0]
    object1 = IntCode(opcode1)
    object1.run()
    object2 = IntCode(opcode2)
    object2.run()
    assert object1.opcode == result1
    assert object2.opcode == result2
Exemplo n.º 2
0
def test_opcode_3_resume_run():
    opcode = [3, 7, 3, 8, 3, 9, 99, 0, 0, 0]
    result = [3, 7, 3, 8, 3, 9, 99, 4, 2, 42]
    input_list = [4, 2]
    object = IntCode(opcode, input_list)
    assert object.run() == []
    assert object.halt
    assert object.position == 4
    object.add_input(42)
    assert object.run() == []
    assert object.opcode == result
    assert not object.halt
Exemplo n.º 3
0
def test_opcode_2_bad_references():
    opcode1 = [2, 10, 0, 0, 99]
    opcode2 = [2, 0, 10, 0, 99]
    opcode3 = [2, 0, 0, 10, 99]
    object1 = IntCode(opcode1)
    assert object1.run() == -1
    assert object1.opcode == opcode1
    object2 = IntCode(opcode2)
    assert object2.run() == -1
    assert object2.opcode == opcode2
    object3 = IntCode(opcode3)
    assert object3.run() == -1
    assert object3.opcode == opcode3
Exemplo n.º 4
0
def test_opcode_3():
    opcode = [3, 3, 99, 0]
    result = [3, 3, 99, 42]
    input_list = [42]
    object = IntCode(opcode, input_list)
    assert object.run() == []
    assert object.opcode == result
Exemplo n.º 5
0
def test_opcode_3_multiple_inputs():
    opcode = [3, 7, 3, 8, 3, 9, 99, 0, 0, 0]
    result = [3, 7, 3, 8, 3, 9, 99, 4, 2, 42]
    input_list = [4, 2, 42]
    object = IntCode(opcode, input_list)
    assert object.run() == []
    assert object.opcode == result
Exemplo n.º 6
0
def test_opcode_3_not_enough_inputs():
    opcode = [3, 7, 3, 8, 3, 9, 99, 0, 0, 0]
    result = [3, 7, 3, 8, 3, 9, 99, 4, 2, 0]
    input_list = [4, 2]
    object = IntCode(opcode, input_list)
    assert object.run() == []
    assert object.opcode == result
    assert object.position == 4
    assert object.halt
Exemplo n.º 7
0
def test_opcode_8():
    opcode1 = [8, 6, 7, 5, 99, 42, 1, 2]
    result1 = [8, 6, 7, 5, 99, 0, 1, 2]
    opcode2 = [1108, 2, 1, 5, 99, 42]
    result2 = [1108, 2, 1, 5, 99, 0]
    opcode3 = [108, 2, 6, 5, 99, 42, 2]
    result3 = [108, 2, 6, 5, 99, 1, 2]
    object1 = IntCode(opcode1)
    object1.run()
    object2 = IntCode(opcode2)
    object2.run()
    object3 = IntCode(opcode3)
    object3.run()
    assert object1.opcode == result1
    assert object2.opcode == result2
    assert object3.opcode == result3
Exemplo n.º 8
0
def test_run_out_of_opcode_values():
    opcode = [1101, 5]
    result = [1101, 5]
    object = IntCode(opcode)
    object.run()
    assert object.opcode == result
Exemplo n.º 9
0
def test_opcode_2():
    opcode = [2, 3, 0, 3, 99]
    result_opcode = [2, 3, 0, 6, 99]
    object = IntCode(opcode)
    assert object.run() == []
    assert object.opcode == result_opcode
Exemplo n.º 10
0
def test_opcode_4():
    opcode = [4, 3, 99, 42]
    result = [4, 3, 99, 42]
    object = IntCode(opcode)
    assert object.run() == [42]
    assert object.opcode == result
Exemplo n.º 11
0
def test_opcode_1():
    opcode = [1, 0, 0, 0, 99]
    result_opcode = [2, 0, 0, 0, 99]
    object = IntCode(opcode)
    assert object.run() == []
    assert object.opcode == result_opcode
Exemplo n.º 12
0
def test_intcode_run():
    opcode = [99]
    object = IntCode(opcode)
    assert object.run() == []
    assert object.opcode == opcode
Exemplo n.º 13
0
def test_get_value():
    opcode = [1, 5, 6, 0, 99, 5, 8]
    result = 13
    object = IntCode(opcode)
    object.run()
    assert object.get_value() == result
Exemplo n.º 14
0
def test_invalid_opcode_position():
    opcode = [1, 0, 0, 3]
    result = [1, 0, 0, 2]
    object = IntCode(opcode)
    object.run()
    assert object.opcode == result
Exemplo n.º 15
0
def test_too_many_opcode_values():
    opcode = [101101, 5, 5, 4, 99, 0]
    result = [101101, 5, 5, 4, 99, 0]
    object = IntCode(opcode)
    object.run()
    assert object.opcode == result
Exemplo n.º 16
0
def test_invalid_last_opcode_mode():
    opcode = [11101, 5, 5, 99]
    result = [11101, 5, 5, 99]
    object = IntCode(opcode)
    object.run()
    assert object.opcode == result
Exemplo n.º 17
0
def test_not_enough_opcode_values():
    opcode = [1, 0, 0]
    result = [1, 0, 0]
    object = IntCode(opcode)
    object.run()
    assert object.opcode == result
Exemplo n.º 18
0
def test_invalid_opcode():
    opcode = [1, 0, 0, 3, 9]
    result = [1, 0, 0, 2, 9]
    object = IntCode(opcode)
    object.run()
    assert object.opcode == result
Exemplo n.º 19
0
def test_mode_opcodes():
    opcode = [1002, 4, 3, 4, 33]
    result = [1002, 4, 3, 4, 99]
    object = IntCode(opcode)
    object.run()
    assert object.opcode == result