def test_is_full_house_should_return_false(self): card1 = Card(DeckSuite.CLOVERS, DeckValue.JACK) card2 = Card(DeckSuite.PIKES, DeckValue.ACE) card3 = Card(DeckSuite.HEARTS, DeckValue.JACK) card4 = Card(DeckSuite.TILES, DeckValue.KING) card5 = Card(DeckSuite.PIKES, DeckValue.KING) self.assertFalse( HandsHelper.is_full_house(card1, card2, card3, card4, card5))
def test_is_full_house_should_return_true_for_three_and_two_cards_with_same_value( self): card1 = Card(DeckSuite.CLOVERS, DeckValue.JACK) card2 = Card(DeckSuite.PIKES, DeckValue.JACK) card3 = Card(DeckSuite.HEARTS, DeckValue.JACK) card4 = Card(DeckSuite.TILES, DeckValue.KING) card5 = Card(DeckSuite.PIKES, DeckValue.KING) self.assertTrue( HandsHelper.is_full_house(card1, card2, card3, card4, card5))
def select_strongest_hand(*hands: Hand) -> Hand: royal_flush = any( HandsHelper.is_royal_flush(*hand.cards) for hand in hands) if royal_flush: return next(x for x in hands if royal_flush) four_of_kind = any( HandsHelper.is_four_of_kind(*hand.cards) for hand in hands) if four_of_kind: return next(x for x in hands if four_of_kind) full_house = any(HandsHelper.is_full_house(*hand.cards) for hand in hands) if full_house: return next(x for x in hands if full_house) three_of_kind = any( HandsHelper.is_three_of_kind(*hand.cards) for hand in hands) if three_of_kind: return next(x for x in hands if three_of_kind) two_pair = any(HandsHelper.is_two_pair(*hand.cards) for hand in hands) if two_pair: return next(x for x in hands if two_pair) one_pair = any(HandsHelper.is_one_pair(*hand.cards) for hand in hands) if one_pair: return next(x for x in hands if one_pair)