def test_nob(self): self.assertEqual( 1, score.score_hand(Card.from_str_list('Jc, 2c, Qc, 6h'), Card.from_str('4c'))) self.assertEqual( 0, score.score_hand(Card.from_str_list('Jc, 2c, Qc, 6h'), Card.from_str('4s')))
def test_flush(self): self.assertEqual( 5, score.score_hand(Card.from_str_list('ac, 2c, 9c, 7c'), Card.from_str('Jc'))) self.assertEqual( 4, score.score_hand(Card.from_str_list('ac, 2c, 9c, 7c'), Card.from_str('Jh'))) self.assertEqual( 0, score.score_hand(Card.from_str_list('ad, 2c, 9c, 7c'), Card.from_str('Jc')))
def test_fifteens(self): self.assertEqual( 6, score.score_hand(Card.from_str_list('10C, QD, KH, 2H'), Card.from_str('3S'))) self.assertEqual( 2, score.score_hand(Card.from_str_list('JC, 5D, 4H, 9S'), Card.from_str('7S'))) self.assertEqual( 4, score.score_hand(Card.from_str_list('JC, QD, 4H, 3S'), Card.from_str('AS')))
def test_runs(self): self.assertEqual( 4, score.score_hand(Card.from_str_list('2d,3d,4d'), Card.from_str('5D'))) self.assertEqual( 8, score.score_hand(Card.from_str_list('2d,3d,4d'), Card.from_str('4c'))) self.assertEqual( 17, score.score_hand(Card.from_str_list('2d,3d,4d,4c'), Card.from_str('4s')))
def test_three_of_a_kind(self): self.assertEqual( 6, score.score_hand(Card.from_str_list('JC, JD, JH, 2H'), Card.from_str('6S'))) self.assertEqual( 6, score.score_hand(Card.from_str_list('3c, 3d, 3s, qh'), Card.from_str('kh'))) self.assertEqual( 8, score.score_hand(Card.from_str_list('JC, JD, JH, 2H'), Card.from_str('2S')))
def test_flush_box(self): self.assertEqual( 5, score.score_hand(Card.from_str_list('ac,2c,9c,7c'), Card.from_str('Jc'), is_box=True)) self.assertEqual( 0, score.score_hand(Card.from_str_list('ac,2c,9c,7s'), Card.from_str('Jc'), is_box=True)) self.assertEqual( 0, score.score_hand(Card.from_str_list('ac,2c,9c,7c'), None, is_box=True))
def test_complex_hands(self): sc, bd = score.score_hand_with_breakdown( Card.from_str_list('2d, 3d, 4d, 5d'), Card.from_str('5s')) self.assertEqual(1, len(bd['pairs'])) self.assertEqual(2, len(bd['runs'])) self.assertEqual(1, len(bd['flushes'])) self.assertEqual(1, len(bd['fifteens'])) self.assertEqual(16, sc) str_rep = '''Runs : [2D, 3D, 4D, 5D], [2D, 3D, 4D, 5S] Flushes : [2D, 3D, 4D, 5D] Fifteens : [2D, 3D, 5D, 5S] Pairs : [5D, 5S]''' self.assertEqual(str_rep, score.breakdown_tostring(bd)) sc, bd = score.score_hand_with_breakdown( Card.from_str_list('jc, qc, kc, jd'), Card.from_str('js')) self.assertEqual(3, len(bd['pairs'])) self.assertEqual(3, len(bd['runs'])) self.assertEqual(15, sc) self.assertEqual( 29, score.score_hand(Card.from_str_list('jc,5d,5h,5s'), Card.from_str('5c')))
def test_pairs(self): self.assertEqual( 4, score.score_hand(Card.from_str_list('JS, JD, 6C, 2H'), Card.from_str('2C'))) self.assertEqual( 2, score.score_hand(Card.from_str_list('QS, JD, 6C, 2H'), Card.from_str('2C'))) self.assertEqual( 2, score.score_hand(Card.from_str_list('JS, QD, 3C, 3H'), Card.from_str('4C'))) self.assertEqual( 4, score.score_hand(Card.from_str_list('JS, JD, 3C, 3H'), Card.from_str('AC')))
def attempts_for_score_v1(deck, target_score, verbose=False): if verbose: print(f'Looking for score of {target_score}') attempts = 1 while True: deck.shuffle() h = deck.deal_one(4) t = deck.next_card() hs = score.score_hand(h, t) deck.return_cards(h) deck.return_card(t) if hs == target_score: if verbose: print( f'Found score of {target_score} after {attempts} attempts' ) break attempts += 1 return attempts
def test_four_of_a_kind(self): self.assertEqual( 12, score.score_hand(Card.from_str_list('QC, QD, QH, QS'), Card.from_str('6S')))
def test_pairs_no_turn(self): self.assertEqual( 2, score.score_hand(Card.from_str_list('JS, JD, 6C, 2H'), None)) self.assertEqual( 0, score.score_hand(Card.from_str_list('QS, JD, 6C, 2H'), None))
def test_flush_no_turn(self): self.assertEqual( 4, score.score_hand(Card.from_str_list('ac, 2c, 9c, 7c'), None))