def setUp(self): card_set1 = [] card_set2 = [] random.seed(1567) for cardIndex in range(0, 30): card_set1.append(card_lookup("Stonetusk Boar")) card_set2.append(card_lookup("Novice Engineer")) self.deck1 = Deck(card_set1, CHARACTER_CLASS.DRUID) self.deck2 = Deck(card_set2, CHARACTER_CLASS.MAGE)
def test_create_game(self): card_set1 = [] card_set2 = [] test_env = self for cardIndex in range(0, 30): card_set1.append(card_lookup("Stonetusk Boar")) card_set2.append(card_lookup("Novice Engineer")) deck1 = Deck(card_set1, CHARACTER_CLASS.DRUID) deck2 = Deck(card_set2, CHARACTER_CLASS.MAGE) checked_cards = [] class MockAgent1: def do_card_check(self, cards): test_env.assertEqual(len(cards), 3) checked_cards.append(list(cards)) return [False, True, True] def set_game(self, game): pass class MockAgent2: def do_card_check(self, cards): test_env.assertEqual(len(cards), 4) checked_cards.append(list(cards)) return [False, True, True, False] def set_game(self, game): pass agent1 = unittest.mock.Mock(spec=MockAgent1(), wraps=MockAgent1()) agent2 = unittest.mock.Mock(spec=MockAgent2(), wraps=MockAgent2()) game = Game([deck1, deck2], [agent1, agent2]) game.pre_game() self.assertEqual(agent1.method_calls[0][0], "set_game", "Agent not asked to select cards") self.assertEqual(agent2.method_calls[0][0], "set_game", "Agent not asked to select cards") self.assertEqual(agent1.method_calls[1][0], "do_card_check", "Agent not asked to select cards") self.assertEqual(agent2.method_calls[1][0], "do_card_check", "Agent not asked to select cards") self.assertTrue(game.players[0].deck == deck1, "Deck not assigned to player") self.assertTrue(game.players[1].deck == deck2, "Deck not assigned to player") self.assertTrue(game.players[0].agent == agent1, "Agent not stored in the hsgame") self.assertTrue(game.players[1].agent == agent2, "Agent not stored in the hsgame") self.assertListEqual(checked_cards[0][1:], game.players[0].hand[:-1], "Cards not retained after request") self.assertListEqual(checked_cards[1][1:2], game.players[1].hand[:-3], "Cards not retained after request")
def test_all_cards(self): fake_game = generate_game_for(StonetuskBoar, StonetuskBoar, DoNothingBot, DoNothingBot) overload_re = re.compile("Overload: \((\\d)\)") spell_damage_re = re.compile("Spell Damage \\+(\\d)") battlecry_re = re.compile("Battlecry: .*") deathrattle_re = re.compile("Deathrattle: .*") split_re = re.compile("\\s*\\.\\s*") file = open("cards.csv", "r") reader = csv.DictReader(file) for row in reader: if row['Implemented?'] == "yes": card = card_lookup(row["Name"]) self.assertEqual(int(row["Cost"]), card.mana, row["Name"]) self.assertEqual(CHARACTER_CLASS.from_str(row["Class"]), card.character_class, row["Name"]) self.assertEqual(CARD_RARITY.from_str(row["Rarity"]), card.rarity, "Expected card '{0}' to have rarity {1}".format(row["Name"], row["Rarity"])) if row["Type"] == "Minion": minion = card.create_minion(fake_game.current_player) minion.player = fake_game.current_player for effect in split_re.split(row["Text"]): if effect == "Taunt": self.assertTrue(minion.taunt, "Expected {:s} to have taunt".format(row["Name"])) elif effect == "Divine Shield": self.assertTrue(minion.divine_shield, "Expected {:s} to have divine shield".format(row["Name"])) elif effect == "Stealth": self.assertTrue(minion.stealth, "Expected {:s} to have stealth".format(row["Name"])) elif effect == "Windfury": self.assertTrue(minion.windfury, "Expected {:s} to have windfury".format(row["Name"])) elif effect == "Charge": self.assertTrue(minion.charge, "Expected {:s} to have charge".format(row["Name"])) elif battlecry_re.match(effect): self.assertTrue(minion.battlecry is not None, "Expected {:s} to have a battlecry".format (row["Name"])) elif deathrattle_re.match(effect): self.assertTrue(minion.deathrattle is not None, "Expected {:s} to have a deathrattle".format (row["Name"])) elif overload_re.match(effect) is not None: self.assertEqual(int(overload_re.match(effect).group(1)), card.overload, ("Expected {:s} to have overload of" + " {:s}, but had {:d}").format(row["Name"], overload_re.match(effect).group(1), card.overload)) elif spell_damage_re.match(effect) is not None: self.assertEqual(int(spell_damage_re.match(effect).group(1)), minion.spell_damage, ("Expected {:s} to have spell damage of" + " {:s}, but had {:d}").format(row["Name"], spell_damage_re.match(effect).group(1), minion.spell_damage)) minion.silence() self.assertEqual(int(row["Attack"]), minion.calculate_attack(), row["Name"]) self.assertEqual(int(row["Health"]), minion.health, row["Name"]) self.assertEqual(MINION_TYPE.from_str(row["Race"]), minion.minion_type, row["Name"]) elif row["Type"] == "Weapon": weapon = card.create_weapon(fake_game.current_player) self.assertEqual(int(row["Attack"]), weapon.base_attack, row["Name"]) self.assertEqual(int(row["Health"]), weapon.durability, row["Name"]) file.close()
def test_first_turn(self): card_set1 = [] card_set2 = [] for cardIndex in range(0, 30): card_set1.append(card_lookup("Stonetusk Boar")) card_set2.append(card_lookup("Novice Engineer")) deck1 = Deck(card_set1, CHARACTER_CLASS.DRUID) deck2 = Deck(card_set2, CHARACTER_CLASS.MAGE) agent1 = unittest.mock.Mock(spec=DoNothingBot(), wraps=DoNothingBot()) agent2 = unittest.mock.Mock(spec=DoNothingBot(), wraps=DoNothingBot()) game = Game([deck1, deck2], [agent1, agent2]) game.start()
def test_AllCards(self): fake_game = generate_game_for(StonetuskBoar, StonetuskBoar, DoNothingBot, DoNothingBot) file = open("cards.csv", "r") reader = csv.DictReader(file) for row in reader: if row['Implemented?'] == "yes": card = card_lookup(row["Name"]) self.assertEqual(int(row["Cost"]), card.mana, row["Name"]) self.assertEqual(CHARACTER_CLASS.from_str(row["Class"]), card.character_class, row["Name"]) if row["Minion/Spell"] == "Minion": minion = card.create_minion(fake_game.current_player) minion.player = fake_game.current_player minion.silence() self.assertEqual(int(row["Attack"]), minion.attack_power, row["Name"]) self.assertEqual(int(row["Health"]), minion.health, row["Name"]) self.assertEqual(MINION_TYPE.from_str(row["Race"]), minion.type, row["Name"]) file.close()