Example #1
0
 def test_player_buy_card(self):
     """
     Tests the buy_card method. This method only checks whether the attack
     action works properly.Any validation checks are conducted in parent
     methods and are thus checked using alternative test cases.
     """
     player = Player('Nikos')
     player._money = 10
     central = {
         'deck': CardsCollection(),
         'active': CardsCollection(),
         'supplement': CardsCollection(),
         'active_size': 5
     }
     central['deck'].push(Card('Deck card', 3, 0, 2), 1)
     central['active'].push(Card('Archer', 3, 0, 2), 5)
     player.buy_card(central['active'], central['deck'], 0)
     self.assertEqual(central['active'].size(), 5)
     self.assertEqual(player.discard.size(), 1)
     self.assertEqual(player.discard.cards[0].name, 'Archer')
     self.assertEqual(central['active'].cards[4].name, 'Deck card')
     player.buy_card(central['active'], central['deck'], 0)
     # deck size = 0 now -> no more cards from deck to active area
     self.assertEqual(central['active'].size(), 4)
     self.assertEqual(player.discard.size(), 2)
 def test_collection_shuffle(self):
     """
     Tests whether the shuffling results to unexpected results.
     """
     collection = CardsCollection()
     collection.push(Card('Archer', 3, 0, 2), 5)
     collection.push(Card('Deck card', 3, 0, 2), 5)
     collection.shuffle_collection()
     self.assertEqual(len(collection.cards), 10)
 def test_collection_clear(self):
     """
     Tests whether the list is cleared when using the appropriate method.
     """
     collection = CardsCollection()
     collection.push(Card('Archer', 3, 0, 2), 5)
     collection.push(Card('Deck card', 3, 0, 2), 5)
     collection.clear_collection()
     self.assertEqual(collection.cards, [])
 def test_collection_size(self):
     """
     Tests whether the size of the list returned when calling the
     appropriate method is the expected one.
     """
     collection = CardsCollection()
     self.assertEqual(collection.size(), 0)
     collection.push(Card('Archer', 3, 0, 5), 2)
     collection.push(Card('Test1', 1, 1, 1), 3)
     self.assertEqual(collection.size(), 5)
 def test_collection_replace(self):
     """
     Tests whether collection's content is correctly replaced by that of
     another -given- collection, when calling the appropriate method.
     """
     collection1 = CardsCollection()
     collection2 = CardsCollection()
     collection1.push(Card('Archer', 3, 0, 2), 2)
     collection2.push(Card('Deck card', 3, 0, 2), 3)
     collection1.replace(collection2)
     self.assertEqual(collection1.cards, collection2.cards)
Example #6
0
 def test_best_buy_acquisative(self):
     """
     Tests the computer_best_buy method for an acquisative opponent.
     The index returned should abide by the implemented logic.
     """
     deck_game = Game()
     deck_game.aggressive = False
     temp_list = [("S", Card('Archer', 3, 1, 5)),
                  (1, Card('Test1', 1, 3, 3)), (3, Card('Test2', 0, 3, 2))]
     deck_game.computer_best_buy(temp_list)
     self.assertEqual(deck_game.computer_best_buy(temp_list), 2)
 def test_collection_push(self):
     """
     Tests whether cards are appended successfully and correctly to the
     list.
     """
     collection = CardsCollection()
     card1 = Card('Archer', 3, 0, 2)
     card2 = Card('Archer', 1, 2, 1)
     collection.push(card1, 2)
     collection.push(card2)
     temp_list = [card1, card1, card2]
     self.assertSequenceEqual(collection.cards, temp_list)
Example #8
0
 def test_computer_buy(self):
     """
     Tests the computer_buy method.
     """
     deck_game = Game()
     deck_game.aggressive = True
     deck_game.player_pc._money = 3
     deck_game.central['active'].push(Card('Archer', 2, 2, 3))
     deck_game.central['active'].push(Card('Test1', 3, 1, 3))
     deck_game.central['active'].push(Card('Test2', 0, 4, 3))
     deck_game.central['supplement'].push(Card('Archer', 3, 3, 6))
     deck_game.computer_buy()
     self.assertEqual(deck_game.player_pc.discard.cards[0].name, 'Test1')
