class TestOnePair(TestCase): def setUp(self): self.one_pair_hand: Hand = Hand( Card(rank=Ranks.A.value, suit=Suits.CLUBS.value), Card(rank=Ranks.A.value, suit=Suits.DIAMONDS.value), Card(rank=Ranks.NINE.value, suit=Suits.HEARTS.value), Card(rank=Ranks.SIX.value, suit=Suits.SPADES.value), Card(rank=Ranks.FOUR.value, suit=Suits.DIAMONDS.value)) self.not_one_pair_hand: Hand = Hand( Card(rank=Ranks.K.value, suit=Suits.HEARTS.value), Card(rank=Ranks.K.value, suit=Suits.SPADES.value), Card(rank=Ranks.J.value, suit=Suits.CLUBS.value), Card(rank=Ranks.J.value, suit=Suits.DIAMONDS.value), Card(rank=Ranks.NINE.value, suit=Suits.DIAMONDS.value)) self.hand_strength = HandStrength(self.one_pair_hand) self.not_valid_one_pair_hand_strength = HandStrength( self.not_one_pair_hand) def test_is_one_pair_returns_true_for_valid_one_pair_hand(self): self.assertTrue(self.hand_strength.is_one_pair()) def test_is_one_pair_returns_false_for_invalid_one_pair_hand(self): self.assertFalse(self.not_valid_one_pair_hand_strength.is_one_pair())
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')