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_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 next_pegging_card(self, stack, hand, turn_card): if not hand: return None print(f'\nYour hand is {hand}') stack_total = sum([x.value for x in stack]) go_allowed = (min([x.value for x in hand]) + stack_total) > 31 while True: try: user_input = input('\nWhat will you peg next (return for GO)? ') if not user_input: if go_allowed: return None else: print('GO not allowed, you can play') continue card = Card.from_str(user_input) if card in hand: if (card.value + stack_total) > 31: print('Total would be more than 31, try again') else: return card else: print('Selection is not a subset of your cards_deprecated, try again') except ValueError as e: print(f'Input error "{e}"')
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 test_pegging(self): dealer = Card.from_str_list('AD, 3D, 5D, 7S') non_dealer = Card.from_str_list('QH, 10H, 7H, 5C') self._game.pegging(self._p1, self._p2, dealer, non_dealer, Card.from_str('KC'), self._board) # QH, AD, 10H, 3D, 7H = 31 scored by non_dealer 2+1 points # 5D 5C 7S = pair for non dealer 2, last card for dealer, 1 point self.assertEqual((1, 0, 0), self._collector.averages(self._p1)) self.assertEqual((4, 0, 0), self._collector.averages(self._p2))
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_score_hand_with_breakdown(self): sc, bd = score.score_hand_with_breakdown( Card.from_str_list('JS, JD, 6C, 2H'), Card.from_str('2C')) self.assertEqual(4, sc) self.assertEqual(2, len(bd['pairs']))
def test_set_equality(self): c1 = Card.from_str('JH') c2 = Card.from_str('JH') self.assertEqual(c1, c2) self.assertEqual({c1}, {c2})
def test_from_str(self): self.assertEqual(Card.from_str('AD'), self.ace_of_diamonds) self.assertEqual(Card.from_str('1D'), self.ace_of_diamonds) self.assertEqual(Card.from_str('ad'), self.ace_of_diamonds) self.assertEqual(Card.from_str('1d'), self.ace_of_diamonds) self.assertEqual(Card.from_str('10S'), self.ten_of_spades) self.assertEqual(Card.from_str('10s'), self.ten_of_spades) self.assertEqual(Card.from_str('5C'), self.five_of_clubs) self.assertEqual(Card.from_str('5c'), self.five_of_clubs) self.assertEqual(Card.from_str('JH'), self.jack_of_hearts) self.assertEqual(Card.from_str('Jh'), self.jack_of_hearts) self.assertEqual(Card.from_str('11H'), self.jack_of_hearts) self.assertEqual(Card.from_str('11h'), self.jack_of_hearts)