Exemple #1
0
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
Exemple #2
0
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]
Exemple #3
0
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
Exemple #4
0
def test_add_ab():
    warrior = Warrior(processes=[0])
    core = Core(
        data=[ADD('AB', '#', '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() == 2
    assert instruction.b_value() == -2
Exemple #5
0
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
Exemple #6
0
 def play(self):
     """
     Play rounds
     """
     for round_num in range(1, self._rounds + 1):
         round_obj = Round(self._warriors,
                           core_size=self._core_size,
                           gui=self._gui,
                           number=round_num,
                           max_cycles=self._max_cycles)
         round_obj.play()
Exemple #7
0
 def test_drink_type_hot(self, got_input):
     # arrange
     db = Mock(Database)
     mock_brewer = Mock(p.Person)
     test_list = []
     test_round = r.Round(db, mock_brewer, test_list)
     got_input.side_effect = ["H"]
     expected = "Hot"
     # act
     actual = test_round.get_drink_type()
     # assert
     self.assertEqual(expected, actual)
Exemple #8
0
    def test_same_again_wo_fav(self, making_drink):
        # arrange
        db = Mock(Database)
        mock_brewer = Mock(p.Person)
        mock_drink = Mock(d.Drink)
        test_list = []
        test_round = r.Round(db, mock_brewer, test_list)
        making_drink.side_effect = [mock_drink]
        expected = mock_drink
        # act
        actual = test_round.same_again(None, "Hot")

        # assert
        self.assertEqual(expected, actual)
Exemple #9
0
    def test_choose_drink(self, get_drink_type, same_again):
        # arrange
        db = Mock(Database)
        get_drink_type.return_value = "Soft"
        mock_brewer = Mock(p.Person)
        mock_brewer.fav_sd_id = 14
        drinky = Mock(d.Drink)
        same_again.return_value = drinky
        test_list = []
        test_round = r.Round(db, mock_brewer, test_list)
        expected = drinky

        # act
        actual = test_round.choose_drink(mock_brewer)

        # assert
        self.assertEqual(expected, actual)
        same_again.assert_called_once_with(14, "Soft")
Exemple #10
0
 def create_round(self, list):
     brewer_id = input("Enter the ID of the brewer: ")  # NOT RECOGNISED?
     if brewer_id == "":
         self.return_to_menu()
     try:
         brewer_id = int(brewer_id)
         select_id = p.identify_item_in_list(brewer_id, list)
     except:
         print("ID not found. Round aborted.")
         time.sleep(2)
         self.root()
     new_round = r.Round(self.db, list[select_id], drink)
     print(f"What you having {list[select_id].first_name}?")
     brewer = list[select_id]
     new_round.add_drinker(brewer)
     list.remove(brewer)
     while True:
         clear_screen()
         print_data.print_table("Possible Drinkers", list)
         person_id = input(
             "Enter the ID of the next person in the round: \nReturn to close round."
         )
         if person_id == "":
             clear_screen()
             print_data.print_dictionary("Round", new_round.orders)
             db.save_round(brewer, new_round.orders)
             menu.return_to_menu()
             clear_screen()
             self.root()
         try:
             person_id = int(person_id)
             select_id = p.identify_item_in_list(person_id, list)
         except:
             print("ID not found. Round aborted.")
             time.sleep(2)
             self.root()
         print(f"What you having {list[select_id].first_name}?")
         new_round.add_drinker(list[select_id])
         list.remove(list[select_id])
Exemple #11
0
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
Exemple #12
0
def test_round_without_gui():
    warrior_a = Warrior([MOV("I", "#", 1, "}", 0)])
    warrior_b = Warrior([MOV("I", "#", 1, "}", 0)])
    round_obj = Round([warrior_a, warrior_b])
    round_obj.play()
Exemple #13
0
def test_has_alive_warriors_false():
    warrior_a = Warrior(processes=[])
    warrior_b = Warrior(processes=[])
    game = Round([warrior_a, warrior_b], core_size=2)
    assert game.get_alive_warriors()