def getNumberOfTries(job): i = 0 while True: i = i + 1 deck = Deck() deck.shuffle() hand = step(deck) if isRoyalFlush(hand): print job, "done" break return i
def test_get_discard_list_equals(self): """ Test that the list returned from get_discard_list() is equal to the internal discard list. """ deck = Deck() returned_list = deck.get_discard_list() self.assertEqual(returned_list, deck._discards)
def test_getitem(self): """ Test operation of the __getitem__ method. """ deck = Deck() get_list = deck.get_card_list() getitem_list = [deck[idx] for idx in range(52)] self.assertEqual(get_list, getitem_list)
def test_contains(self): """ Test operation of the __contains__ method. """ deck = Deck() get_list = deck.get_card_list() contains_list = [card for card in deck] self.assertEqual(get_list, contains_list)
def test_get_discard_list_not_same(self): """ Test that the list returned from get_discard_list() is not the same as the internal discard list, i.e. that the method is returning a copy. """ deck = Deck() returned_list = deck.get_discard_list() self.assertFalse(returned_list is deck._discards)
def test_shuffle_no_size_change(self): """ Test that the deck size doesn't change on shuffling (fairly unlikely error). """ deck = Deck() original_size = len(deck) deck.shuffle() shuffled_size = len(deck) self.assertEqual(original_size, shuffled_size)
def test_shuffle_shuffles(self): """ Test that the shuffled card list is different to the original card list. """ deck = Deck() original_list = deck.get_card_list() deck.shuffle() shuffled_list = deck.get_card_list() self.assertNotEqual(original_list, shuffled_list)
def test_setitem(self): """ Test operation of the __setitem__ method. """ deck1 = Deck() deck2 = Deck() d1_clist = deck1.get_card_list() d2_clist = deck1.get_card_list() self.assertEqual(d1_clist, d2_clist) deck1.shuffle() d1_clist = deck1.get_card_list() self.assertNotEqual(d1_clist, d2_clist) for idx, card in enumerate(d1_clist): deck2[idx] = card d2_clist = deck2.get_card_list() self.assertEqual(d1_clist, d2_clist)
def main(): """ main() function. """ hand_types = ["RF", "SF", "FK", "FH", "FL", "ST", "TK", "TP", "PR", "HI"] types_found = {"RF": 0, "SF": 0, "FK": 0, "FH": 0, "FL": 0, "ST": 0, "TK": 0, "TP": 0, "PR": 0, "HI": 0} expected = {"RF": 4, "SF": 36, "FK": 624, "FH": 3744, "FL": 5108, "ST": 10200, "TK": 54912, "TP": 123552, "PR": 1098240, "HI": 1302540} total_expected = 2598960 total_hands = 0 percent = 0 deck = Deck() cards = deck.draw(52) deck = Deck() hand = PokerHand(deck) # Loop through all hands and store number of hand types for a in range(48): for b in range(a + 1, 52): for c in range(b + 1, 52): for d in range(c + 1, 52): for e in range(d + 1, 52): cds = [cards[a], cards[b], cards[c], cards[d], cards[e]] hand._cards = cds hand.evaluate() types_found[hand.show_value(short=True)] += 1 total_hands += 1 # Print status indicator if total_hands % 25990 == 0: percent += 1 print "{0}%.....".format(percent) # Output results sumscores = 0 failed = False for hand_type in hand_types: if expected[hand_type] == types_found[hand_type]: result = "passed" else: result = "failed" failed = True print "{0}: {1} expected, {2} found...{3}.".format( hand_type, expected[hand_type], types_found[hand_type], result) sumscores += types_found[hand_type] if total_expected == sumscores: result = "passed" else: result = "failed" failed = True print "Total hands: {0} expected, {1} found...{2}".format( total_expected, sumscores, result) if not failed: print("All tests passed.") else: print("SOME TESTS FAILED!")