def test_kind(self): self.assertEqual(9, poker.kind(4, poker.get_ranks(self.fk9))) self.assertEqual(10, poker.kind(3, poker.get_ranks(self.fhT))) self.assertEqual(7, poker.kind(2, poker.get_ranks(self.fhT))) self.assertEqual(9, poker.kind(2, poker.get_ranks(self.tp))) self.assertEqual( 5, poker.kind(2, list(reversed(poker.get_ranks(self.tp)))))
def test_Poker(): "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 9H 9C 6S".split() # Two Pairs fkranks = poker.cardRanks(fk) tpranks = poker.cardRanks(tp) assert poker.allMax([1, 2, 3, 3, 3, 2]) == [3, 3, 3 ] assert poker.kind(4, fkranks) == 9 assert poker.kind(3, fkranks) == None assert poker.kind(2, fkranks) == None assert poker.kind(1, fkranks) == 7 assert poker.twoPair(fkranks) == None assert poker.twoPair(tpranks) == (9, 5) assert poker.cardRanks(sf) == [10, 9, 8, 7, 6] assert poker.cardRanks(fk) == [9, 9, 9, 9, 7 ] assert poker.cardRanks(fh) == [10, 10, 10, 7, 7] assert poker.straight([9, 8, 7, 6, 5]) == True assert poker.straight([9, 8, 7, 6, 4]) == False assert poker.flush(sf) == True assert poker.flush(fk) == False assert poker.poker( [ sf, fk, fh ] ) == [sf] assert poker.poker( [ fk, fh ] ) == [fk] assert poker.poker( [ fh, fh ] ) == [fh, fh] assert poker.poker( [ sf, fh ] ) == [sf] assert poker.poker( [ sf ] + 99 * [ fh ] ) == [sf] assert poker.handRank( sf ) == ( 8, 10 ) assert poker.handRank( fk ) == ( 7, 9, 7 ) assert poker.handRank( fh ) == ( 6, 10, 7 ) return "tests pass"
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_kind_7(self): """ Test kind full house hand with four of a kind hand ['6H', '6S', '6D', '6C', 'KS'] """ fk = ['6H', '6S', '6D', '6C', 'KS'] actual = poker.kind(fk,3) and poker.kind(fk,2) expected = False self.assertEqual(actual,expected)
def test_kind_6(self): """ Test kind full house hand with full house hand ['5H', '5S', '5D', '8C', '8S'] """ fh = ['5H', '5S', '5D', '8C', '8S'] actual = poker.kind(fh,3) and poker.kind(fh,2) expected = 8 self.assertEqual(actual,expected)
def test_kind_tester_2(self): '''testcase normal three_of_a_kind tk_ranks = [5, 5, 5, 8, 9] ''' tk_ranks = [5, 5, 5, 8, 9] actual = poker.kind(3,tk_ranks) expected = 5 self.assertEqual (actual,expected)
def test_kind_tester_1(self): '''testcase normal four_of_a_kind fk_ranks = [5, 5, 5, 5, 13] ''' fk_ranks = [5, 5, 5, 5, 13] actual = poker.kind(4,fk_ranks) expected = 5 self.assertEqual (actual,expected)
def test_one_pair_tester_1(self): '''testcase normal one_pair op = [5,3,9,7,5] ''' op = [5,3,9,7,5] actual = poker.kind(2,op) expected = 5 self.assertEqual (actual,expected)
def test_kind_tester_3(self): '''testcase normal straight st_ranks = ['5','6','7','8','9'] ''' st_ranks = ['5','6','7','8','9'] actual = poker.kind(2,st_ranks) expected = 0 self.assertEqual (actual,expected)
def test_one_pair_tester_2(self): '''testcase normal high_card hc = [3,4,8,2,9] ''' hc = [3,4,8,2,9] actual = poker.kind(2,hc) expected = 0 self.assertEqual (actual,expected)
def test_onepair(self): """ Test onepair with onepair hand ['4H', '5S', '3D', '6C', '7S'] """ op = ['5S', '3H', '9D', '8C', '8S'] actual = poker.kind(op, 2) expected = 8 self.assertEqual(actual,expected)
def test_onepair_2(self): """ Test onepair with straight hand ['5S', '3H', '9D', '7C', '8S'] """ st = ['5S', '3H', '9D', '7C', '8S'] actual = poker.kind(st, 2) expected = 0 self.assertEqual(actual,expected)
def test_kind_5(self): """ Test kind n = 4 with three of a kind hand ['6H', '6S', '6D', '7C', 'KS'] """ thk = ['6H', '6S', '6D', '7C', 'KS'] actual = poker.kind(thk,4) expected = 0 self.assertEqual(actual,expected)
def test_kind_4(self): """ Test kind n = 4 with four of a kind hand ['6H', '6S', '6D', '6C', 'KS'] """ fk = ['6H', '6S', '6D', '6C', 'KS'] actual = poker.kind(fk,4) expected = 6 self.assertEqual(actual,expected)
def test_kind_2(self): """ Test kind n = 3 with three of a kind hand ['6H', '6S', '6D', '7C', 'KS'] """ tk = ['6H', '6S', '6D', '7C', 'KS'] actual = poker.kind(tk,3) expected = 6 self.assertEqual(actual,expected)
def test_kind(self): """ Test kind n = 3 with three of a kind hand ['QS', 'QC', 'QD', '4H', '5H'] """ tk = ['QS', 'QC', 'QD', '4H', '5H'] actual = poker.kind(tk,3) expected = 12 self.assertEqual(actual,expected)
def test_four_of_kind_1(self): '''Test four of kind with [11, 10, 9, 8, 7]''' actual = poker.kind(4, [11, 10, 9, 8, 7]) expected = 0 self.assertEqual(actual, expected)
def test_kind_rank2(self): self.assertEqual(poker.kind(3, self.rank2), 10, 'Should be 10')
def test_kind_rank3(self): self.assertEqual(poker.kind(4, self.rank3), 7, 'Should be 7')
def test_kind_rank1(self): self.assertEqual(poker.kind(2, self.rank1), None, 'Should be None')
def test_4_of_a_kind(self): hand = ["2C", "2H", "2C", "2S", "6C"] ranks = card_ranks(hand) self.assertEqual(kind(4, ranks), 2)
def test_one_pair_2(self): '''Test four of kind with [11, 4, 2, 2, 9]''' actual = poker.kind(2, [11, 4, 2, 2, 9]) expected = 2 self.assertEqual(actual, expected)
def test_one_pair_1(self): '''Test four of kind with [9, 4, 9, 8, 6]''' actual = poker.kind(2, [9, 4, 9, 8, 6]) expected = 9 self.assertEqual(actual, expected)
def test_four_of_kind_2(self): '''Test four of kind with [9, 4, 9, 9, 9]''' actual = poker.kind(4, [9, 4, 9, 9, 9]) expected = 9 self.assertEqual(actual, expected)
def test_kind(self): self.assertEqual(9, poker.kind(4, poker.get_ranks(self.fk9))) self.assertEqual(10, poker.kind(3, poker.get_ranks(self.fhT))) self.assertEqual(7, poker.kind(2, poker.get_ranks(self.fhT))) self.assertEqual(9, poker.kind(2, poker.get_ranks(self.tp))) self.assertEqual(5, poker.kind(2, list(reversed(poker.get_ranks(self.tp)))))
def test_three_of_kind_1(self): '''Test three of kind with [4, 4, 4, 3, 7]''' actual = poker.kind(3, [4, 4, 4, 3, 7]) expected = 4 self.assertEqual(actual, expected)
def test_3_of_a_kind(self): hand = ["5C", "2H", "5C", "5S", "6C"] ranks = card_ranks(hand) self.assertEqual(kind(3, ranks), 5)
def test_three_of_kind_2(self): '''Test three of kind with [4, 4, 7, 3, 2]''' actual = poker.kind(3, [4, 4, 7, 3, 2]) expected = 0 self.assertEqual(actual, expected)