Exemple #1
0
	def __init__(self, players):
		self.deck = cardlib.Deck()
		self.deck.shuffle()
		self.hands = dict()
		for player in range(players):
			hand = List()
			hand.append(deck.pop())
			hand.append(deck.pop())
			self.hands[player](hand)
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
def test_pokerhand():
    #  Creating the pokerhand objects and then testing them against other pokerhands.
    deck = cl.Deck()
    deck.create_deck()
    hand = cl.Hand()
    hand2 = cl.Hand()
    for i in range(5):
        hand.add_card(deck.draw())
    for i in range(5):
        hand2.add_card(deck.draw())
    bph = hand.best_poker_hand()
    bph2 = hand2.best_poker_hand()
    assert bph > bph2
    assert bph == bph
    assert bph2 < bph
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
	def __init__(self):
		self.deck = cardlib.Deck()
		self.score = 0