def pool_with_same_value_card(): """setting pool with some same value cards.""" player1, player2 = Player('Player1', Hand()), Player('Player2', Hand()) player1.hand.cards = [ Card('D', 'A'), Card('D', '8'), Card('H', '3'), Card('S', '9'), Card('C', 'Q') ] player2.hand.cards = [ Card('H', 'A'), Card('C', 'J'), Card('H', '2'), Card('S', '2'), Card('S', 'A') ] pool = Pool() pool.add_card(player1.hand.take_top(), player1) pool.add_card(player2.hand.take_top(), player2) pool.add_bonus([ player1.hand.take_top(), player1.hand.take_top(), player1.hand.take_top(), player2.hand.take_top(), player2.hand.take_top(), player2.hand.take_top() ]) pool.add_card(player1.hand.take_top(), player1) pool.add_card(player2.hand.take_top(), player2) return pool
def test_hand_take_top_has_only_1_card(): """ Hand has only one card. take_top gives empty hand.""" hand = Hand() card1 = Card('H', '5') hand.add_card(card1) top_card = hand.take_top() assert len(hand.cards) == 0 assert str(top_card) == str(card1)
def test_hand_has_cards_yes(): """ Check Hand has some cards.""" hand = Hand() card1 = Card('H', '5') card2 = Card('S', 'J') hand.add_card(card1) hand.add_card(card2) assert hand.has_cards
def test_hand_take_top_check(): """Take top card of hand""" hand = Hand() card1 = Card('H', '5') card2 = Card('S', 'J') hand.add_card(card1) hand.add_card(card2) top_card = hand.take_top() assert str(top_card) == str(card1)
def test_deck_setup_hands_for_2_gives_26_each(): """For 2 player each has 26 cards in their hand""" deck = Deck() player1 = Player('player1', Hand()) player2 = Player('player2', Hand()) players = [player1, player2] deck.setup_hands(players) assert len(player1.hand.cards) == 26 assert len(player2.hand.cards) == 26
def test_pool_winner_cards_value_same(): """Pool winner is None when card value same""" player1 = Player('Player1', Hand()) card1 = Card('D', '5') player2 = Player('Player2', Hand()) card2 = Card('S', '5') pool = Pool() pool.add_card(card1, player1) pool.add_card(card2, player2) assert pool.winner is None
def pool_with_diff_value_card(): """setting pool with different value cards.""" card1, card2 = Card('D', '5'), Card('S', '8') player1, player2 = Player('Player1', Hand()), Player('Player2', Hand()) player1.hand.add_card(card1) player2.hand.add_card(card2) pool = Pool() pool.add_card(player1.hand.take_top(), player1) pool.add_card(player2.hand.take_top(), player2) return pool
def test_pool_winner_cards_value_differ(): """Pool winner when card value differ""" player1 = Player('Player1', Hand()) card1 = Card('D', '5') player2 = Player('Player2', Hand()) card2 = Card('S', '8') pool = Pool() pool.add_card(card1, player1) pool.add_card(card2, player2) assert pool.winner.name == 'Player2'
def test_pool_add_bonus_when_tie(): """Adding cards to bonus bucket of pool.""" player1 = Player('Player1', Hand()) card1 = Card('D', '5') player2 = Player('Player2', Hand()) card2 = Card('C', '5') pool = Pool() pool.add_card(card1, player1) pool.add_card(card2, player2) cards = [Card('H', '6'), Card('S', '8'), Card('D', '6')] pool.add_bonus(cards) assert len(pool.bonus) == len(cards)
def test_pool_add_card_multiple(): """ Adding multiple cards to pool using add_card """ player1 = Player('Player1', Hand()) card1 = Card('D', 'A') player2 = Player('Player2', Hand()) card2 = Card('C', '5') player3 = Player('Player3', Hand()) card3 = Card('S', '10') pool = Pool() pool.add_card(card1, player1) pool.add_card(card2, player2) pool.add_card(card3, player3) assert str(pool) == '[D-A :: Player1, C-5 :: Player2, S-10 :: Player3]'
def test_deck_setup_hands_for_4_gives_13_each(): """For 4 player each has 13 cards in their hand""" deck = Deck() player1 = Player('player1', Hand()) player2 = Player('player2', Hand()) player3 = Player('player3', Hand()) player4 = Player('player4', Hand()) players = [player1, player2, player3, player4] deck.setup_hands(players) assert len(player1.hand.cards) == 13 assert len(player2.hand.cards) == 13 assert len(player3.hand.cards) == 13 assert len(player4.hand.cards) == 13
def test_pool_add_card_1(): """Adding 1 card to pool""" player1 = Player('Player1', Hand()) card1 = Card('D', 'A') pool = Pool() pool.add_card(card1, player1) assert str(pool) == '[D-A :: Player1]'
def test_player_drop_card_empty_hand(): """Empty hand drop card to pool.""" player1 = Player('Player1', Hand()) pool = Pool() player1.drop_card(pool) assert len(pool.cards) == 0 assert len(player1.hand.cards) == 0
def __init__(self, players): """ Initialize the game with Players as input. @param players: A list of 2 players. """ self.players = [Player(name, Hand()) for name in players] self.deck = Deck() self.rounds = 0
def test_player_drop_bonus_have_less_than_3_cards(): """Player drops number of cards in hand to bonus bucket, when hand has less than 3 cards.""" player1 = Player('Player1', Hand()) player1.hand.cards = [Card('D', 'A'), Card('D', '8')] pool = Pool() player1.drop_bonus(pool, 3) assert len(player1.hand.cards) == 0 assert len(pool.bonus) == 2
def test_hand_take_top_len_check_after_pop(): """Hand len decreases after take_top""" hand = Hand() card1 = Card('H', '5') card2 = Card('S', 'J') hand.add_card(card1) hand.add_card(card2) hand.take_top() assert len(hand.cards) == 1
def test_hand_add_all_1_card_as_list(): """ Add 1 card as list to non-empty Hand""" hand = Hand() card1 = Card('H', '5') card2 = Card('S', 'J') hand.add_card(card1) hand.add_card(card2) hand.add_all([Card('C', '2')]) assert len(hand.cards) == 3
def test_hand_add_card_multiple(): """Add multiple cards to empty hand.""" hand = Hand() card = Card('D', '5') card1 = Card('C', '10') card2 = Card('H', 'A') hand.add_card(card) hand.add_card(card1) hand.add_card(card2) assert len(hand.cards) == 3
def test_hand_add_all_to_non_empty(): """ Add list of cards to non-empty Hand""" hand = Hand() card1 = Card('H', '5') card2 = Card('S', 'J') hand.add_card(card1) hand.add_card(card2) hand_cards_len_before_add_all = len(hand.cards) assert hand_cards_len_before_add_all == 2 cards = [Card('D', '5'), Card('C', '10'), Card('H', 'A'), Card('S', 'K')] hand.add_all(cards) hand_cards_len_after_add_all = len(hand.cards) assert hand_cards_len_after_add_all == hand_cards_len_before_add_all + len( cards)
def test_hand_has_cards_no(): """Check empty Hand has cards""" hand = Hand() assert not hand.has_cards
def test_hand_empty(): """ Create empty hand""" hand = Hand() assert len(hand.cards) == 0
def test_hand_add_all_to_empty(): """ Add list of cards to empty Hand""" cards = [Card('D', '5'), Card('C', '10'), Card('H', 'A'), Card('S', 'K')] hand = Hand() hand.add_all(cards) assert len(hand.cards) == len(cards)
def test_hand_take_top_of_empty_hand(): """Assert IndexError for empty hand, when take_top ran""" with pytest.raises(IndexError): hand = Hand() hand.take_top()
def test_hand_add_card_1(): """Add 1 card to empty hand.""" hand = Hand() card = Card('D', '5') hand.add_card(card) assert len(hand.cards) == 1
def players(): """ Setting a players of 2""" player1, player2 = Player('Player1', Hand()), Player('Player2', Hand()) player1.hand.cards = [Card('D', 'A'), Card('D', '8'), Card('H', '3'), Card('S', '9'), Card('C', 'Q')] player2.hand.cards = [Card('H', 'A'), Card('C', 'J'), Card('H', '2'), Card('S', '2'), Card('S', 'A')] return [player1, player2]
def test_deck_setup_hands_makes_empty(): """Check if all the cards are distributed. By check deck len = 0""" deck = Deck() players = [Player(name, Hand()) for name in ['player1', 'player2']] deck.setup_hands(players) assert len(deck.cards) == 0