示例#1
0
class TestPlayerAdvanced(unittest.TestCase):
    def setUp(self):
        self.player = Advanced("AdvancedPlayer")

    def test_setUp_class_attributes_and_properties(self):
        self.assertEqual(self.player.username, 'AdvancedPlayer')
        self.assertEqual(self.player.health, 250)
        self.assertEqual("CardRepository",
                         self.player.card_repository.__class__.__name__)

    def test_health_cannot_go_under_zero(self):
        with self.assertRaises(ValueError) as exc:
            self.player.health = -10
        self.assertEqual("Player's health bonus cannot be less than zero.",
                         str(exc.exception))

    def test_username_cannot_be_empty(self):
        with self.assertRaises(ValueError) as exc:
            pl = Advanced('')
        self.assertEqual("Player's username cannot be an empty string.",
                         str(exc.exception))

    def test_is_dead_return_True_is_health_below_zero(self):
        self.assertEqual(False, self.player.is_dead)
        self.player.health = 0
        self.assertEqual(True, self.player.is_dead)

    def test_take_damage_func_works(self):
        self.player.take_damage(200)
        self.assertEqual(50, self.player.health)
        with self.assertRaises(ValueError) as exc:
            self.player.take_damage(-200)
        self.assertEqual("Damage points cannot be less than zero.",
                         str(exc.exception))
 def test_is_dead(self):
     a = Advanced("Test")
     self.assertEqual(a.health, INITIAL_HEALTH)
     self.assertFalse(a.is_dead)
     a.health = 0
     self.assertEqual(a.health, 0)
     self.assertTrue(a.is_dead)
class TestAdvanced(unittest.TestCase):
    def setUp(self):
        self.player = Advanced("Tony")

    def test_initialization_is_done_correctly(self):
        self.assertEqual(self.player.username, "Tony")
        self.assertEqual(self.player.health, 250)
        self.assertEqual(self.player.card_repository.__class__.__name__, "CardRepository")

    def test_username_raises_error_when_trying_to_set_it_to_empty_str(self):
        with self.assertRaises(ValueError) as cm:
            self.player.username = ""
        self.assertEqual(str(cm.exception), "Player's username cannot be an empty string.")

    def test_health_raises_error_when_trying_to_set_it_below_zero(self):
        with self.assertRaises(ValueError) as cm:
            self.player.health = -1
        self.assertEqual(str(cm.exception), "Player's health bonus cannot be less than zero.")

    def test_is_dead_returns_false_if_health_is_positive(self):
        self.assertEqual(self.player.is_dead, False)

    def test_is_dead_returns_true_if_health_is_not_positive(self):
        self.player.health = 0
        self.assertEqual(self.player.is_dead, True)

    def test_take_damage_raises_error_when_damage_points_are_less_than_zero(self):
        with self.assertRaises(ValueError) as cm:
            self.player.take_damage(-10)
        self.assertEqual(str(cm.exception), "Damage points cannot be less than zero.")

    def test_take_damage_decreases_health_when_damage_points_is_positive_number(self):
        self.player.take_damage(30)
        self.assertEqual(self.player.health, 220)
示例#4
0
    def test_fight_attacker_is_dead(self):
        attacker = Advanced("Test1")
        enemy = Advanced("Test2")
        attacker.health = 0

        with self.assertRaises(ValueError):
            BattleField.fight(attacker, enemy)
示例#5
0
    def test_take_damage_to_death_valid_data_should_raise_error(self):
        player = Advanced("Dave")

        with self.assertRaises(ValueError):
            player.take_damage(500)

        self.assertEqual(player.is_dead, False)
示例#6
0
 def test_fight_with_one_of_player_is_dead__should_raise_error(self):
     attacker = Advanced('Attacker')
     enemy = Beginner('Enemy')
     attacker.health = 0
     with self.assertRaises(ValueError) as cm:
         self.battlefield.fight(attacker, enemy)
     self.assertIsNotNone(cm.exception)
 def test_if_enemy_is_dead_should_raise_error(self):
     attacker = Beginner("Simo")
     enemy = Advanced('Dimo')
     enemy.health = 0
     with self.assertRaises(ValueError) as cm:
         self.battlefield.fight(attacker, enemy)
     self.assertEqual(str(cm.exception), "Player is dead!")
