def testHandsDifferentNumCards(self): cards = [ Card(RED, 2), Card(YELLOW, 4), Card(GREEN, 3), Card(GREEN, "J"), ] hand1 = Hand() hand1.add_cards(cards) self.assertEqual(28, hand1.score) self.assertEqual(4, len(hand1)) self.assertNotEqual(99, hand1.score) self.assertNotEqual(1, len(hand1)) cards = [ Card(RED, 3), Card(YELLOW, 3), Card(GREEN, 4), ] hand2 = Hand() hand2.add_cards(cards) self.assertEqual(19, hand2.score) self.assertEqual(3, len(hand2)) self.assertNotEqual(99, hand2.score) self.assertNotEqual(1, len(hand2)) ################################################## self.assertFalse(hand1.same_number_of_cards(hand2)) self.assertFalse(hand2.same_number_of_cards(hand1)) with self.assertRaises(ValueError): self.assertTrue(hand1 == hand2) with self.assertRaises(ValueError): self.assertTrue(hand1 != hand2) with self.assertRaises(ValueError): self.assertNotEqual(hand1, hand2) with self.assertRaises(ValueError): self.assertFalse(hand1 == hand2) with self.assertRaises(ValueError): self.assertTrue(hand1 != hand2) with self.assertRaises(ValueError): self.assertFalse(hand1.is_tie(hand2)) with self.assertRaises(ValueError): self.assertFalse(hand1.is_winner(hand2)) with self.assertRaises(ValueError): self.assertTrue(hand1.is_loser(hand2))
def testHandsEqual(self): cards = [ Card(RED, 2), Card(YELLOW, 4), Card(GREEN, 2), ] hand1 = Hand() hand1.add_cards(cards) self.assertEqual(16, hand1.score) self.assertEqual(3, len(hand1)) self.assertNotEqual(99, hand1.score) self.assertNotEqual(1, len(hand1)) cards = [ Card(RED, 3), Card(YELLOW, 3), Card(GREEN, 1), ] hand2 = Hand() hand2.add_cards(cards) self.assertEqual(16, hand2.score) self.assertEqual(3, len(hand2)) self.assertNotEqual(99, hand2.score) self.assertNotEqual(1, len(hand2)) ################################################## self.assertEqual(hand1, hand2) self.assertTrue(hand1 == hand2) self.assertFalse(hand1 != hand2) self.assertTrue(hand1.is_tie(hand2)) self.assertFalse(hand1.is_winner(hand2)) self.assertFalse(hand1.is_loser(hand2)) self.assertTrue(hand1.same_number_of_cards(hand2)) self.assertTrue(hand2.same_number_of_cards(hand1)) ## hands are a tie hands = [hand1, hand2] n, winners = Hand.determine_winner(hands) self.assertEqual(2, n) self.assertEqual(hands, winners)
def testHandsTwoWinner(self): cards = [ Card(RED, 2), Card(YELLOW, 4), Card(GREEN, 3), ] hand1 = Hand() hand1.add_cards(cards) self.assertEqual(17, hand1.score) self.assertEqual(3, len(hand1)) self.assertNotEqual(99, hand1.score) self.assertNotEqual(1, len(hand1)) cards = [ Card(RED, 3), Card(YELLOW, 3), Card(GREEN, 1), ] hand2 = Hand() hand2.add_cards(cards) self.assertEqual(16, hand2.score) self.assertEqual(3, len(hand2)) self.assertNotEqual(99, hand2.score) self.assertNotEqual(1, len(hand2)) ################################################## self.assertNotEqual(hand1, hand2) self.assertFalse(hand1 == hand2) self.assertTrue(hand1 != hand2) self.assertTrue(hand1 > hand2) self.assertFalse(hand1 < hand2) self.assertFalse(hand1.is_tie(hand2)) self.assertTrue(hand1.same_number_of_cards(hand2)) self.assertTrue(hand2.same_number_of_cards(hand1)) n, winner = Hand.determine_winner([hand1, hand2]) self.assertEqual(1, n) self.assertEqual(17, winner[0].score) hands = Hand.sort_hands([hand1, hand2]) self.assertEqual(17, hands[0].score) self.assertEqual(16, hands[1].score) n, winner = Hand.determine_winner(hands) self.assertEqual(1, n) self.assertEqual(17, winner[0].score) hands = Hand.sort_hands([hand1, hand2], ascending=True) self.assertEqual(16, hands[0].score) self.assertEqual(17, hands[1].score) n, winner = Hand.determine_winner(hands) self.assertEqual(1, n) self.assertEqual(17, winner[0].score)