Example #9
0
 def test_check_no_winner(self):
     """
     Tests the get_winner method where no winner found
     (and the game continues).
     """
     deck_game = Game()
     deck_game.player_1 = Player('Nikos')
     deck_game.player_pc = Player('Computer')
     deck_game.central['active'].push(Card('Archer', 3, 1, 5))
     deck_game.central['active'].push(Card('Test1', 1, 3, 3))
     deck_game.central['active'].push(Card('Test2', 0, 3, 2))
     self.assertFalse(deck_game.check_winner(),\
         'False expected. Players\' health > 0 and central.active.size() > 0')
Example #10
0
 def test_player_end_turn(self):
     """
     Tests the end_turn method with 0 cards in player's deck.
     Player's discard pile is shuffled and its cards go to player's deck.
     A new hand with handsize cards is generated from player's deck.
     """
     player = Player('Nikos', handsize=5)
     player.hand.push(Card('Archer', 3, 0, 2), 1)
     player.discard.push(Card('Archer', 3, 0, 2), 10)
     player.active.push(Card('Archer', 3, 0, 2), 4)
     player.end_turn()
     self.assertEqual(player.active.size(), 0)
     self.assertEqual(player.discard.size(), 0)
     self.assertEqual(player.deck.size(), 10)
     self.assertEqual(player.hand.size(), 5)
Example #11
0
 def init_central_deck(self):
     """
     Initialises the central deck by pushing the predefined cards into the
     deck.
     format (Name,Strength, Skill, Size)
     """
     self.deck.push(Card('Iron Man', 30, 45, 35))
     self.deck.push(Card('Hulk', 50, 10, 50))
     self.deck.push(Card('Groot', 40, 19, 48))
     self.deck.push(Card('Thanos', 45, 30, 46))
     self.deck.push(Card('Thor', 35, 25, 36))
     self.deck.push(Card('Ultron', 33, 48, 38))
     self.deck.push(Card('Captain-America', 36, 42, 33))
     self.deck.push(Card('Spider-man', 26, 50, 26))
     self.deck.push(Card('Vision', 28, 24, 28))
     self.deck.push(Card('Star-lord', 18, 32, 27))
 def test_collection_pop(self):
     """
     Tests whether cards are removed successfully and correctly by the
     list.
     """
     collection = CardsCollection()
     card1 = Card('Archer', 3, 0, 2)
     card2 = Card('Test1', 1, 1, 1)
     card3 = Card('Test2', 1, 2, 1)
     collection.push(card1, 1)
     collection.push(card2, 2)
     collection.push(card3, 1)
     card_pop = collection.pop()
     self.assertEqual(card_pop, card3)
     card_pop = collection.pop(0)
     self.assertEqual(card_pop, card1)
Example #13
0
 def test_init_default_values(self):
     """
     Tests the initialiser of the class in case of default parameters.
     """
     card = Card('Archer')
     self.assertEqual(card.name, 'Archer')
     self.assertEqual(card.attack, 0)
     self.assertEqual(card.money, 0)
     self.assertEqual(card.cost, 0)
Example #14
0
 def test_init_(self):
     """
     Tests the initialiser of the class in case of non-default parameters.
     """
     card = Card('Archer', 3, 0, 2)
     self.assertEqual(card.name, 'Archer')
     self.assertEqual(card.attack, 3)
     self.assertEqual(card.money, 0)
     self.assertEqual(card.cost, 2)
Example #15
0
 def test_init_default_attack(self):
     """
     Tests the initialiser of the class in case of default and non-default
     parameters.
     """
     card = Card('Archer', money=1, cost=1)
     self.assertEqual(card.name, 'Archer')
     self.assertEqual(card.attack, 0)
     self.assertEqual(card.money, 1)
     self.assertEqual(card.cost, 1)
Example #16
0
 def test_buy_card(self):
     """
     Tests the buy_card method mocking user's input.
     """
     deck_game = Game()
     deck_game.player_1._money = 3
     deck_game.central['active'].push(Card('Archer', 2, 2, 3))
     with patch('__builtin__.raw_input', return_value='0'):
         deck_game.player_1_buy()
         self.assertEqual(deck_game.player_1.money, 0)
         self.assertEqual(deck_game.central['active'].size(), 0)
