def test_seq_i_yes(): warrior = Warrior(processes=[0]) core = Core(data=[ SEQ('I', '$', 1, '$', 2), DAT('F', '$', 2, '$', 4), DAT('F', '$', 2, '$', 4) ]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert warrior.processes()[0] == 2
def test_mod_zero(): warrior = Warrior(processes=[0]) core = Core(data=[ MOD('I', '$', 1, '$', 2), DAT('F', '$', 0, '$', 0), DAT('F', '$', 0, '$', 0) ]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert len(warrior.processes()) == 0
def test_djn_f_not_zero(): warrior = Warrior(processes=[0]) core = Core(data=[ DJN('B', '$', 2, '$', 0), DAT('F', '$', 0, '$', 1), DAT('F', '$', 0, '$', 1) ]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert warrior.processes() == [2]
def test_core_add_cycle_begin_two_times(): warrior = Warrior(processes=[1]) core = Core(data=[ DAT('F', '$', 1, '$', 5), ADD('AB', '#', '3', '$', '-5'), DAT('F', '$', 1, '$', -5) ]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert game.core()[2].b_value() == -2
def test_spl_typical(): warrior = Warrior(processes=[0]) core = Core(data=[ SPL('F', '$', 2, '$', 2), DAT('F', '$', 0, '$', 0), DAT('F', '$', 0, '$', 0) ]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert warrior.processes() == [1, 2]
def test_jmp_typical(): warrior = Warrior(processes=[2]) core = Core(data=[ DAT('F', '$', 1, '$', -5), DAT('F', '$', 1, '$', -5), JMP('B', '$', -1, '$', 0) ]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert game.warriors()[0].processes()[0] == 1
def test_mov_x(): warrior = Warrior(processes=[0]) core = Core(data=[ MOV('X', '$', '1', '$', '2'), DAT('F', '$', 1, '$', 7), DAT('F', '$', 0, '$', 0) ]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert game.core()[2].a_value() == 7 assert game.core()[2].b_value() == 1
def prepare_core(size): """ Generate data with single instruction :param size: Core size :return: Core data """ return [DAT('F', '$', 0, '$', 0) for _ in range(size)]
def test_post_decrement_a(): warrior = Warrior(processes=[0]) core = Core(data=[MOV('I', '}', 1, '$', 1), DAT('F', '$', 0, '$', 0)]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert core[1].a_value() == 0 assert core[1].b_value() == 0
def test_sub_typical(): warrior = Warrior(processes=[0]) core = Core( data=[SUB('AB', '#', '3', '$', '1'), DAT('F', '$', 1, '$', -5)]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert game.core()[1].b_value() == -8
def test_sub_x(): warrior = Warrior(processes=[0]) core = Core(data=[SUB('X', '#', '3', '$', '1'), DAT('F', '$', 2, '$', -5)]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() instruction = game.core()[1] assert instruction.a_value() == 1 assert instruction.b_value() == -8
def test_instruction_create(): instruction = DAT('AB', '#', 1, '@', -1) assert instruction.modifier() == Modifier.AB assert instruction.a_mode() == Mode.IMMEDIATE assert instruction.a_value() == 1 assert instruction.b_mode() == Mode.B_INDIRECT assert instruction.b_value() == -1
def test_get_cycled_value_begin(): instruction_1 = DAT('F', '$', 1, '$', 5) instruction_2 = ADD('AB', '#', '3', '$', '-2') instruction_3 = DAT('F', '$', 1, '$', -5) core = Core(data=[instruction_1, instruction_2, instruction_3]) assert core[-5] == instruction_2
def test_core_postincrement_b(): warrior = Warrior(processes=[0]) core = Core(data=[DAT('F', '>', 1, '$', 1), DAT('F', '$', 0, '$', 0)]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert game.core()[1].b_value() == 1
def test_instruction_to_str(): instruction = DAT('AB', '#', 1, '@', -1) assert str(instruction) == 'DAT.AB #1, @-1'