コード例 #1
0
def test_high_card():
    #  Checking the highest card function
    hand = cl.Hand()
    hand.add_card(cl.AceCard(cl.Suit(2)))
    hand.add_card(cl.AceCard(cl.Suit(3)))
    hand.add_card(cl.NumberedCard(cl.Rank(2), cl.Suit(0)))
    k = cl.check_high_card(hand.cards)
    assert k[1] == hand.cards
    assert k[0] == cl.AceCard(cl.Suit(3)).give_value().value
    assert k[1][0].give_suit().value == cl.AceCard(
        cl.Suit(3)).give_suit().value
コード例 #2
0
def test_lt_eq_card():
    card1 = cardlib.NumberedCard(5, cardlib.Suits.Hearts)
    card2 = cardlib.NumberedCard(5, cardlib.Suits.Hearts)
    card3 = cardlib.AceCard(cardlib.Suits.Spades)

    assert card1 == card2
    assert card1 < card3
コード例 #3
0
def test_poker_hand():
    # Creates a poker table with 5 cards
    card1 = cardlib.NumberedCard(5, cardlib.Suits.Hearts)
    card2 = cardlib.NumberedCard(5, cardlib.Suits.Hearts)
    card3 = cardlib.AceCard(cardlib.Suits.Spades)
    card4 = cardlib.KingCard(cardlib.Suits.Clubs)
    card5 = cardlib.QueenCard(cardlib.Suits.Diamonds)

    poker_table = cardlib.Hand()
    poker_table.cards = [card1, card2, card3, card4, card5]

    # Creates two hands with two cards
    hand1 = cardlib.Hand()
    hand2 = cardlib.Hand()

    hand1.cards = [cardlib.NumberedCard(10, cardlib.Suits.Diamonds), cardlib.JackCard(cardlib.Suits.Hearts)]
    hand2.cards = [cardlib.NumberedCard(5, cardlib.Suits.Clubs), cardlib.NumberedCard(4, cardlib.Suits.Diamonds)]


    # Create two pokerhands using the hands cards and the poker_table cards
    pokerhand1 = hand1.best_poker_hand(poker_table.cards)   # Should return poker hand 'Straight'
    pokerhand2 = hand2.best_poker_hand(poker_table.cards)   # Should return poker hand 'Three of a kind'

    assert pokerhand1.poker_hand.name == 'Straight'
    assert pokerhand2.poker_hand.name == 'Threeofakind'

    # Testing < operand for the pokerhand comparison
    assert pokerhand2 < pokerhand1
コード例 #4
0
def test_sort_cards_is_sorting():
    my_hand = cardlib.Hand()

    my_hand.add_new_card(cardlib.AceCard(cardlib.Suit.CLUBS))
    my_hand.add_new_card(cardlib.NumberedCard(9, cardlib.Suit.SPADES))
    my_hand.add_new_card(cardlib.NumberedCard(2, cardlib.Suit.DIAMONDS))
    my_hand.add_new_card(cardlib.NumberedCard(8, cardlib.Suit.HEARTS))
    my_hand.add_new_card(cardlib.NumberedCard(5, cardlib.Suit.DIAMONDS))

    my_hand.sort_cards()

    # sort sorts card in order: 1 - suit 2-value
    assert my_hand.cards[0] == cardlib.NumberedCard(9, cardlib.Suit.SPADES)
    assert my_hand.cards[1] == cardlib.NumberedCard(8, cardlib.Suit.HEARTS)
    assert my_hand.cards[2] == cardlib.AceCard(cardlib.Suit.CLUBS)
    assert my_hand.cards[3] == cardlib.NumberedCard(2, cardlib.Suit.DIAMONDS)
    assert my_hand.cards[4] == cardlib.NumberedCard(5, cardlib.Suit.DIAMONDS)
コード例 #5
0
def test_cards():
    #  Testing so that the card functions give the correct values
    assert cl.NumberedCard(cl.Rank(2), cl.Suit(0)).card[0].value == 2
    assert cl.NumberedCard(cl.Rank(2), cl.Suit(0)).card[0].name == "Two"
    assert cl.NumberedCard(cl.Rank(2), cl.Suit(0)).card[1].value == 0
    assert cl.NumberedCard(cl.Rank(2), cl.Suit(0)).card[1].name == "Clubs"
    assert cl.JackCard(cl.Suit(0)).give_value().value == 11
    assert cl.QueenCard(cl.Suit(0)).give_value().value == 12
    assert cl.KingCard(cl.Suit(0)).give_value().value == 13
    assert cl.AceCard(cl.Suit(0)).give_value().value == 14