Example #17
0
 def test_buy_supplement(self):
     """
     Tests the buy_supplement method mocking user's input.
     """
     deck_game = Game()
     deck_game.player_1._money = 6
     deck_game.central['supplement'].push(Card('Archer', 3, 3, 6))
     with patch('__builtin__.raw_input', return_value='S'):
         deck_game.player_1_buy()
         self.assertEqual(deck_game.player_1.money, 0)
         self.assertEqual(deck_game.central['supplement'].size(), 0)
Example #18
0
 def test_player_turn(self):
     """
     Tests the player_turn method mocking user's input.
     It gives valid as well as invalid input, covering all possible
     branches.
     """
     deck_game = Game()
     deck_game.init_central_deck()
     deck_game.player_1.init_deck()
     deck_game.central['active'].push(Card('Archer', 1, 3, 3), 5)
     deck_game.player_1.hand.push(Card('Archer', 1, 0, 0))
     deck_game.player_1.hand.push(Card('Archer', 0, 1, 0))
     deck_game.player_1.hand.push(Card('Archer', 1, 1, 1))
     deck_game.player_1.hand.push(Card('Archer', 2, 2, 3), 2)
     deck_size = deck_game.player_1.deck.size()
     with patch('__builtin__.raw_input',
                side_effect=['0', '0', 'A', 'P', 'B', '0', 'B', '0', 'A']):
         deck_game.player_1_turn()
         self.assertEquals(deck_game.player_1.hand.size(), 5)
         self.assertEquals(deck_game.player_1.deck.size(), deck_size - 5)
Example #19
0
 def test_buy_card_invalid_index(self):
     """
     Tests the card method mocking user's input and giving an invalid index
     for the card to buy.
     """
     deck_game = Game()
     deck_game.player_1._money = 3
     deck_game.central['active'].push(Card('Archer', 2, 2, 3))
     with patch('__builtin__.raw_input', side_effect=['1', 'E']):
         deck_game.player_1_buy()
         self.assertEqual(deck_game.player_1.money, 3)
         self.assertEqual(deck_game.central['active'].size(), 1)
Example #20
0
 def test_player_buy_supplement(self):
     """
     Tests the buy_supplement method. This method only checks whether the attack
     action works properly.Any validation checks are conducted in parent
     methods and are thus checked using alternative test cases.
     """
     player = Player('Nikos')
     player._money = 2
     central = {
         'deck': CardsCollection(),
         'active': CardsCollection(),
         'supplement': CardsCollection(),
         'active_size': 5
     }
     central['supplement'].push(Card('Levy', 1, 2, 2), 10)
     player.buy_supplement(central['supplement'])
     self.assertEqual(central['supplement'].size(), 9)
     self.assertEqual(player.discard.size(), 1)
     self.assertEqual(player.money, 0)
Example #21
0
 def init_supplement(self):
     """
     Initialises the supplements pile by pushing the predefined cards into the
     pile.
     """
     self.central['supplement'].push(Card('Levy', 1, 2, 2), 10)
Example #22
0
 def init_central_deck(self):
     """
     Initialises the central deck by pushing the predefined cards into the
     deck.
     """
     self.central['deck'].push(Card('Archer', 3, 0, 2), 4)
     self.central['deck'].push(Card('Baker', 0, 3, 2), 4)
     self.central['deck'].push(Card('Swordsman', 4, 0, 3), 3)
     self.central['deck'].push(Card('Knight', 6, 0, 5), 2)
     self.central['deck'].push(Card('Tailor', 0, 4, 3), 3)
     self.central['deck'].push(Card('Crossbowman', 4, 0, 3), 3)
     self.central['deck'].push(Card('Merchant', 0, 5, 4), 3)
     self.central['deck'].push(Card('Thug', 2, 0, 1), 4)
     self.central['deck'].push(Card('Thief', 1, 1, 1), 4)
     self.central['deck'].push(Card('Catapault', 7, 0, 6), 2)
     self.central['deck'].push(Card('Caravan', 1, 5, 5), 2)
     self.central['deck'].push(Card('Assassin', 5, 0, 4), 2)