Beispiel #1
0
    def test_card__cmp__(self):
        card1 = Card('4', 'C')
        card2 = Card('T', 'C')

        self.assertTrue(card1 < card2)
        self.assertTrue(card2 > card1)
        self.assertTrue(card1 == card1)
Beispiel #2
0
 def setUp(self):
     self.cards_string = '4D 4D 4D 7H 8D'
     self.expected_cards = [
         Card('4', 'D'),
         Card('4', 'D'),
         Card('4', 'D'),
         Card('7', 'H'),
         Card('8', 'D'),
     ]
Beispiel #3
0
 def test_is_straight_flush(self):
     hand = Hand([
         Card('T', 'D'),
         Card('J', 'D'),
         Card('Q', 'D'),
         Card('A', 'D'),
         Card('K', 'D'),
     ])
     self.assertTrue(PokerRules.is_royal_flush(hand))
Beispiel #4
0
    def test_is_flush(self):
        hand = Hand([
            Card('A', 'D'),
            Card('2', 'D'),
            Card('3', 'D'),
            Card('4', 'D'),
            Card('5', 'D')
        ])

        self.assertTrue(PokerRules.is_flush(hand))
Beispiel #5
0
    def test_is_full_house(self):
        hand = Hand([
            Card('2', 'C'),
            Card('3', 'S'),
            Card('2', 'D'),
            Card('3', 'D'),
            Card('2', 'H'),
        ])

        self.assertTrue(PokerRules.is_full_house(hand))
Beispiel #6
0
    def test_is_one_pair(self):
        hand = Hand([
            Card('2', 'C'),
            Card('T', 'D'),
            Card('6', 'S'),
            Card('4', 'D'),
            Card('2', 'H'),
        ])

        self.assertTrue(PokerRules.is_one_pair(hand))
Beispiel #7
0
    def test_is_tree_of_a_kind(self):
        hand = Hand([
            Card('2', 'C'),
            Card('2', 'D'),
            Card('3', 'S'),
            Card('4', 'D'),
            Card('2', 'H'),
        ])

        self.assertTrue(PokerRules.is_tree_of_a_kind(hand))
Beispiel #8
0
    def test_is_straight(self):
        hand = Hand([
            Card('2', 'C'),
            Card('3', 'D'),
            Card('6', 'D'),
            Card('4', 'H'),
            Card('5', 'S'),
        ])

        self.assertTrue(PokerRules.is_straight(hand))
Beispiel #9
0
    def test_untie_royal_flush(self):
        royal_flush1 = Hand([
            Card('T', 'C'),
            Card('J', 'C'),
            Card('Q', 'C'),
            Card('K', 'C'),
            Card('A', 'C'),
        ])

        royal_flush2 = Hand([
            Card('T', 'D'),
            Card('J', 'D'),
            Card('Q', 'D'),
            Card('K', 'D'),
            Card('A', 'D'),
        ])

        self.assertEquals(royal_flush1, royal_flush2)
Beispiel #10
0
    def test_is_high_card(self):
        hand = Hand([
            Card('2', 'C'),
            Card('T', 'D'),
            Card('6', 'S'),
            Card('4', 'D'),
            Card('8', 'H'),
        ])

        self.assertTrue(PokerRules.is_high_card(hand))

        hand = Hand([
            Card('2', 'C'),
            Card('2', 'D'),
            Card('6', 'S'),
            Card('4', 'D'),
            Card('8', 'H'),
        ])

        self.assertFalse(PokerRules.is_high_card(hand))
Beispiel #11
0
    def test_untie_straight_flush(self):
        straight_flush1 = Hand([
            Card('9', 'C'),
            Card('T', 'C'),
            Card('J', 'C'),
            Card('Q', 'C'),
            Card('K', 'C'),
        ])

        straight_flush2 = Hand([
            Card('9', 'D'),
            Card('T', 'D'),
            Card('J', 'D'),
            Card('Q', 'D'),
            Card('K', 'D'),
        ])
        self.assertEquals(straight_flush1, straight_flush2)

        lower_straight_flush = Hand([
            Card('8', 'C'),
            Card('9', 'C'),
            Card('T', 'C'),
            Card('J', 'C'),
            Card('Q', 'C'),
        ])

        higher_straight_flush = Hand([
            Card('9', 'D'),
            Card('T', 'D'),
            Card('J', 'D'),
            Card('Q', 'D'),
            Card('K', 'D'),
        ])
        self.assertGreater(higher_straight_flush, lower_straight_flush)
