Пример #1
0
 def test_two_pair(self):
     sevens_with_fives = Hand.from_string('5D 5H 4S 7C 7S')
     sevens_with_fours = Hand.from_string('4D 4H 3S 7C 7S')
     sixes_with_threes = Hand.from_string('6D 6H 2S 3C 3S')
     self.assertGreater(sevens_with_fives, sevens_with_fours)
     self.assertGreater(sevens_with_fours, sixes_with_threes)
     self.assertGreater(sevens_with_fives, sixes_with_threes)
Пример #2
0
 def test_pair(self):
     fives_and_seven = Hand.from_string('5D 5H 4S 7C 6S')
     fives_and_six = Hand.from_string('5D 5H 3S 6C 4S')
     fours = Hand.from_string('4D 4H 2S 3C AS')
     self.assertGreater(fives_and_seven, fives_and_six)
     self.assertGreater(fives_and_six, fours)
     self.assertGreater(fives_and_seven, fours)
Пример #3
0
 def test_straight(self):
     five_high = Hand.from_string('5S 4S 3S 2S AS')
     six_high = Hand.from_string('2S 3S 4S 5S 6S')
     ace_high = Hand.from_string('TS JS QS KS AS')
     self.assertGreater(ace_high, six_high)
     self.assertGreater(six_high, five_high)
     self.assertGreater(ace_high, five_high)
Пример #4
0
 def test_three_of_a_kind(self):
     fives_with_ace = Hand.from_string('5D 5H 5S 7C AS')
     fives_with_three = Hand.from_string('5D 5H 5S 3C 2S')
     fours = Hand.from_string('4D 4H 4S 5C AS')
     self.assertGreater(fives_with_ace, fives_with_three)
     self.assertGreater(fives_with_three, fours)
     self.assertGreater(fives_with_ace, fours)
Пример #5
0
 def test_flush(self):
     king_queen = Hand.from_string('KS 5S QS 7S 4S')
     king_jack = Hand.from_string('KS 5S JS 7S 4S')
     queen_eight = Hand.from_string('QS 5S 8S 7S 4S')
     self.assertGreater(king_queen, king_jack)
     self.assertGreater(king_jack, queen_eight)
     self.assertGreater(king_queen, queen_eight)
Пример #6
0
 def test_full_house(self):
     fives_and_fours = Hand.from_string('5D 5H 5S 4S 4D')
     fives_and_threes = Hand.from_string('5D 5H 5S 3S 3D')
     fours_and_aces = Hand.from_string('4D 4H 4S AC AS')
     self.assertGreater(fives_and_fours, fives_and_threes)
     self.assertGreater(fives_and_threes, fours_and_aces)
     self.assertGreater(fives_and_fours, fours_and_aces)
Пример #7
0
 def test_four_of_a_kind(self):
     fives_with_ace = Hand.from_string('5D 5H 5S 5C AS')
     fives_with_two = Hand.from_string('5D 5H 5S 5C 2S')
     fours = Hand.from_string('4D 4H 4S 4C AS')
     self.assertGreater(fives_with_ace, fives_with_two)
     self.assertGreater(fives_with_two, fours)
     self.assertGreater(fives_with_ace, fours)
Пример #8
0
 def test_straight_flush(self):
     five_high_straight_flush = Hand.from_string('5S 4S 3S 2S AS')
     straight_flush = Hand.from_string('2S 3S 4S 5S 6S')
     royal_flush = Hand.from_string('TS JS QS KS AS')
     self.assertGreater(royal_flush, straight_flush)
     self.assertGreater(straight_flush, five_high_straight_flush)
     self.assertGreater(royal_flush, five_high_straight_flush)
Пример #9
0
 def test_valid(self):
     hand = Hand.from_string('4D 3D 5D 7H AD')
     self.assertEqual(
         hand,
         Hand((
             Card('4D'),
             Card('3D'),
             Card('5D'),
             Card('7H'),
             Card('AD'),
         )))
Пример #10
0
 def test_category_order(self):
     hands_from_lowest_to_highest = [
         Hand.from_string('TS 2S JH KS AS'),  # high card
         Hand.from_string('TS JS JH KS AS'),  # one pair
         Hand.from_string('TS JS JH TH AS'),  # two pair
         Hand.from_string('4D 4H 4S 7H 8D'),  # three of a kind
         Hand.from_string('5H 4S 3S 2D AS'),  # straight
         Hand.from_string('5S JS QS KS AS'),  # flush
         Hand.from_string('4D 4H 4S KS KD'),  # full house
         Hand.from_string('4D 4H 4S 4C 8D'),  # four of a kind
         Hand.from_string('2S 3S 4S 5S 6S'),  # straight flush
         Hand.from_string('TS JS QS KS AS'),  # royal flush
     ]
     resorted_hands = sorted(hands_from_lowest_to_highest)
     self.assertEqual(hands_from_lowest_to_highest, resorted_hands)
Пример #11
0
 def test_straight(self):
     hand = Hand.from_string('TS JH QS KS AS')
     self.assertEqual(hand.category, STRAIGHT)
Пример #12
0
 def test_five_high_straight(self):
     hand = Hand.from_string('5H 4S 3S 2D AS')
     self.assertEqual(hand.category, STRAIGHT)
Пример #13
0
 def test_two_pair(self):
     hand = Hand.from_string('TS JS JH TH AS')
     self.assertEqual(hand.category, TWO_PAIR)
Пример #14
0
 def test_three_of_a_kind(self):
     hand = Hand.from_string('4D 4H 4S 7H 8D')
     self.assertEqual(hand.category, THREE_OF_A_KIND)
Пример #15
0
 def test_one_pair(self):
     hand = Hand.from_string('TS JS JH KS AS')
     self.assertEqual(hand.category, ONE_PAIR)
Пример #16
0
 def test_high_card(self):
     hand = Hand.from_string('TS 2S JH KS AS')
     self.assertEqual(hand.category, HIGH_CARD)
Пример #17
0
 def test_flush(self):
     hand = Hand.from_string('5S JS QS KS AS')
     self.assertEqual(hand.category, FLUSH)
Пример #18
0
 def test_five_high_straight_flush(self):
     hand = Hand.from_string('5S 4S 3S 2S AS')
     self.assertEqual(hand.category, STRAIGHT_FLUSH)
Пример #19
0
 def test_four_of_a_kind(self):
     hand = Hand.from_string('4D 4H 4S 4C 8D')
     self.assertEqual(hand.category, FOUR_OF_A_KIND)
Пример #20
0
 def test_full_house(self):
     hand = Hand.from_string('4D 4H 4S KS KD')
     self.assertEqual(hand.category, FULL_HOUSE)
Пример #21
0
 def test_too_few_cards(self):
     with self.assertRaises(InvalidHand):
         Hand.from_string('4D 3D 3D 7H')
Пример #22
0
 def test_straight_flush(self):
     hand = Hand.from_string('2S 3S 4S 5S 6S')
     self.assertEqual(hand.category, STRAIGHT_FLUSH)
Пример #23
0
 def test_duplicate_cards(self):
     with self.assertRaises(InvalidHand):
         Hand.from_string('AD AH AS AC AD')
Пример #24
0
 def test_royal_flush(self):
     hand = Hand.from_string('TS JS QS KS AS')
     self.assertEqual(hand.category, ROYAL_FLUSH)
Пример #25
0
 def test_only_two_duplicates(self):
     with self.assertRaises(InvalidHand):
         Hand.from_string('4D 3D 3D 7H AD')