Example #1
0
    def test_get_value(self):
        a = PokerHand()

        #case 1: check the empty hand
        out = a.get_hand_value()
        self.assertTrue(out.type == HandValue.HV_HIGH_CARD)
        self.assertTrue(out.primary == 0)

        #case 2: check a straight flush
        a = PokerHand()
        a.add_cards('AhKhQhJhTh', None)
        out = a.get_hand_value()
        self.assertTrue(out.type == HandValue.HV_STR_FLUSH)
        self.assertTrue(out.primary == Card.CV_ACE)

        #case 3: check a four of a kind
        a = PokerHand()
        a.add_cards(['Ah', 'Ad', 'As', 'Ac', 'Th', '6d'], None)
        out = a.get_hand_value()
        self.assertTrue(out.type == HandValue.HV_QUADS)
        self.assertTrue(out.primary == Card.CV_ACE)

        #case 4: check a full house
        a = PokerHand()
        a.add_cards(['Ah', 'Ad', 'Ks', 'Kc', 'Kh', '6d'], None)
        out = a.get_hand_value()
        self.assertTrue(out.type == HandValue.HV_FULL_HOUSE)
        self.assertTrue(out.primary == Card.CV_KING)
        self.assertTrue(out.secondary == Card.CV_ACE)

        #case 5: check a flush
        a = PokerHand()
        a.add_cards(['Ah', 'Ad', 'Kh', 'Jh', '5h', '6h'], None)
        out = a.get_hand_value()
        self.assertTrue(out.type == HandValue.HV_FLUSH)

        #case 6: check a straight
        a = PokerHand()
        a.add_cards(['Ah', '2d', '3s', '4d', '5h', 'Kh'], None)
        out = a.get_hand_value()
        self.assertTrue(out.type == HandValue.HV_STRAIGHT)

        #case 7: check a three of a kind
        a = PokerHand()
        a.add_cards(['Ah', '2d', '3s', '5d', '5h', '5s'], None)
        out = a.get_hand_value()
        self.assertTrue(out.type == HandValue.HV_TRIPS)
        self.assertTrue(out.primary == Card.CV_FIVE)

        #case 8: check two pair
        a = PokerHand()
        a.add_cards(['Ah', 'Ad', '3s', '3d', '4h', '5s'], None)
        out = a.get_hand_value()
        self.assertTrue(out.type == HandValue.HV_TWO_PAIR)
        self.assertTrue(out.primary == Card.CV_ACE)
        self.assertTrue(out.secondary == Card.CV_THREE)

        #case 9: check a pair
        a = PokerHand()
        a.add_cards('AhAd2sJd4h5s', None)
        out = a.get_hand_value()
        self.assertTrue(out.type == HandValue.HV_PAIR)
        self.assertTrue(out.primary == Card.CV_ACE)

        #case 10: check a high card hand
        a = PokerHand()
        a.add_cards('AhQd2sJd4h5s', None)
        out = a.get_hand_value()
        self.assertTrue(out.type == HandValue.HV_HIGH_CARD)