Exemple #1
0
 def test_four_points_for_run_of_four(self):
     cribbage_hand = CribbageHand([
         Card(Rank('2'), Suite.DIAMONDS),
         Card(Rank('0'), Suite.SPADES),
         Card(Rank('J'), Suite.DIAMONDS),
         Card(Rank('Q'), Suite.DIAMONDS),
         Card(Rank('K'), Suite.SPADES),
     ])
     self.assertEqual(4, score(cribbage_hand))
Exemple #2
0
 def test_one_point_for_the_J_of_the_same_suite_as_the_starter_card(self):
     cribbage_hand = CribbageHand([
         Card(Rank('3'), Suite.DIAMONDS),
         Card(Rank('J'), Suite.SPADES),
         Card(Rank('7'), Suite.DIAMONDS),
         Card(Rank('9'), Suite.DIAMONDS),
         Card(Rank('A'), Suite.SPADES),
     ])
     self.assertEqual(1, score(cribbage_hand))
Exemple #3
0
 def test_two_points_for_a_pair_of_cards_of_a_kind(self):
     cribbage_hand = CribbageHand([
         Card(Rank('2'), Suite.DIAMONDS),
         Card(Rank('A'), Suite.DIAMONDS),
         Card(Rank('2'), Suite.CLUBS),
         Card(Rank('7'), Suite.DIAMONDS),
         Card(Rank('9'), Suite.DIAMONDS),
     ])
     self.assertEqual(2, score(cribbage_hand))
Exemple #4
0
 def test_four_points_for_a_flush(self):
     cribbage_hand = CribbageHand([
         Card(Rank('3'), Suite.DIAMONDS),
         Card(Rank('A'), Suite.DIAMONDS),
         Card(Rank('7'), Suite.DIAMONDS),
         Card(Rank('9'), Suite.DIAMONDS),
         Card(Rank('J'), Suite.SPADES),
     ])
     self.assertEqual(4, score(cribbage_hand))
Exemple #5
0
 def test_five_points_for_a_flush_and_starter_card_of_same_suite(self):
     cribbage_hand = CribbageHand([
         Card(Rank('3'), Suite.DIAMONDS),
         Card(Rank('A'), Suite.DIAMONDS),
         Card(Rank('7'), Suite.DIAMONDS),
         Card(Rank('9'), Suite.DIAMONDS),
         Card(Rank('J'), Suite.DIAMONDS),
     ])
     self.assertEqual(5, score(cribbage_hand))
Exemple #6
0
 def test_six_points_for_three_cards_of_a_kind(self):
     cribbage_hand = CribbageHand([
         Card(Rank('6'), Suite.DIAMONDS),
         Card(Rank('A'), Suite.DIAMONDS),
         Card(Rank('6'), Suite.CLUBS),
         Card(Rank('7'), Suite.DIAMONDS),
         Card(Rank('6'), Suite.SPADES),
     ])
     self.assertEqual(6, score(cribbage_hand))
Exemple #7
0
 def test_twelve_points_for_four_cards_of_a_kind(self):
     cribbage_hand = CribbageHand([
         Card(Rank('0'), Suite.DIAMONDS),
         Card(Rank('A'), Suite.DIAMONDS),
         Card(Rank('0'), Suite.CLUBS),
         Card(Rank('0'), Suite.HEARTS),
         Card(Rank('0'), Suite.SPADES),
     ])
     self.assertEqual(12, score(cribbage_hand))
Exemple #8
0
 def test_highest_possible_score(self):
     cribbage_hand = CribbageHand([
         Card(Rank('5'), Suite.DIAMONDS),
         Card(Rank('5'), Suite.HEARTS),
         Card(Rank('5'), Suite.CLUBS),
         Card(Rank('J'), Suite.SPADES),
         Card(Rank('5'), Suite.SPADES),
     ])
     self.assertEqual(29, score(cribbage_hand))
Exemple #9
0
 def test_four_points_for_two_pairs_of_cards_of_a_kind(self):
     cribbage_hand = CribbageHand([
         Card(Rank('3'), Suite.DIAMONDS),
         Card(Rank('A'), Suite.DIAMONDS),
         Card(Rank('3'), Suite.CLUBS),
         Card(Rank('6'), Suite.DIAMONDS),
         Card(Rank('A'), Suite.HEARTS),
     ])
     self.assertEqual(4, score(cribbage_hand))
Exemple #10
0
 def test_fifteen_sixteen_and_six_pairs(self):
     cribbage_hand = CribbageHand([
         Card(Rank('5'), Suite.DIAMONDS),
         Card(Rank('5'), Suite.HEARTS),
         Card(Rank('5'), Suite.CLUBS),
         Card(Rank('0'), Suite.SPADES),
         Card(Rank('5'), Suite.SPADES),
     ])
     self.assertEqual(28, score(cribbage_hand))
Exemple #11
0
 def test_fifteen_two(self):
     cribbage_hand = CribbageHand([
         Card(Rank('0'), Suite.DIAMONDS),
         Card(Rank('5'), Suite.HEARTS),
         Card(Rank('3'), Suite.CLUBS),
         Card(Rank('A'), Suite.DIAMONDS),
         Card(Rank('8'), Suite.SPADES),
     ])
     self.assertEqual(2, score(cribbage_hand))
Exemple #12
0
 def test_sixteen_points_for_double_double_run(self):
     cribbage_hand = CribbageHand([
         Card(Rank('4'), Suite.DIAMONDS),
         Card(Rank('2'), Suite.HEARTS),
         Card(Rank('3'), Suite.CLUBS),
         Card(Rank('4'), Suite.DIAMONDS),
         Card(Rank('3'), Suite.SPADES),
     ])
     self.assertEqual(16, score(cribbage_hand))
Exemple #13
0
 def test_eight_points_for_double_run(self):
     cribbage_hand = CribbageHand([
         Card(Rank('5'), Suite.DIAMONDS),
         Card(Rank('5'), Suite.HEARTS),
         Card(Rank('6'), Suite.CLUBS),
         Card(Rank('A'), Suite.DIAMONDS),
         Card(Rank('7'), Suite.SPADES)
     ])
     self.assertEqual(8, score(cribbage_hand))
Exemple #14
0
 def test_three_points_for_a_run_of_three(self):
     cribbage_hand = CribbageHand([
         Card(Rank('0'), Suite.DIAMONDS),
         Card(Rank('A'), Suite.DIAMONDS),
         Card(Rank('2'), Suite.CLUBS),
         Card(Rank('8'), Suite.DIAMONDS),
         Card(Rank('9'), Suite.SPADES),
     ])
     self.assertEqual(3, score(cribbage_hand))
Exemple #15
0
def compute_score(hand_as_string):
    points = score(parse_hand(hand_as_string))
    print('The score is ' + str(points))