コード例 #6
0
def test_acecard_creates_playingcard():
    '''
        Test to verify that the acecard method creates a
        Playing card with value 14
        '''
    ACE_VALUE = 14
    for suit in cardlib.Suit:
        card = cardlib.AceCard(suit)
        assert type(card.get_value()) == int
        assert card.get_value() == ACE_VALUE
コード例 #7
0
def test_straight_flush():
    #  Checking the Straight Flush function
    deck = cl.Deck()
    deck.create_deck()
    hand = cl.Hand()
    for i in range(5):
        hand.add_card(deck.draw())
    k = cl.check_straight_flush(hand.cards)
    assert k[0] == 14
    assert k[1] == cl.AceCard(cl.Suit(3))
    hand.drop_cards(0)
    assert cl.check_straight_flush(hand.cards) is None
コード例 #8
0
def test_hand_and_deck():
    #  Creating the cards and then testing them towards the values they should have. Checking if the functions in the
    #  hand and deck classes are working as well as the values from the poker_hand class.
    deck = cl.Deck()
    deck.create_deck()  # Testing create_deck func
    hand = cl.Hand()
    hand2 = cl.Hand()
    n = 5
    k = [0, 2, 4]
    for i in range(n):
        hand.add_card(deck.draw())  # Testing add_card function
    hand.drop_cards(k)  # Testing drop_cards funtion
    hand2.add_card(cl.KingCard(cl.Suit(0)))
    hand2.add_card(cl.JackCard(cl.Suit(0)))
    assert len(hand.cards) == n - len(k)
    assert hand.cards == hand2.cards
    hand2.add_card(cl.AceCard(cl.Suit(0)))
    hand2.sort_cards()  # Test of sort function
    assert hand2.cards[0] == cl.AceCard(cl.Suit(0))
    poker_hand = hand2.best_poker_hand()
    assert poker_hand.type == cl.HandType(1)  # Test of best_poker_hand
    assert poker_hand.value == cl.AceCard(cl.Suit(0)).card[0]
    assert poker_hand.cards == hand2.cards
コード例 #9
0
def test_cards():
    card_1 = num_card(2, cardlib.Suit.clubs)
    assert card_1.get_value() == 2
    assert card_1.get_suit() == 0

    card_2 = cardlib.JackCard(cardlib.Suit.diamonds)
    assert card_2.get_value() == 11
    assert card_2.get_suit() == 1

    card_3 = cardlib.QueenCard(cardlib.Suit.spades)
    assert card_3.get_value() == 12
    assert card_3.get_suit() == 2

    card_4 = cardlib.KingCard(cardlib.Suit.diamonds)
    assert card_4.get_value() == 13
    assert card_4.get_suit() == 1

    card_5 = cardlib.AceCard(cardlib.Suit.diamonds)
    assert card_5.get_value() == 14
    assert card_5.get_suit() == 1
コード例 #10
0
def test_less_and_greater_than_of_playingcards():
    '''
        Test the __lt__ and __gt__ methods between two playing cards
        (less than & greater than)
        '''
    suit = cardlib.Suit.SPADES

    ace = cardlib.AceCard(suit)
    king = cardlib.KingCard(suit)
    queen = cardlib.QueenCard(suit)
    jack = cardlib.JackCard(suit)

    for value in range(2, 11):
        numberedcard = cardlib.NumberedCard(value, suit)
        assert ace > numberedcard
        assert king > numberedcard
        assert queen > numberedcard
        assert jack > numberedcard

        assert numberedcard < ace
        assert numberedcard < king
        assert numberedcard < queen
        assert numberedcard < jack

    assert ace > king
    assert ace > queen
    assert ace > jack

    assert king < ace
    assert king > queen
    assert king > jack

    assert queen < ace
    assert queen < king
    assert queen > jack

    assert jack < ace
    assert jack < king
    assert jack < queen