Exemple #1
0
    def test_sorts_cards(self):
        two_of_spades = Card(rank="2", suit="Spades")
        five_of_diamonds = Card(rank="5", suit="Diamonds")
        five_of_hearts = Card(rank="5", suit="Hearts")
        eight_of_hearts = Card(rank="8", suit="Hearts")
        ace_of_clubs = Card(rank="Ace", suit="Clubs")

        unsorted_cards = [
            five_of_diamonds,
            two_of_spades,
            five_of_hearts,
            ace_of_clubs,
            eight_of_hearts
        ]
        unsorted_cards.sort()

        self.assertEqual(
            unsorted_cards,
            [
                two_of_spades,
                five_of_diamonds,
                five_of_hearts,
                eight_of_hearts,
                ace_of_clubs
            ]
        )
Exemple #2
0
def test_hand():
    for tc in test_cases:
        cards_sorted = hand(tc["hand"])
        for i, card in enumerate(cards_sorted):
            assert card == Card(tc["cards_sorted"][i])
        cards_unsorted = hand(tc["hand"], sort=False)
        for i, card in enumerate(cards_unsorted):
            assert card == Card(tc["cards_unsorted"][i])
Exemple #3
0
 def test_card_compare(self):
     card1 = Card(u"4♣")
     card2 = Card(u"9♣")
     card3 = Card(u"10♣")
     card4 = Card(u"J♣")
     self.assertTrue(card2 > card1)
     self.assertTrue(card3 > card2)
     self.assertTrue(card4 > card3)
Exemple #4
0
 def test_pair(self):
     # Given
     hand = [
         Card(CardFace.Two, CardSuit.Clubs),
         Card(CardFace.Four, CardSuit.Spades),
         Card(CardFace.Five, CardSuit.Clubs),
         Card(CardFace.Six, CardSuit.Clubs),
         Card(CardFace.Six, CardSuit.Hearts),
     ]
Exemple #5
0
 def test_three_of_kind_of_8_third_to_last_pos(self):
     card_list = [
         Card("C","9"),
         Card("H","10"),
         Card("H","8"), 
         Card("D","8"), 
         Card("S","8"), 
     ]
     hand = Hand(card_list)
     self.assertEqual(hand.result(), "Three of a kind")
Exemple #6
0
 def test_three_of_kind_of_7_first_until_third_pos(self):
     card_list = [
         Card("H","7"), 
         Card("D","7"), 
         Card("S","7"), 
         Card("C","9"),
         Card("H","10"),
     ]
     hand = Hand(card_list)
     self.assertEqual(hand.result(), "Three of a kind")
Exemple #7
0
 def test_two_pairs_7_and_9_at_first_until_four_pos(self):
     card_list = [
         Card("H","7"), 
         Card("S","7"), 
         Card("H","9"), 
         Card("C","9"),
         Card("H","10"),
     ]
     hand = Hand(card_list)
     self.assertEqual(hand.result(), "Two Pairs")
Exemple #8
0
 def test_pair_6_at_first_and_second_position(self):
     card_list = [
         Card("H","6"), 
         Card("C","6"), 
         Card("H","8"), 
         Card("H","9"),
         Card("H","10"),
     ]
     hand = Hand(card_list)
     self.assertEqual(hand.result(), "One Pair")
Exemple #9
0
 def test_pair_de_7_na_second_and_fourth_position(self):
     card_list = [
         Card("H","9"), 
         Card("H","7"), 
         Card("H","8"), 
         Card("C","7"),
         Card("H","10"),
     ]
     hand = Hand(card_list)
     self.assertEqual(hand.result(), "One Pair")
Exemple #10
0
 def test_high_card_hand(self):
     card_list = [
         Card("H","6"), 
         Card("C","5"), 
         Card("H","8"), 
         Card("D","2"),
         Card("H","10"),
     ]
     hand = Hand(card_list)
     self.assertEqual(hand.result(), "High Card")
 def test_cmp_same_ranks_same_3_suits(self):
     score1 = TraditionalPokerScore(
         TraditionalPokerScore.NO_PAIR,
         [Card(14, 0), Card(11, 1), Card(10, 3), Card(9, 2), Card(7, 2)]
     )
     score2 = TraditionalPokerScore(
         TraditionalPokerScore.NO_PAIR,
         [Card(14, 0), Card(11, 1), Card(10, 3), Card(9, 1), Card(7, 1)]
     )
     self._test_cmp(score1, score2)
