예제 #1
0
파일: test.py 프로젝트: tyrostone/dominion
class BoardTest(unittest.TestCase):

    def setUp(self):
        self.board = Board()

    def test_board_defaults_to_two_players(self):
        self.assertEqual(2, self.board.num_players)

    def test_board_has_ten_slots_for_kingdom_cards(self):
        self.assertEqual(10, len(self.board.kingdom_slots))

    def test_board_has_three_treasure_card_slots(self):
        self.assertEqual(3, len(self.board.treasure_slots))

    def test_board_has_three_victory_card_slots(self):
        self.assertEqual(3, len(self.board.victory_slots))

    def test_kingdom_cards_in_board_slots_are_unique_to_board(self):
        card_names = [x.card.name for x in self.board.kingdom_slots]
        card_names_set = set(card_names)
        self.assertEqual(len(card_names_set), len(card_names))

    def test_board_has_trash_pile(self):
        self.assertEqual([], self.board.trash)

    def test_board_displays_available_cards(self):
        all_cards = self.board.display_cards()
        for card in all_cards:
            self.assertIsInstance(card, Card)
예제 #2
0
파일: test.py 프로젝트: tyrostone/dominion
 def setUp(self):
     self.board = Board()
     self.player = Player(self.board)
예제 #3
0
파일: test.py 프로젝트: tyrostone/dominion
class PlayerTest(unittest.TestCase):

    def setUp(self):
        self.board = Board()
        self.player = Player(self.board)

    def test_player_starts_with_three_victory_points(self):
        self.assertEqual(3, self.player.victory_points)

    def test_player_starts_with_ten_total_cards_in_deck(self):
        self.assertEqual(10, len(self.player.deck))

    def test_player_starts_with_seven_treasure_copper_cards(self):
        self.assertEqual(7, len(self.player.get_cards_of_type('treasure')))

    def test_player_starts_with_three_victory_estate_cards(self):
        self.assertEqual(3, len(self.player.get_cards_of_type('victory')))

    def test_player_starts_with_no_action_cards(self):
        action_cards = self.player.get_cards_of_type('kingdom')
        self.assertEqual([], action_cards)

    def test_player_starts_not_as_starting_player(self):
        self.assertFalse(self.player.is_starting)

    def test_player_returns_action_card_if_one_available(self):
        self.player.deck.append(KingdomCard('Village'))
        self.assertIsInstance(
            self.player.get_cards_of_type('kingdom')[0], KingdomCard)

    def test_player_can_play_card_in_hand(self):
        turn = Turn(self.player, self.board)
        self.player.current_hand.append(KingdomCard('Village'))
        self.player.play_card(self.player.current_hand[0], turn)

    def test_player_cannot_play_card_not_in_hand(self):
        turn = Turn(self.player, self.board)
        self.player.generate_hand()
        deck_card = KingdomCard('Village')
        self.player.deck.append(deck_card)
        self.assertRaises(Exception, self.player.play_card, deck_card, turn)

    def test_player_generates_hand_of_five_cards(self):
        self.player.generate_hand()
        self.assertEqual(5, len(self.player.current_hand))

    def test_player_cards_in_hand_not_in_deck(self):
        self.player.generate_hand()
        for card in self.player.current_hand:
            self.assertNotIn(card, self.player.deck)

    def test_player_discard_starts_empty(self):
        self.assertEqual([], self.player.discard)

    def test_player_discard_hand_empties_hand(self):
        self.player.generate_hand()
        self.player.discard_hand()
        self.assertEqual([], self.player.current_hand)

    def test_player_discard_hand_goes_to_discard(self):
        self.player.generate_hand()
        hand = copy.copy(self.player.current_hand)
        self.player.discard_hand()
        self.assertEqual(hand, self.player.discard)

    def test_player_discards_card_after_playing_it(self):
        turn = Turn(self.player, self.board)
        self.player.generate_hand()
        card_to_play = self.player.current_hand[0]
        self.player.play_card(self.player.current_hand[0], turn)
        self.assertIn(card_to_play, self.player.discard)

    def test_player_can_buy_copper_treasure_card(self):
        card = TreasureCard('Copper')
        self.player.buy_card(card)
        self.assertIn(card, self.player.discard)

    def test_player_can_discard_copper_treasure_card(self):
        self.player.generate_hand()
        copper = [card for card in self.player.current_hand
                  if card.name == 'Copper'][0]
        self.player.trash(copper)
        self.assertIn(copper, self.player.board.trash)

    def test_player_can_count_coins_in_current_hand(self):
        self.player.current_hand = [TreasureCard('Copper'),
                                    TreasureCard('Copper'),
                                    TreasureCard('Copper'),
                                    TreasureCard('Copper')]
        self.assertEqual(len(self.player.current_hand),
                         self.player.count_coins_in_hand())

    def test_player_chooses_purchase_if_one_option_available(self):
        self.board.slots = [Slot(KingdomCard('Village'))]
        self.player.current_hand = [TreasureCard('Copper'),
                                    TreasureCard('Copper'),
                                    TreasureCard('Copper'),
                                    TreasureCard('Copper')]
        self.assertIsInstance(self.player.determine_purchase(
                             self.board.display_cards()), KingdomCard)
예제 #4
0
파일: test.py 프로젝트: tyrostone/dominion
 def setUp(self):
     self.board = Board()