Example #1
0
 def test_winner_incase_of_two_pair_harnds(self):
     player_one = Hand('9D 9H 6C 8S 8C')  # (9, 9),(8, 8) => has high points
     player_two = Hand('2D 2H 6C 8S 8C')  # (2, 2),(8, 8)
     self.assertTrue(
         player_one.rank == player_two.rank and
         player_two.get_points() < player_one.get_points()
     )
Example #2
0
 def test_winner_incase_of_full_house(self):
     player_one = Hand('KH KC KD TC TD')    #(K, K, K)  => has high points
     player_two = Hand('QH QC QD TC TD')    #(Q, Q, Q)
     self.assertTrue(
         player_one.rank == player_two.rank and
         player_one.get_points() > player_two.get_points()
     )
Example #3
0
 def test_winner_incase_of_three_of_a_kind(self):
     player_one = Hand('8S 8D 8C 2H 5C')    #(8, 8, 8) => has high value
     player_two = Hand('AS AD AC 2H 5C')    #(A, A, A)
     self.assertTrue(
         player_one.rank == player_two.rank and
         player_one.get_points() > player_two.get_points()
     )
Example #4
0
 def test_winner_incase_of_four_of_a_kind(self):
     player_one = Hand('9S 9H 9C 9D TC')    # (9,9,9,9) => has high points
     player_two = Hand('3S 3H 3C 3D TC')    # (3,3,3,3)
     self.assertTrue(
         player_one.rank == player_two.rank and
         player_one.get_points() > player_two.get_points()
     )
Example #5
0
 def test_draw_condition(self):
     player_one = Hand('9S 9H 9C 9D TC')     # (9,9,9,9)  => same value
     player_two = Hand('9S 9H 9C 9D TC')     # (9,9,9,9)  => same value
     self.assertTrue(
         player_one.rank == player_two.rank and
         player_one.get_points() == player_two.get_points()
     )
Example #6
0
 def test_winner_incase_of_one_pair_hands(self):
     player_one = Hand('5H 5C 6S 7S KD')    # 5, 5
     player_two = Hand('2C 3S 8S 8D TD')    # 8, 8 => This hand has High Points as per Poker Rules
     self.assertTrue(
         player_one.rank == player_two.rank and
         player_two.get_points() > player_one.get_points()
     )
Example #7
0
    def test_cmp_method(self):
        high_card = Hand('QS 3D 7H TC 6D')
        straight = Hand('4D 5D 6D 7H 8D')

        self.assertTrue(high_card < straight)
        self.assertTrue(straight > high_card)

        dummy = Hand('QS 3D 7H TC 6D')
        self.assertTrue(dummy == high_card)
        self.assertFalse(dummy == straight)
        self.assertTrue(dummy != straight)
Example #8
0
 def test_winner_incase_of_one_pair_hands(self):
     player_one = Hand('5H 5C 6S 7S KD')  # 5, 5
     player_two = Hand(
         '2C 3S 8S 8D TD'
     )  # 8, 8 => This hand has High Points as per Poker Rules
     self.assertTrue(player_one.rank == player_two.rank
                     and player_two.get_points() > player_one.get_points())
Example #9
0
    def test_sorting_harnds(self):
        expected = [('TH JH QH KH AH', "Royal Flush", 10),
                    ('8D 9D TD JD QD', "Straight Flush", 9),
                    ('9S 9H 9C 9D TC', "Four Of A Kind", 8),
                    ('KH KC KD TC TD', "Full House", 7),
                    ('2D 6D 8D JD QD', "Flush", 6),
                    ('5D 6S 7C 8H 9H', "Straight", 5),
                    ('8S 8D 8C 2H 5C', "Three Of A Kind", 4),
                    ('9H 9D 5S 5C 3D', "Two Pair", 3),
                    ('6D 6C 8S 5H TD', "One Pair", 2),
                    ('QS 3D 7H TC 6D', "High Card", 1)]

        hands = []
        for hand in expected:
            hands.append(Hand(hand[0]))

        hands = shuffle(hands)
        qsort(hands, 0, len(hands) - 1)

        for exp, card in zip(expected, hands):
            self.assertEqual(exp[0], card.cards_repr())
            self.assertEqual(exp[1], card.get_category())
            self.assertEqual(exp[2], card.rank)
Example #10
0
 def test_straight(self):
     h = Hand('AH 2D 3C 4C 5D')
     self.assertTrue(h.is_straight())
Example #11
0
 def test_flush(self):
     h = Hand('QC TC 7C 6C 4C')
     self.assertTrue(h.is_flush())
Example #12
0
 def test_get_category(self):
     for d in self.regression_data:
         s, exp = d
         h = Hand(s)
         self.assertEqual(exp, h.get_category())
Example #13
0
 def test_three_of_a_kind(self):
     h = Hand('2H 2D 2C KC QD')
     self.assertTrue(h.is_three_of_a_kind())
Example #14
0
 def test_ranks(self):
     for h, n, r in self.ordered_data:
         h = Hand(h)
         self.assertEqual(h.rank, r)
Example #15
0
 def test_straight(self):
     h = Hand('AH 2D 3C 4C 5D')
     self.assertTrue(h.is_straight())
Example #16
0
 def test_winner_incase_of_two_pair_harnds(self):
     player_one = Hand('9D 9H 6C 8S 8C')  # (9, 9),(8, 8) => has high points
     player_two = Hand('2D 2H 6C 8S 8C')  # (2, 2),(8, 8)
     self.assertTrue(player_one.rank == player_two.rank
                     and player_two.get_points() < player_one.get_points())