Beispiel #12
0
    def test_untie_one_pair(self):
        one_pair1 = Hand([
            Card('2', 'C'),
            Card('2', 'D'),
            Card('7', 'H'),
            Card('5', 'S'),
            Card('6', 'S'),
        ])

        one_pair2 = Hand([
            Card('2', 'C'),
            Card('2', 'D'),
            Card('7', 'H'),
            Card('5', 'S'),
            Card('6', 'S'),
        ])
        self.assertEquals(one_pair1, one_pair2)

        lower_one_pair = Hand([
            Card('2', 'C'),
            Card('2', 'D'),
            Card('7', 'H'),
            Card('5', 'S'),
            Card('6', 'S'),
        ])

        higher_one_pair = Hand([
            Card('3', 'C'),
            Card('3', 'D'),
            Card('7', 'H'),
            Card('5', 'S'),
            Card('8', 'S'),
        ])
        self.assertGreater(higher_one_pair, lower_one_pair)

        lower_one_pair1 = Hand([
            Card('2', 'C'),
            Card('2', 'D'),
            Card('7', 'H'),
            Card('5', 'S'),
            Card('6', 'S'),
        ])

        higher_one_pair1 = Hand([
            Card('2', 'C'),
            Card('2', 'D'),
            Card('7', 'H'),
            Card('5', 'S'),
            Card('8', 'S'),
        ])
        self.assertGreater(higher_one_pair1, lower_one_pair1)
Beispiel #13
0
    def test_untie_two_pair(self):
        two_pair1 = Hand([
            Card('2', 'C'),
            Card('6', 'S'),
            Card('2', 'D'),
            Card('5', 'H'),
            Card('5', 'S'),
        ])

        two_pair2 = Hand([
            Card('2', 'C'),
            Card('6', 'S'),
            Card('5', 'H'),
            Card('2', 'D'),
            Card('5', 'S'),
        ])
        self.assertEquals(two_pair1, two_pair2)

        lower_two_pair = Hand([
            Card('2', 'C'),
            Card('2', 'D'),
            Card('5', 'S'),
            Card('5', 'H'),
            Card('9', 'S'),
        ])

        higher_two_pair = Hand([
            Card('2', 'C'),
            Card('2', 'D'),
            Card('6', 'H'),
            Card('6', 'S'),
            Card('4', 'S'),
        ])
        self.assertGreater(higher_two_pair, lower_two_pair)

        lower_two_pair1 = Hand([
            Card('2', 'C'),
            Card('2', 'D'),
            Card('5', 'S'),
            Card('5', 'H'),
            Card('6', 'S'),
        ])

        higher_two_pair1 = Hand([
            Card('2', 'C'),
            Card('2', 'D'),
            Card('5', 'H'),
            Card('5', 'S'),
            Card('7', 'S'),
        ])
        self.assertGreater(higher_two_pair1, lower_two_pair1)

        lower_two_pair1 = Hand([
            Card('2', 'C'),
            Card('2', 'D'),
            Card('6', 'S'),
            Card('6', 'H'),
            Card('9', 'S'),
        ])

        higher_two_pair1 = Hand([
            Card('3', 'C'),
            Card('3', 'D'),
            Card('6', 'H'),
            Card('6', 'S'),
            Card('7', 'S'),
        ])
        self.assertGreater(higher_two_pair1, lower_two_pair1)
Beispiel #14
0
    def test_untie_tree_of_a_kind(self):
        tree_of_a_kind1 = Hand([
            Card('2', 'C'),
            Card('2', 'D'),
            Card('2', 'H'),
            Card('5', 'S'),
            Card('6', 'S'),
        ])

        tree_of_a_kind2 = Hand([
            Card('2', 'C'),
            Card('2', 'D'),
            Card('2', 'H'),
            Card('5', 'S'),
            Card('6', 'S'),
        ])
        self.assertEquals(tree_of_a_kind1, tree_of_a_kind2)

        lower_tree_of_a_kind = Hand([
            Card('2', 'D'),
            Card('4', 'S'),
            Card('2', 'H'),
            Card('6', 'S'),
            Card('2', 'C'),
        ])

        higher_tree_of_a_kind = Hand([
            Card('2', 'D'),
            Card('5', 'S'),
            Card('2', 'H'),
            Card('6', 'S'),
            Card('2', 'C'),
        ])
        self.assertGreater(higher_tree_of_a_kind, lower_tree_of_a_kind)
Beispiel #15
0
    def test_untie_straight(self):
        straight1 = Hand([
            Card('2', 'C'),
            Card('3', 'D'),
            Card('4', 'H'),
            Card('5', 'S'),
            Card('6', 'S'),
        ])

        straight2 = Hand([
            Card('2', 'C'),
            Card('3', 'D'),
            Card('4', 'H'),
            Card('5', 'S'),
            Card('6', 'S'),
        ])
        self.assertEquals(straight1, straight2)

        lower_straight = Hand([
            Card('2', 'C'),
            Card('3', 'D'),
            Card('4', 'H'),
            Card('5', 'S'),
            Card('6', 'S'),
        ])

        higher_straight = Hand([
            Card('3', 'D'),
            Card('4', 'H'),
            Card('5', 'S'),
            Card('6', 'S'),
            Card('7', 'C'),
        ])
        self.assertGreater(higher_straight, lower_straight)
