def testDeckSortTwoColors(self): deck = Deck() deck.add_cards( [ Card(GREEN, 2), Card(GREEN, 6), Card(YELLOW, 5), Card(YELLOW, "K"), Card(RED, 4), Card(RED, "J"), ] ) self.assertEqual(6, len(deck)) self.assertNotEqual(1, len(deck)) deck.shuffle() deck.sort_by_color([GREEN.color, RED.color]) self.assertEqual( deck.cards, [ Card(GREEN, 2), Card(GREEN, 6), Card(RED, 4), Card(RED, "J"), Card(YELLOW, 5), Card(YELLOW, "K"), ], ) deck.shuffle() deck.sort_by_color([YELLOW.color, RED.color]) self.assertEqual( deck.cards, [ Card(YELLOW, 5), Card(YELLOW, "K"), Card(RED, 4), Card(RED, "J"), Card(GREEN, 2), Card(GREEN, 6), ], ) deck.shuffle() deck.sort_by_color([GREEN.color, YELLOW.color]) self.assertEqual( deck.cards, [ Card(GREEN, 2), Card(GREEN, 6), Card(YELLOW, 5), Card(YELLOW, "K"), Card(RED, 4), Card(RED, "J"), ], )
def testDeckSortSingleColor(self): deck = Deck() deck.add_cards( [ Card(GREEN, 2), Card(GREEN, 6), Card(YELLOW, 5), Card(YELLOW, "K"), Card(RED, 4), Card(RED, "J"), ] ) self.assertEqual(6, len(deck)) self.assertNotEqual(1, len(deck)) green_result = [ Card(GREEN, 2), Card(GREEN, 6), Card(YELLOW, 5), Card(YELLOW, "K"), Card(RED, 4), Card(RED, "J"), ] deck.shuffle() deck.sort_by_color([GREEN.color]) self.assertEqual(deck.cards, green_result) deck.shuffle() deck.sort_by_color(GREEN.color) self.assertEqual(deck.cards, green_result) red_result = [ Card(RED, 4), Card(RED, "J"), Card(GREEN, 2), Card(GREEN, 6), Card(YELLOW, 5), Card(YELLOW, "K"), ] deck.shuffle() deck.sort_by_color([RED.color]) self.assertEqual(deck.cards, red_result) deck.shuffle() deck.sort_by_color(RED.color) self.assertEqual(deck.cards, red_result) yellow_result = [ Card(YELLOW, 5), Card(YELLOW, "K"), Card(GREEN, 2), Card(GREEN, 6), Card(RED, 4), Card(RED, "J"), ] deck.shuffle() deck.sort_by_color([YELLOW.color]) self.assertEqual(deck.cards, yellow_result) deck.shuffle() deck.sort_by_color(YELLOW.color) self.assertEqual(deck.cards, yellow_result)