Example #17
0
 def test_is_highcard(self):
     h = Hand('2H 5H 7D 8C 9S')
     self.assertTrue(h.is_highcard())
Example #18
0
 def test_flush(self):
     h = Hand('QC TC 7C 6C 4C')
     self.assertTrue(h.is_flush())
Example #19
0
 def test_straight_flush(self):
     h = Hand('TH JH QH KH AH')
     self.assertTrue(h.is_straight_flush())
Example #20
0
 def test_full_house(self):
     h = Hand('2H 3H 2D 3C 3D')
     self.assertTrue(h.is_fullhouse())
Example #21
0
 def test_four_of_a_kind(self):
     h = Hand('2H 7H 7D 7C 7S')
     self.assertTrue(h.is_four_of_a_kind())
Example #22
0
 def test_is_highcard(self):
     h = Hand('2H 5H 7D 8C 9S')
     self.assertTrue(h.is_highcard())
Example #23
0
 def test_full_house(self):
     h = Hand('2H 3H 2D 3C 3D')
     self.assertTrue(h.is_fullhouse())
Example #24
0
 def test_winner_incase_of_full_house(self):
     player_one = Hand('KH KC KD TC TD')  #(K, K, K)  => has high points
     player_two = Hand('QH QC QD TC TD')  #(Q, Q, Q)
     self.assertTrue(player_one.rank == player_two.rank
                     and player_one.get_points() > player_two.get_points())
Example #25
0
 def test_four_of_a_kind(self):
     h = Hand('2H 7H 7D 7C 7S')
     self.assertTrue(h.is_four_of_a_kind())
Example #26
0
 def test_draw_condition(self):
     player_one = Hand('9S 9H 9C 9D TC')  # (9,9,9,9)  => same value
     player_two = Hand('9S 9H 9C 9D TC')  # (9,9,9,9)  => same value
     self.assertTrue(player_one.rank == player_two.rank
                     and player_one.get_points() == player_two.get_points())
Example #27
0
 def test_get_category(self):
     for d in self.regression_data:
         s, exp = d
         h = Hand(s)
         self.assertEqual(exp, h.get_category())
Example #28
0
import argparse
import logging

from lib.poker import (Hand)

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)

if __name__ == "__main__":

    parser = argparse.ArgumentParser(
        description='Calculate Category of A Poker Hand')

    parser.add_argument(
        '--hand', help='flag to pass poker hand string to the Hand Class')

    args = parser.parse_args()

if args.hand:
    hand = Hand(args.hand)
    logging.info("Details: " + hand.__str__())
else:
    logging.info("Please pass all the positional Arguments and try again.")
Example #29
0
 def test_to_string_method(self):
     h = Hand('4D 5D 6D 7H 8D')
     self.assertEqual("<Hand ['4D 5D 6D 7H 8D'], 'Straight', 5>",
                      h.__str__())
Example #30
0
 def test_three_of_a_kind(self):
     h = Hand('2H 2D 2C KC QD')
     self.assertTrue(h.is_three_of_a_kind())
Example #31
0
 def test_two_pair(self):
     h = Hand('2H 7H 2D 3C 3D')
     self.assertTrue(h.is_two_pair())
Example #32
0
 def test_to_string_method(self):
     h = Hand('4D 5D 6D 7H 8D')
     self.assertEqual(
         "<Hand ['4D 5D 6D 7H 8D'], 'Straight', 5>",
         h.__str__()
     )
Example #33
0
 def test_winner_incase_of_three_of_a_kind(self):
     player_one = Hand('8S 8D 8C 2H 5C')  #(8, 8, 8) => has high value
     player_two = Hand('AS AD AC 2H 5C')  #(A, A, A)
     self.assertTrue(player_one.rank == player_two.rank
                     and player_one.get_points() > player_two.get_points())
Example #34
0
 def test_Hand_constructor_with_string_inputs(self):
     for input_exp in self.input_and_expectations:
         inp, expected, typ = input_exp
         h = Hand(inp)
         for c, e in zip(h.cards, expected):
             self.assertTrue(c.is_same_card(e))
Example #35
0
 def test_winner_incase_of_four_of_a_kind(self):
     player_one = Hand('9S 9H 9C 9D TC')  # (9,9,9,9) => has high points
     player_two = Hand('3S 3H 3C 3D TC')  # (3,3,3,3)
     self.assertTrue(player_one.rank == player_two.rank
                     and player_one.get_points() > player_two.get_points())
Example #36
0
 def test_straight_flush(self):
     h = Hand('TH JH QH KH AH')
     self.assertTrue(h.is_straight_flush())
Example #37
0
 def test_two_pair(self):
     h = Hand('2H 7H 2D 3C 3D')
     self.assertTrue(h.is_two_pair())
Example #38
0
 def test_one_pair(self):
     h = Hand('4H 4S KS 5D TS')
     self.assertTrue(h.is_one_pair())
Example #39
0
import argparse
import logging

from lib.poker import (
    Hand
)

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)

if __name__ == "__main__":

    parser = argparse.ArgumentParser(description='Calculate Category of A Poker Hand')

    parser.add_argument('--hand', help='flag to pass poker hand string to the Hand Class')

    args = parser.parse_args()

if  args.hand :
    hand = Hand(args.hand)
    logging.info("Details: " + hand.__str__())
else:
    logging.info("Please pass all the positional Arguments and try again.")
Example #40
0
 def test_one_pair(self):
     h = Hand('4H 4S KS 5D TS')
     self.assertTrue(h.is_one_pair())