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() )
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() )
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() )
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() )
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() )
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() )
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)
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())
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)
def test_straight(self): h = Hand('AH 2D 3C 4C 5D') self.assertTrue(h.is_straight())
def test_flush(self): h = Hand('QC TC 7C 6C 4C') self.assertTrue(h.is_flush())
def test_get_category(self): for d in self.regression_data: s, exp = d h = Hand(s) self.assertEqual(exp, h.get_category())
def test_three_of_a_kind(self): h = Hand('2H 2D 2C KC QD') self.assertTrue(h.is_three_of_a_kind())
def test_ranks(self): for h, n, r in self.ordered_data: h = Hand(h) self.assertEqual(h.rank, r)
def test_straight(self): h = Hand('AH 2D 3C 4C 5D') self.assertTrue(h.is_straight())
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())
def test_is_highcard(self): h = Hand('2H 5H 7D 8C 9S') self.assertTrue(h.is_highcard())
def test_flush(self): h = Hand('QC TC 7C 6C 4C') self.assertTrue(h.is_flush())
def test_straight_flush(self): h = Hand('TH JH QH KH AH') self.assertTrue(h.is_straight_flush())
def test_full_house(self): h = Hand('2H 3H 2D 3C 3D') self.assertTrue(h.is_fullhouse())
def test_four_of_a_kind(self): h = Hand('2H 7H 7D 7C 7S') self.assertTrue(h.is_four_of_a_kind())
def test_is_highcard(self): h = Hand('2H 5H 7D 8C 9S') self.assertTrue(h.is_highcard())
def test_full_house(self): h = Hand('2H 3H 2D 3C 3D') self.assertTrue(h.is_fullhouse())
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())
def test_four_of_a_kind(self): h = Hand('2H 7H 7D 7C 7S') self.assertTrue(h.is_four_of_a_kind())
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())
def test_get_category(self): for d in self.regression_data: s, exp = d h = Hand(s) self.assertEqual(exp, h.get_category())
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.")
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__())
def test_three_of_a_kind(self): h = Hand('2H 2D 2C KC QD') self.assertTrue(h.is_three_of_a_kind())
def test_two_pair(self): h = Hand('2H 7H 2D 3C 3D') self.assertTrue(h.is_two_pair())
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__() )
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())
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))
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())
def test_straight_flush(self): h = Hand('TH JH QH KH AH') self.assertTrue(h.is_straight_flush())
def test_two_pair(self): h = Hand('2H 7H 2D 3C 3D') self.assertTrue(h.is_two_pair())
def test_one_pair(self): h = Hand('4H 4S KS 5D TS') self.assertTrue(h.is_one_pair())
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.")
def test_one_pair(self): h = Hand('4H 4S KS 5D TS') self.assertTrue(h.is_one_pair())