mirror of
https://github.com/correl/euler.git
synced 2024-11-27 19:19:50 +00:00
Corrected: Values not sorted properly for hands with multiple multiples. Added a
test case to handle it. git-svn-id: file:///srv/svn/euler@52 e5f4c3ec-3c0c-11df-b522-21efaa4426b5
This commit is contained in:
parent
ad80b41e06
commit
7ab229ba18
2 changed files with 10 additions and 2 deletions
|
@ -174,7 +174,7 @@ class Hand:
|
||||||
self.__rank = Hand.THREE_OF_A_KIND
|
self.__rank = Hand.THREE_OF_A_KIND
|
||||||
else:
|
else:
|
||||||
self.__rank = Hand.ONE_PAIR
|
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]
|
self.__values = mvalues + [c.value for c in self.__cards if c.value not in mvalues]
|
||||||
if not self.__rank:
|
if not self.__rank:
|
||||||
self.__rank = Hand.HIGH_CARD
|
self.__rank = Hand.HIGH_CARD
|
||||||
|
|
|
@ -46,6 +46,10 @@ class TestFiveCardHands(unittest.TestCase):
|
||||||
low = poker.Hand(['AH', '2S', '3C', '4S', '5S'])
|
low = poker.Hand(['AH', '2S', '3C', '4S', '5S'])
|
||||||
high = poker.Hand(['2S', '3C', '4S', '5S', '6S'])
|
high = poker.Hand(['2S', '3C', '4S', '5S', '6S'])
|
||||||
self.assertTrue(low < high)
|
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):
|
def test_compare_ranks(self):
|
||||||
for rank, hand in self.rank_hands.iteritems():
|
for rank, hand in self.rank_hands.iteritems():
|
||||||
for rank2, hand2 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'])
|
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'])
|
high = poker.Hand.create_best_hand(['2S', '3C', '4S', '5S', '8D', 'TC', '6S'])
|
||||||
self.assertTrue(low < high)
|
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):
|
def test_compare_ranks(self):
|
||||||
for rank, hand in self.rank_hands.iteritems():
|
for rank, hand in self.rank_hands.iteritems():
|
||||||
for rank2, hand2 in self.rank_hands.iteritems():
|
for rank2, hand2 in self.rank_hands.iteritems():
|
||||||
|
|
Loading…
Reference in a new issue