Exemple #1
0
    def test_create(self):
        self.assertRaises(TypeError, Hand, Card(1, 2))
        self.assertRaises(HandCreationError, Hand, [])
        self.assertRaises(HandCreationError, Hand, [3, 1])

        self.assertRaises(HandCreationError, Hand.from_chars)
        self.assertRaises(HandCreationError, Hand.from_chars, 4)
        self.assertRaises(HandCreationError, Hand.from_chars, 'aS', '4p')
        self.assertRaises(HandCreationError, Hand.from_chars, ['Th', 9])
        self.assertRaises(HandCreationError, Hand.from_chars,
                          'KH', 'Qs', 'Acd')

        hand = Hand([Card(4, 2), Card.from_chars('AS'), Card(9, 0)])
        self.assertIsInstance(hand, Hand)
        self.assertEqual(hand.value, 0)
        self.assertEqual(Hand.names[hand.value], 'high card')
        self.assertEqual(hand.best_cards, [12, 9, 4])

        hand = Hand.from_chars('4s', 'Th', '3s', '3c', 'Js', '3d')
        self.assertIsInstance(hand, Hand)
        self.assertEqual(hand.value, 3)
        self.assertEqual(Hand.names[hand.value], 'three of a kind')
        self.assertEqual(hand.best_cards, [1, 1, 1, 9, 8])

        hand = Hand.from_chars(['KH', '9H', 'KS', '9C'])
        self.assertIsInstance(hand, Hand)
        self.assertEqual(hand.value, 2)
        self.assertEqual(Hand.names[hand.value], 'two pair')
        self.assertEqual(hand.best_cards, [11, 11, 7, 7])
Exemple #2
0
 def setUp(self):
     self.players = [], []
     self.wins = []
     with open(join(dirname(__file__), 'testcases')) as testcases:
         for i, line in enumerate(testcases):
             case = i % 3
             parts = line.split()
             if case == 2:
                 self.wins.append(int(parts[0]))
             else:
                 self.players[case].append((Hand.from_chars(parts[:-1]),
                                            int(parts[-1])))