Beispiel #16
0
    def test_untie_flush(self):
        flush1 = Hand([
            Card('9', 'C'),
            Card('A', 'C'),
            Card('J', 'C'),
            Card('K', 'C'),
            Card('8', 'C'),
        ])

        flush2 = Hand([
            Card('9', 'C'),
            Card('A', 'C'),
            Card('J', 'C'),
            Card('K', 'C'),
            Card('8', 'C'),
        ])
        self.assertEquals(flush1, flush2)

        lower_flush = Hand([
            Card('9', 'C'),
            Card('A', 'C'),
            Card('J', 'C'),
            Card('K', 'C'),
            Card('5', 'C'),
        ])

        higher_flush = Hand([
            Card('9', 'C'),
            Card('A', 'C'),
            Card('J', 'C'),
            Card('K', 'C'),
            Card('8', 'C'),
        ])
        self.assertGreater(higher_flush, lower_flush)
Beispiel #17
0
    def test_untie_full_house(self):
        full_house1 = Hand([
            Card('9', 'C'),
            Card('9', 'D'),
            Card('9', 'H'),
            Card('K', 'S'),
            Card('K', 'C'),
        ])

        full_house2 = Hand([
            Card('9', 'C'),
            Card('9', 'D'),
            Card('9', 'H'),
            Card('K', 'S'),
            Card('K', 'C'),
        ])
        self.assertEquals(full_house1, full_house2)

        lower_full_house = Hand([
            Card('7', 'C'),
            Card('7', 'D'),
            Card('7', 'H'),
            Card('K', 'S'),
            Card('K', 'C'),
        ])

        higher_full_house = Hand([
            Card('9', 'C'),
            Card('9', 'D'),
            Card('9', 'H'),
            Card('A', 'S'),
            Card('A', 'C'),
        ])
        self.assertGreater(higher_full_house, lower_full_house)

        lower_full_house1 = Hand([
            Card('9', 'C'),
            Card('9', 'D'),
            Card('9', 'H'),
            Card('K', 'S'),
            Card('K', 'C'),
        ])

        higher_full_house1 = Hand([
            Card('9', 'C'),
            Card('9', 'D'),
            Card('9', 'H'),
            Card('A', 'S'),
            Card('A', 'C'),
        ])
        self.assertGreater(higher_full_house1, lower_full_house1)
Beispiel #18
0
    def test_untie_high_card(self):
        high_card1 = Hand([
            Card('A', 'C'),
            Card('2', 'D'),
            Card('7', 'H'),
            Card('5', 'S'),
            Card('6', 'S'),
        ])

        high_card2 = Hand([
            Card('A', 'C'),
            Card('2', 'D'),
            Card('7', 'H'),
            Card('5', 'S'),
            Card('6', 'S'),
        ])
        self.assertEquals(high_card1, high_card2)

        lower_high_card = Hand([
            Card('2', 'D'),
            Card('7', 'H'),
            Card('5', 'S'),
            Card('6', 'S'),
            Card('9', 'C'),
        ])

        higher_high_card = Hand([
            Card('7', 'H'),
            Card('5', 'S'),
            Card('A', 'D'),
            Card('6', 'S'),
            Card('9', 'C'),
        ])
        self.assertGreater(higher_high_card, lower_high_card)
Beispiel #19
0
    def test__init__raise_error(self):
        with self.assertRaises(ValueError):
            Card(self.value, self.invalid_suit)

        with self.assertRaises(ValueError):
            Card(self.invalid_value, self.suit)
Beispiel #20
0
 def setUp(self):
     self.suit = 'C'
     self.invalid_suit = 'X'
     self.value = 'A'
     self.invalid_value = 'X'
     self.card = Card(self.value, self.suit)
Beispiel #21
0
    def test_untie_four_of_a_kind(self):
        four_of_a_kind1 = Hand([
            Card('9', 'C'),
            Card('9', 'D'),
            Card('9', 'H'),
            Card('9', 'S'),
            Card('K', 'C'),
        ])

        four_of_a_kind2 = Hand([
            Card('9', 'C'),
            Card('9', 'D'),
            Card('9', 'H'),
            Card('9', 'S'),
            Card('K', 'C'),
        ])
        self.assertEquals(four_of_a_kind1, four_of_a_kind2)

        lower_four_of_a_kind = Hand([
            Card('8', 'C'),
            Card('8', 'D'),
            Card('8', 'H'),
            Card('8', 'S'),
            Card('K', 'C'),
        ])

        higher_four_of_a_kind = Hand([
            Card('9', 'C'),
            Card('9', 'D'),
            Card('9', 'H'),
            Card('9', 'S'),
            Card('A', 'C'),
        ])
        self.assertGreater(higher_four_of_a_kind, lower_four_of_a_kind)

        lower_four_of_a_kind1 = Hand([
            Card('9', 'C'),
            Card('9', 'D'),
            Card('9', 'H'),
            Card('9', 'S'),
            Card('K', 'C'),
        ])

        higher_four_of_a_kind1 = Hand([
            Card('9', 'C'),
            Card('9', 'D'),
            Card('9', 'H'),
            Card('9', 'S'),
            Card('A', 'C'),
        ])
        self.assertGreater(higher_four_of_a_kind1, lower_four_of_a_kind1)