Beispiel #1
0
def test():
    "Test cases for the functions in poker program"
    sf = "6C 7C 8C 9C TC".split()  # Straight Flush
    fk = "9D 9H 9S 9C 7D".split()  # Four of a Kind
    fh = "TD TC TH 7C 7D".split()  # Full House
    tp = "5S 5D AC AS KS".split()  # Two Pair
    s1 = "AC 2S 3C 4D 5D".split()  # A-5 Straight
    s2 = "2S 3C 4D 5D 6S".split()  # 2-6 Straight
    ah = "AC 2S 9C 4D 6D".split()  # A High
    sh = "7C 2S 6C 3D 5D".split()  # 7 High
    assert poker([s1, s2, ah, sh]) == [s2]
    assert poker([s1, ah, sh]) == [s1]
    fkranks = card_ranks(fk)
    tpranks = card_ranks(tp)
    assert kind(4, fkranks) == 9
    assert kind(3, fkranks) is None
    assert kind(2, fkranks) is None
    assert kind(1, fkranks) == 7
    assert two_pair(fkranks) is None
    assert two_pair(tpranks) == (14, 5)
    assert poker([sf, fk, fh]) == [sf]
    assert poker([fk, fh]) == [fk]
    assert poker([fh, fh]) == [fh, fh]
    assert poker([sf]) == [sf]
    assert poker([sf] + 99*[fh]) == [sf]
    assert hand_rank(sf) == (8, 10)
    assert hand_rank(fk) == (7, 9, 7)
    assert hand_rank(fh) == (6, 10, 7)
    return 'tests pass'
def test_card_ranks():
    """
    card_ranks returns the ranks in sorted order
    """
    sf = "6C 7C 8C 9C TC".split()
    fk = "9D 9H 9S 9C 7D".split()
    fh = "TD TC TH 7C 7D".split()

    assert card_ranks(sf) == [10, 9, 8, 7, 6]
    assert card_ranks(fk) == [9, 9, 9, 9, 7]
    assert card_ranks(fh) == [10, 10, 10, 7, 7]
Beispiel #3
0
 def test_card_ranks(self):
     hand = ["TC", "TH", "5C", "5H", "KH"]
     self.assertEqual(card_ranks(hand), [13, 10, 10, 5, 5])
Beispiel #4
0
 def test_two_pair(self):
     hand = ["5C", "2H", "5C", "2S", "6C"]
     ranks = card_ranks(hand)
     self.assertEqual(two_pair(ranks), (2, 5))
Beispiel #5
0
 def test_3_of_a_kind(self):
     hand = ["5C", "2H", "5C", "5S", "6C"]
     ranks = card_ranks(hand)
     self.assertEqual(kind(3, ranks), 5)
Beispiel #6
0
 def test_4_of_a_kind(self):
     hand = ["2C", "2H", "2C", "2S", "6C"]
     ranks = card_ranks(hand)
     self.assertEqual(kind(4, ranks), 2)
Beispiel #7
0
 def test_not_straight(self):
     hand = ["2C", "3H", "4C", "7H", "8C"]
     self.assertFalse(straight(card_ranks(hand)))
Beispiel #8
0
 def test_straight(self):
     hand = ["2C", "3H", "4C", "5H", "6C"]
     self.assertTrue(straight(card_ranks(hand)))
Beispiel #9
0
 def test_royal_flush(self):
     hand = ["TC", "QC", "KC", "AC", "JC"]
     ranks = card_ranks(hand)
     self.assertTrue(royal_flush(ranks, hand))
Beispiel #10
0
 def test_card_ranks_hands3(self):
     self.assertEqual(poker.card_ranks(self.hand3), [11, 7, 7, 7, 7],'Should be list: [11, 7, 7, 7, 7]')
Beispiel #11
0
 def test_card_ranks_hands2(self):
     self.assertEqual(poker.card_ranks(self.hand2), [10, 10, 10, 8, 8],'Should be list: [10, 10, 10, 8, 8]')
Beispiel #12
0
 def test_card_ranks_hands1(self):
     self.assertEqual(poker.card_ranks(self.hand1), [10, 9, 8, 7, 6],'Should be list: [10, 9, 8, 7, 6]')