コード例 #1
0
ファイル: test.py プロジェクト: tyrostone/dominion
class TurnTest(unittest.TestCase):

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

    def tearDown(self):
        pass

    def test_turn_starts_with_one_action(self):
        self.assertEqual(1, self.turn.actions)

    def test_turn_starts_with_one_buy(self):
        self.assertEqual(1, self.turn.buys)

    def test_turn_has_three_phases(self):
        self.assertEqual(3, len(self.turn.phases))

    def test_turn_first_phase_is_action(self):
        self.assertEqual('action', self.turn.phases[0].type)

    def test_turn_second_phase_is_buy(self):
        self.assertEqual('buy', self.turn.phases[1].type)

    def test_turn_third_phase_is_cleanup(self):
        self.assertEqual('cleanup', self.turn.phases[-1].type)

    def test_action_phase_plays_action_card_if_one_available(self):
        board = Board()
        player = Player(board)
        self.player.generate_hand()
        player.current_hand.append(KingdomCard('Village'))
        turn = Turn(player, board)
        phase = Phase('action', player)
        self.assertTrue(turn.take_phase(phase))

    def test_action_phase_passes_if_no_action_cards_available(self):
        phase = Phase('action', self.player)
        self.assertFalse(self.turn.take_phase(phase))

    def test_buy_phase_adds_card_to_player_discard(self):
        phase = Phase('buy', self.player)
        self.turn.take_phase(phase)
        self.assertEqual(1, len(self.player.discard))

    def test_buy_phase_removes_card_from_board(self):
        self.board.slots = [Slot(TreasureCard('Copper'))]
        phase = Phase('buy', self.player)
        self.turn.take_phase(phase)
        self.assertEqual(45, self.board.slots[0].num_cards)
コード例 #2
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)