def test_load_data(): codes = """nop +0 acc +1 jmp +4 acc +3 jmp -3 acc -99 acc +1 jmp -4 acc +6""" machine = solution.Machine() machine.load_code(codes.split("\n")) assert machine.data == data
def test_machine_ops_register(ops, amount, curr_ptr, expected): machine = solution.Machine(data=data) machine.ptr = curr_ptr getattr(machine, ops)(amount) assert machine.data[machine.ptr] == expected
def test_machine_jmp(initial, amount, expected): machine = solution.Machine() machine.ptr = initial machine.jmp(amount) assert machine.ptr == expected
def test_machine_ops(ops, amount, initial, expected): machine = solution.Machine() machine.ptr = initial getattr(machine, ops)(amount) assert machine.ptr == expected
def test_machine_acc(initial, amount, expected): machine = solution.Machine() machine.accumulator = initial machine.acc(amount) assert machine.accumulator == expected