Exemple #12
0
 def test_four_of_8_second_to_last_pos(self):
     card_list = [
         Card("C","9"),
         Card("C","8"),
         Card("H","8"), 
         Card("D","8"), 
         Card("S","8"), 
     ]
     hand = Hand(card_list)
     self.assertEqual(hand.result(), "Four of a kind")
 def test_cmp_different_categories(self):
     highest_card = HoldemPokerScore(
         HoldemPokerScore.NO_PAIR,
         [Card(13, 0), Card(11, 1), Card(10, 1), Card(9, 0), Card(7, 2)]
     )
     four_oak = HoldemPokerScore(
         HoldemPokerScore.QUADS,
         [Card(14, 3), Card(14, 2), Card(14, 1), Card(14, 0), Card(9, 0)]
     )
     self._test_cmp(four_oak, highest_card)
Exemple #14
0
 def test_full_house_of_8_and_9(self):
     card_list = [
         Card("C","9"),
         Card("H","9"),
         Card("H","8"), 
         Card("D","8"), 
         Card("S","8"), 
     ]
     hand = Hand(card_list)
     self.assertEqual(hand.result(), "Full house")
 def test_cmp_same_categories(self):
     four_9 = HoldemPokerScore(
         HoldemPokerScore.QUADS,
         [Card(9, 3), Card(9, 2), Card(9, 1), Card(9, 0), Card(14, 2)]
     )
     four_8 = HoldemPokerScore(
         HoldemPokerScore.QUADS,
         [Card(8, 3), Card(8, 2), Card(8, 1), Card(8, 0), Card(14, 0)]
     )
     self._test_cmp(four_9, four_8)
 def test_cmp_same_ranks(self):
     # In the traditional poker game, suits matter (hearts, diamonds, clubs and spades)
     score1 = TraditionalPokerScore(
         TraditionalPokerScore.NO_PAIR,
         [Card(14, 1), Card(11, 0), Card(10, 1), Card(9, 0), Card(7, 2)]
     )
     score2 = TraditionalPokerScore(
         TraditionalPokerScore.NO_PAIR,
         [Card(14, 0), Card(11, 1), Card(10, 3), Card(9, 1), Card(7, 1)]
     )
     self._test_cmp(score1, score2)
Exemple #17
0
 def test_create_52_cards(self):
     cards = Card.create_52_cards()
     self.assertEqual(len(cards), 52)
     self.assertEqual(
         cards[0],
         Card("2", "Hearts")
     )
     self.assertEqual(
         cards[-1],
         Card("Ace", "Clubs")
     )
Exemple #18
0
 def test_figures_out_four_of_a_kind_is_best_card(self):
     cards = [
         Card("Ace", "Diamonds"),
         Card("Ace", "Hearts"),
         Card("Ace", "Clubs"),
         Card("Ace", "Spades"),
         Card("King", "Diamonds")
     ]
     hand = Hand()
     hand.add_cards(cards)
     self.assertEqual(hand.best_rank(), "Four of a Kind")
 def test_cmp_straight_flush(self):
     min_straight = TraditionalPokerScore(
         TraditionalPokerScore.STRAIGHT_FLUSH,
         [Card(10, 3), Card(9, 3), Card(8, 3), Card(7, 3), Card(14, 3)]
     )
     max_straight = TraditionalPokerScore(
         TraditionalPokerScore.STRAIGHT_FLUSH,
         [Card(14, 2), Card(13, 2), Card(12, 2), Card(11, 2), Card(10, 2)]
     )
     self.assertGreater(min_straight.cmp(max_straight), 0)
     self.assertLess(max_straight.cmp(min_straight), 0)
Exemple #20
0
 def test_figures_out_royal_flush_is_best_card(self):
     cards = [
         Card("10", "Diamonds"),
         Card("Jack", "Diamonds"),
         Card("Queen", "Diamonds"),
         Card("King", "Diamonds"),
         Card("Ace", "Diamonds")
     ]
     hand = Hand()
     hand.add_cards(cards)
     self.assertEqual(hand.best_rank(), "Royal Flush")
