def test_hand_rank(self): """ Test the output of a hand_rank""" sf = "6C 7C 8C 9C TC".split() fk = "9D 9H 9S 9C 7D".split() fh = "TD TC TH 7C 7D".split() self.assertEqual(poker_game.hand_rank(sf), (8, 10)) self.assertEqual(poker_game.hand_rank(fk), (7, 9, 7)) self.assertEqual(poker_game.hand_rank(fh), (6, 10, 7))
def hand_percentages(n_hands=700*1000): """ Sample n_hands random and print a table of percentages for each type of hand """ label = ["Higer card", "One pair", "Two pairs", "Three of a kind", "Straight", "Flush", "Full House", "Four of a kind", "Straight Flush"] counts = [0]*9 for i in xrange(n_hands//10): for hand in deal.deal_2(10): ranking = poker_game.hand_rank(hand)[0] counts[ranking] += 1 for i in reversed(xrange(9)): print "{0:14s} {1:6.3f} %".format(label[i], 100.*counts[i]/n_hands)