Example #1
0
class TestHandScore(unittest.TestCase):
    def setUp(self):
        self.royal_flush = Hand(["TC", "JC", "QC", "KC", "AC"])
        self.straight_flush = Hand(["9C", "TC", "JC", "QC", "KC"])
        self.four_of_a_kind = Hand(["9C", "AH", "AS", "AD", "AC"])
        self.full_house = Hand(["KC", "KD", "AD", "AS", "AC"])
        self.flush = Hand(["8C", "TC", "JC", "QC", "KC"])
        self.straight = Hand(["TD", "JS", "QC", "KH", "AC"])
        self.three_of_a_kind = Hand(["8H", "TD", "AS", "AC", "AD"])
        self.two_pairs = Hand(["8H", "KD", "KS", "AC", "AD"])
        self.one_pair = Hand(["3H", "9D", "5S", "AC", "AD"])

    def test_confirm_hands(self):
        self.assertTrue(self.royal_flush.royal_flush())
        self.assertTrue(self.straight_flush.straight_flush())
        self.assertTrue(self.four_of_a_kind.four_of_a_kind())
        self.assertTrue(self.full_house.full_house())
        self.assertTrue(self.flush.flush())
        self.assertTrue(self.straight.straight())
        self.assertTrue(self.three_of_a_kind.three_of_a_kind())
        self.assertTrue(self.two_pairs.two_pairs())
        self.assertTrue(self.one_pair.one_pair())

    def test_highest_scoring_hand_always_wins(self):
        self.assertGreater(self.royal_flush, self.straight_flush, "royal flush > s straight flush")
        self.assertGreater(self.straight_flush, self.four_of_a_kind, "straight flush > 4 of a kind")
        self.assertGreater(self.four_of_a_kind, self.full_house, "4 of a kind > full house")
        self.assertGreater(self.full_house, self.flush, "full house > flush")
        self.assertGreater(self.flush, self.straight, "flush > straight")
        self.assertGreater(self.straight, self.three_of_a_kind, "straight > 3 of a kind")
        self.assertGreater(self.three_of_a_kind, self.two_pairs, "3 of a kind > 2 pairs")
        self.assertGreater(self.two_pairs, self.one_pair, "2 pairs > 1 pair")
Example #2
0
 def setUp(self):
     self.royal_flush = Hand(["TC", "JC", "QC", "KC", "AC"])
     self.straight_flush = Hand(["9C", "TC", "JC", "QC", "KC"])
     self.four_of_a_kind = Hand(["9C", "AH", "AS", "AD", "AC"])
     self.full_house = Hand(["KC", "KD", "AD", "AS", "AC"])
     self.flush = Hand(["8C", "TC", "JC", "QC", "KC"])
     self.straight = Hand(["TD", "JS", "QC", "KH", "AC"])
     self.three_of_a_kind = Hand(["8H", "TD", "AS", "AC", "AD"])
     self.two_pairs = Hand(["8H", "KD", "KS", "AC", "AD"])
     self.one_pair = Hand(["3H", "9D", "5S", "AC", "AD"])