示例#8
0
 def test_player_is_dead(self):
     a = Advanced('attacker')
     e = Beginner('enemy')
     a.health = 0
     bf = BattleField()
     with self.assertRaises(ValueError) as ex:
         bf.fight(a, e)
     self.assertEqual(str(ex.exception), "Player is dead!")
 def test_enemy_is_dead(self):
     advanced = Advanced("test")
     advanced_2 = Advanced("test2")
     advanced_2.health = 0
     bf = BattleField()
     with self.assertRaises(ValueError) as ex:
         bf.fight(advanced, advanced_2)
     self.assertEqual(str(ex.exception), "Player is dead!")
示例#10
0
    def test_add__when_player_invalid(self) -> None:
        player1 = Advanced('John')
        player2 = Advanced('John')
        self.player_repository.add(player1)
        with self.assertRaises(ValueError) as context:
            self.player_repository.add(player2)

        self.assertEqual(context.exception.args[0], 'Player John already exists!')
示例#11
0
 def test_attacker_is_dead(self):
     p1 = Advanced("test")
     p1.health = 0
     p2 = Advanced("test2")
     bf = BattleField()
     with self.assertRaises(ValueError) as ex:
         bf.fight(p1, p2)
     self.assertEqual(str(ex.exception), "Player is dead!")
示例#12
0
 def test_att_is_dead(self):
     advanced = Advanced('test')
     advanced.health = 0
     advanced2 = Advanced('test2')
     battlefield = BattleField()
     with self.assertRaises(ValueError) as cm:
         battlefield.fight(advanced, advanced2)
     self.assertEqual('Player is dead!', str(cm.exception))
示例#13
0
 def setUp(self) -> None:
     # self.card1 = Advanced("Test")
     # self.card2 = MagicCard("Test2")
     # self.card3 = MagicCard("Test")
     self.player1 = Advanced("Test")
     self.player2 = Advanced("Test2")
     self.player3 = Advanced("Test")
     self.repository = PlayerRepository()
 def test_fight(self):
     attacker = Advanced('p1')
     enemy = Advanced('p2')
     ac = MagicCard('card1')
     attacker.card_repository.add(ac)
     ec = MagicCard('card2')
     enemy.card_repository.add(ec)
     self.ctrl.player_repository.add(attacker)
     self.ctrl.player_repository.add(enemy)
     expected = "Attack user health 325 - Enemy user health 325"
     self.assertEqual(expected, self.ctrl.fight('p1', 'p2'))
示例#15
0
 def test_fight_increase_health(self):
     attacker = Advanced("Bushido")
     enemy = Advanced("Onyx")
     card = TrapCard("Exodia")
     attacker.card_repository.cards.append(card)
     enemy.card_repository.cards.append(card)
     BattleField.fight(attacker, enemy)
     self.assertEqual(135, attacker.health)
     self.assertEqual(135, enemy.health)
     self.assertFalse(attacker.is_dead)
     self.assertFalse(enemy.is_dead)
示例#16
0
 def test_helth_one_hero_die2(self):
     a = Advanced('A')
     e = Advanced('AA')
     # d- 120, h-5
     c_a = TrapCard('TrapCard')
     c_a.damage_points = 255
     c_e = TrapCard('TrapCard')
     a.card_repository.cards.append(c_a)
     e.card_repository.cards.append(c_e)
     self.b.fight(a, e)
     self.assertTrue(e.is_dead)
     self.assertEqual(a.health, 255)
示例#17
0
 def test_helth_one_hero_die(self):
     a = Beginner('A')
     e = Advanced('AA')
     e.health = 1000
     # d- 120, h-5
     c_a = TrapCard('TrapCard')
     c_e = TrapCard('TrapCard')
     a.card_repository.cards.append(c_a)
     e.card_repository.cards.append(c_e)
     with self.assertRaises(ValueError) as ex:
         self.b.fight(a, e)
     self.assertEqual(str(ex.exception),
                      "Player's health bonus cannot be less than zero.")
