def test_playing_card(self): card = PlayingCard(rank='ACE', suit='SPADES') self.assertEqual(card.rank, 'ACE') self.assertEqual(card.suit, 'SPADES') r = card.__repr__() self.assertEqual(r, '<PlayingCard: ACE of SPADES>') card_dict = card.to_dict() self.assertEqual(card_dict['rank'], 'ACE') self.assertEqual(card_dict['suit'], 'SPADES')
def test_generate_playing_cards(self): cards = PlayingCard.generate_cards() for card in cards: self.assertTrue(isinstance(card, PlayingCard))
def test_playing_card_from_json(self): card_json = json.dumps({'rank': 'ACE', 'suit': 'SPADES'}) card = PlayingCard.from_json(card_json=card_json) self.assertEqual(card.rank, 'ACE') self.assertEqual(card.suit, 'SPADES')
def test_playing_card_to_json(self): card = PlayingCard(rank='ACE', suit='SPADES') card_json = card.to_json() card_dict = json.loads(card_json) self.assertEqual(card_dict['rank'], 'ACE') self.assertEqual(card_dict['suit'], 'SPADES')