Пример #1
0
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
Пример #2
0
def test_game_finished_no():
    """Finished is False"""
    game = Game(['Player1', 'Player2'])
    game.players[0].hand.cards = [Card('S', '2'), Card('H', '3'), Card('H', '4'), Card('H', '5'), Card('H', '6'),
                                  Card('H', '7')]
    game.players[1].hand.cards = [Card('H', '2'), Card('H', '10'), Card('H', 'J'), Card('H', 'K'), Card('H', 'Q'),
                                  Card('H', 'A')]
    assert not game.finished
Пример #3
0
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
Пример #4
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
Пример #5
0
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
Пример #6
0
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
Пример #7
0
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)
Пример #8
0
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
Пример #9
0
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'
Пример #10
0
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
Пример #11
0
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
Пример #12
0
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)
Пример #13
0
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]'
Пример #14
0
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]'
Пример #15
0
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)
Пример #16
0
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)
Пример #17
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)
Пример #18
0
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
Пример #19
0
def test_card_invalid_rank():
    """create a card with invalid Rank"""
    with pytest.raises(AssertionError):
        card = Card('H', '13')
Пример #20
0
def test_player_give_cards_after_win(players):
    """ Player gets cards after win. So increases the hand len"""
    player1 = players[0]
    winning_cards = [Card('H', '7'), Card('S', '6')]
    player1.give_cards(winning_cards)
    assert len(player1.hand.cards) == 7
Пример #21
0
def test_card_value_of_king():
    """create a card with face value = K"""
    card = Card('C', 'K')
    card_value = card.value + 2
    assert card_value == 13
Пример #22
0
def test_card_value_of_5():
    """create a card with value = 5"""
    card = Card('H', '5')
    card_value = card.value + 2
    assert card_value == 5
Пример #23
0
def test_card_invalid_suite():
    """create a card with invalid suite"""
    with pytest.raises(AssertionError):
        card = Card('E', '3')
Пример #24
0
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]
Пример #25
0
def test_card_value_of_ace():
    """create a card with face value = A"""
    card = Card('C', 'A')
    card_value = card.value + 2
    assert card_value == 14
Пример #26
0
def test_card_validity():
    """Check card value is card.value - 2  as its returned as Index in Card.RANK"""
    card = Card('H', '3')
    assert card.value == 1
Пример #27
0
def test_card_value_of_10():
    """create a card with value = 10"""
    card = Card('D', '10')
    card_value = card.value + 2
    assert card_value == 10
Пример #28
0
def players_cards_with_no_tie():
    """Setting 26 cards to each player with no tie card"""
    player2_cards = [Card('H', '2'), Card('H', '3'), Card('H', '4'), Card('H', '5'), Card('H', '6'),
                     Card('H', '7'), Card('H', '8'), Card('D', '2'), Card('D', '3'), Card('D', '4'),
                     Card('D', '5'), Card('D', '6'), Card('D', '7'), Card('D', '8'), Card('S', '2'),
                     Card('S', '3'), Card('S', '4'), Card('S', '5'), Card('S', '6'), Card('S', '7'),
                     Card('C', '2'), Card('C', '3'), Card('C', '4'), Card('C', '5'), Card('C', '6'),
                     Card('C', '7')]
    player1_cards = [Card('H', '9'), Card('H', '10'), Card('H', 'J'), Card('H', 'K'), Card('H', 'Q'),
                     Card('H', 'A'), Card('D', '9'), Card('D', '10'), Card('D', 'J'), Card('D', 'K'),
                     Card('D', 'Q'), Card('D', 'A'), Card('S', '8'), Card('S', '9'), Card('S', '10'),
                     Card('S', 'J'), Card('S', 'K'), Card('S', 'Q'), Card('S', 'A'), Card('C', '8'),
                     Card('C', '9'), Card('C', '10'), Card('C', 'J'), Card('C', 'K'), Card('C', 'Q'),
                     Card('C', 'A')]
    players_cards = [player1_cards, player2_cards]
    return players_cards
Пример #29
0
 def __init__(self):
     """
     Initializes with 52 cards with suite & rank.
     """
     self.cards = [Card(s, r) for s in Card.SUITES for r in Card.RANKS]
Пример #30
0
def test_card_value_of_jack():
    """create a card with face value = J"""
    card = Card('S', 'J')
    card_value = card.value + 2
    assert card_value == 11