class TestFlush(TestCase): def setUp(self): self.flush_hand: Hand = Hand( Card(rank=Ranks.K.value, suit=Suits.HEARTS.value), Card(rank=Ranks.Q.value, suit=Suits.HEARTS.value), Card(rank=Ranks.TWO.value, suit=Suits.HEARTS.value), Card(rank=Ranks.FIVE.value, suit=Suits.HEARTS.value), Card(rank=Ranks.FOUR.value, suit=Suits.HEARTS.value)) self.not_flush_hand: Hand = Hand( Card(rank=Ranks.A.value, suit=Suits.HEARTS.value), Card(rank=Ranks.K.value, suit=Suits.HEARTS.value), Card(rank=Ranks.Q.value, suit=Suits.HEARTS.value), Card(rank=Ranks.J.value, suit=Suits.HEARTS.value), Card(rank=Ranks.TEN.value, suit=Suits.HEARTS.value)) self.hand_strength = HandStrength(self.flush_hand) self.not_valid_flush_hand_strength = HandStrength(self.not_flush_hand) def test_is_flush_returns_true_for_valid_flush_hand(self): self.assertTrue(self.hand_strength.is_flush()) def test_is_flush_returns_false_for_invalid_flush_hand(self): self.assertFalse(self.not_valid_flush_hand_strength.is_flush())
def get_hand_strength(self): hand_strength = HandStrength(self.hand) if hand_strength.is_royal_flush(): return HandsName.ROYAL_FLUSH.value if hand_strength.is_straight_flush(): return HandsName.STRAIGHT_FLUSH.value if hand_strength.is_four_of_a_kind(): return HandsName.FOUR_OF_A_KIND.value if hand_strength.is_full_house(): return HandsName.FULL_HOUSE.value if hand_strength.is_flush(): return HandsName.FLUSH.value if hand_strength.is_straight(): return HandsName.STRAIGHT.value if hand_strength.is_three_of_a_kind(): return HandsName.THREE_OF_A_KIND.value if hand_strength.is_two_pair(): return HandsName.TWO_OF_A_KIND.value if hand_strength.is_one_pair(): return HandsName.ONE_OF_A_PAIR.value if hand_strength.is_high_card(): return HandsName.HIGH_CARD.value else: raise Exception('Unknown Kind')