diff --git a/p054/poker.py b/p054/poker.py index 6b7d6af..dcb4684 100644 --- a/p054/poker.py +++ b/p054/poker.py @@ -174,7 +174,7 @@ class Hand: self.__rank = Hand.THREE_OF_A_KIND else: self.__rank = Hand.ONE_PAIR - mvalues = [m[0] for m in multiples] + mvalues = sorted([m[0] for m in multiples], reverse=True) self.__values = mvalues + [c.value for c in self.__cards if c.value not in mvalues] if not self.__rank: self.__rank = Hand.HIGH_CARD diff --git a/p054/test.py b/p054/test.py index c8abce8..5195195 100644 --- a/p054/test.py +++ b/p054/test.py @@ -46,6 +46,10 @@ class TestFiveCardHands(unittest.TestCase): low = poker.Hand(['AH', '2S', '3C', '4S', '5S']) high = poker.Hand(['2S', '3C', '4S', '5S', '6S']) self.assertTrue(low < high) + def test_compare_two_pair(self): + low = poker.Hand(['7S', '9D', 'JH', '7D', 'JS']) + high = poker.Hand(['AS', 'AD', '5C', '2D', '2H']) + self.assertTrue(low < high) def test_compare_ranks(self): for rank, hand in self.rank_hands.iteritems(): for rank2, hand2 in self.rank_hands.iteritems(): @@ -83,6 +87,10 @@ class TestSevenCardHands(unittest.TestCase): low = poker.Hand.create_best_hand(['AH', '2S', '3C', '4S', '9D', '4C', '5S']) high = poker.Hand.create_best_hand(['2S', '3C', '4S', '5S', '8D', 'TC', '6S']) self.assertTrue(low < high) + def test_compare_two_pair(self): + low = poker.Hand.create_best_hand(['3D', 'KC', '7S', '9D', 'JH', '7D', 'JS']) + high = poker.Hand.create_best_hand(['4D', '9H', 'AS', 'AD', '5C', '2D', '2H']) + self.assertTrue(low < high) def test_compare_ranks(self): for rank, hand in self.rank_hands.iteritems(): for rank2, hand2 in self.rank_hands.iteritems(): @@ -94,4 +102,4 @@ class TestSevenCardHands(unittest.TestCase): self.assertTrue(hand.rank() > hand2.rank(), '{0} > {1}'.format(poker.Hand.RANKS[rank], poker.Hand.RANKS[rank2])) if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main()