Exemple #21
0
 def test_figures_out_straight_flush_is_best_card(self):
     cards = [
         Card("6", "Diamonds"),
         Card("7", "Diamonds"),
         Card("8", "Diamonds"),
         Card("9", "Diamonds"),
         Card("10", "Diamonds")
     ]
     hand = Hand()
     hand.add_cards(cards)
     self.assertEqual(hand.best_rank(), "Straight Flush")
    def test_remove_specified_number_of_cards_from_deck(self):
        ace = Card("Ace", "Hearts")
        king = Card("King", "Clubs")
        queen = Card("Queen", "Diamonds")
        cards = [ace, king, queen]

        deck = Deck()
        deck.add_cards(cards)

        self.assertEqual(deck.deal_cards(2), [ace, king])
        self.assertEqual(deck.cards, [queen])
Exemple #23
0
 def test_figures_out_full_house_is_best_card(self):
     cards = [
         Card("Ace", "Diamonds"),
         Card("Ace", "Hearts"),
         Card("Ace", "Clubs"),
         Card("King", "Spades"),
         Card("King", "Diamonds")
     ]
     hand = Hand()
     hand.add_cards(cards)
     self.assertEqual(hand.best_rank(), "Full House")
 def test_cmp_AA_with_AA(self):
     score1 = HoldemPokerScore(
         HoldemPokerScore.PAIR,
         [Card(14, 3), Card(14, 2)]
     )
     score2 = HoldemPokerScore(
         HoldemPokerScore.PAIR,
         [Card(14, 1), Card(14, 0)]
     )
     self.assertEquals(0, score1.cmp(score2))
     self.assertEquals(0, score2.cmp(score1))
 def test_cmp_straight_flush(self):
     min_straight = HoldemPokerScore(
         HoldemPokerScore.STRAIGHT_FLUSH,
         [Card(5, 3), Card(4, 3), Card(3, 3), Card(2, 3), Card(14, 3)]
     )
     max_straight = HoldemPokerScore(
         HoldemPokerScore.STRAIGHT_FLUSH,
         [Card(14, 2), Card(13, 2), Card(12, 2), Card(11, 2), Card(10, 2)]
     )
     self.assertLess(min_straight.cmp(max_straight), 0)
     self.assertGreater(max_straight.cmp(min_straight), 0)
 def test_cmp_same_cards(self):
     score1 = HoldemPokerScore(
         HoldemPokerScore.NO_PAIR,
         [Card(14, 0), Card(11, 1), Card(10, 3), Card(9, 2), Card(7, 2)]
     )
     score2 = HoldemPokerScore(
         HoldemPokerScore.NO_PAIR,
         [Card(14, 0), Card(11, 1), Card(10, 3), Card(9, 2), Card(7, 2)]
     )
     self.assertEqual(score1.cmp(score2), 0)
     self.assertEqual(score2.cmp(score1), 0)
Exemple #27
0
    def test_figures_out_two_pairs_is_best_card(self):
        cards = [
            Card("Ace", "Diamonds"),
            Card("Ace", "Clubs"),
            Card("King", "Diamonds"),
            Card("King", "Clubs"),
            Card("5", "Clubs"),
        ]

        hand = Hand()
        hand.add_cards(cards)
        self.assertEqual(hand.best_rank(), "Two Pair")
Exemple #28
0
    def test_figures_out_three_of_the_kind_is_best_card(self):
        cards = [
            Card("Ace", "Diamonds"),
            Card("Ace", "Clubs"),
            Card("Ace", "Diamonds"),
            Card("King", "Clubs"),
            Card("5", "Clubs"),
        ]

        hand = Hand()
        hand.add_cards(cards)
        self.assertEqual(hand.best_rank(), "Three of a Kind")
 def test_cmp_shorter_and_longer_sequence_same_cards(self):
     score1 = HoldemPokerScore(
         HoldemPokerScore.NO_PAIR,
         [Card(14, 0), Card(11, 1), Card(10, 3), Card(9, 2), Card(7, 2)]
     )
     score2 = HoldemPokerScore(
         HoldemPokerScore.NO_PAIR,
         [Card(14, 0), Card(11, 1), Card(10, 3), Card(9, 2)]
     )
     self._test_cmp(score1, score2)
    def test_detect_and_cmp_integration(self):
        board = [Card(14, 3), Card(14, 2), Card(14, 1), Card(14, 0), Card(13, 0)]
        player1 = [Card(12, 3), Card(9, 2)]
        player2 = [Card(11, 3), Card(7, 2)]

        sd = HoldemPokerScoreDetector()
        score1 = sd.get_score(player1 + board)
        score2 = sd.get_score(player2 + board)
        self.assertEquals(0, score1.cmp(score2))
        self.assertEquals(0, score2.cmp(score1))