示例#18
0
    def test_players_health_is_increased(self):
        attacker = Advanced("Test1")
        enemy = Advanced("Test2")
        card = TrapCard("TrapTest")
        attacker.card_repository.add(card)
        enemy.card_repository.add(card)
        self.assertEqual(attacker.health, 250)
        self.assertEqual(enemy.health, 250)

        BattleField.fight(attacker, enemy)
        self.assertEqual(attacker.health, 135)
        self.assertEqual(enemy.health, 135)
        self.assertFalse(attacker.is_dead)
        self.assertFalse(enemy.is_dead)
 def test_add_existing_player_should_raise_error(self):
     repo = PlayerRepository()
     player = Advanced("Peter")
     repo.players.append(player)
     with self.assertRaises(ValueError) as cm:
         repo.add(player)
     self.assertEqual(str(cm.exception), "Player Peter already exists!")
示例#20
0
class TestAdvanced(TestCase):
    def setUp(self):
        self.advanced_player = Advanced('User1')

    def test_attributes_are_set(self):
        self.assertEqual('User1', self.advanced_player.username)
        self.assertEqual(250, self.advanced_player.health)

    def test_set_username_with_empty_string__raises(self):
        with self.assertRaises(ValueError) as ex:
            self.advanced_player.username(player=Advanced(""))
        self.assertEqual("Player's username cannot be an empty string.",
                         str(ex.exception))

    def test_check_class_name(self):
        self.assertEqual("Advanced", self.advanced_player.__class__.__name__)
示例#21
0
 def test_fight__when_player_is_beginner__should_increase_health(self):
     beginner = Beginner('Beginner')
     advance = Advanced("Advanced")
     expected = 50 + 40
     self.battlefield.fight(beginner, advance)
     actual = beginner.health
     self.assertEqual(actual, expected)
示例#22
0
    def test_remove__when_player_invalid__expect_exception(self) -> None:
        player = Advanced('John')
        self.player_repository.add(player)
        with self.assertRaises(ValueError) as context:
            self.player_repository.remove('')

        self.assertEqual(context.exception.args[0], 'Player cannot be an empty string!')
    def setUp(self):
        self.controller = Controller()

        self.beginner = Beginner('Noob')
        self.advanced = Advanced('Pro')
        self.magic_card = MagicCard('Magic')
        self.trap_card = TrapCard('Trap')
 def test_add_raises(self):
     p = Advanced("test")
     self.pr.add(p)
     with self.assertRaises(ValueError) as ex:
         self.pr.add(p)
     self.assertEqual(str(ex.exception),
                      f"Player {p.username} already exists!")
 def add_player(self, type, username):
     if type == 'Beginner':
         p = Beginner(username)
     elif type == 'Advanced':
         p = Advanced(username)
     self.player_repository.add(p)
     return f"Successfully added player of type {type} with username: {username}"
示例#26
0
 def test_beginner_health_increase(self):
     a = Advanced('attacker')
     e = Beginner('enemy')
     self.assertEqual(50, e.health)
     bf = BattleField()
     bf.fight(a, e)
     self.assertEqual(90, e.health)
 def test_damage_points_and_health_increased_without_cards(self):
     advanced = Advanced("test")
     beginner = Beginner("test2")
     bf = BattleField()
     bf.fight(advanced, beginner)
     self.assertEqual(advanced.health, 250)
     self.assertEqual(beginner.health, 90)
 def test_if_init_is_properly_initialized(self):
     advanced = Advanced('Test')
     expected_name = 'Test'
     expected_hp = 250
     self.assertEqual(expected_hp, advanced.health)
     self.assertEqual(expected_name, advanced.username)
     self.assertFalse(advanced.is_dead)
示例#29
0
 def add_player(self, type: str, username: str):
     if type == "Beginner":
         player = Beginner(username)
     else:
         player = Advanced(username)
     self.player_repository.add(player)
     return f"Successfully added player of type {type} with username: {username}"
 def test_add_raises(self):
     repo = PlayerRepository()
     p = Advanced('test')
     repo.add(p)
     with self.assertRaises(ValueError) as ex:
         repo.add(p)
     self.assertEqual(str(ex.exception), "Player test already exists!")