def test_serialization(self): table = self.__setup_players_with_table() for card in table.deck.draw_cards(3): table.add_community_card(card) table.shift_dealer_btn() table.set_blind_pos(1, 2) serial = table.serialize() restored = Table.deserialize(serial) self.eq(table.dealer_btn, restored.dealer_btn) self.eq(Seats.serialize(table.seats), Seats.serialize(restored.seats)) self.eq(Deck.serialize(table.deck), Deck.serialize(restored.deck)) self.eq(table.get_community_card(), restored.get_community_card()) self.eq(1, restored.sb_pos()) self.eq(2, restored.bb_pos())
def serialize(self): community_card = [card.to_id() for card in self._community_card] return [ self.dealer_btn, Seats.serialize(self.seats), Deck.serialize(self.deck), community_card, self._blind_pos ]
def test_cheat_serialization(self): cards = [Card.from_id(cid) for cid in [12, 15, 17]] cheat = Deck(cheat=True, cheat_card_ids=[12, 15, 17]) serial = cheat.serialize() restored = Deck.deserialize(serial) self.eq(cheat.deck, restored.deck) self.eq(cheat.cheat, restored.cheat) self.eq(cheat.cheat_card_ids, restored.cheat_card_ids)
class DeckTest(BaseUnitTest): def setUp(self): self.deck = Deck() def test_draw_card(self): card = self.deck.draw_card() self.eq("SK", str(card)) self.eq(51, self.deck.size()) def test_draw_cards(self): cards = self.deck.draw_cards(3) self.eq("SJ", str(cards[2])) self.eq(49, self.deck.size()) def test_restore(self): self.deck.draw_cards(5) self.deck.restore() self.eq(52, self.deck.size()) def test_serialization(self): self.deck.draw_cards(5) self.deck.shuffle() serial = self.deck.serialize() restored = Deck.deserialize(serial) self.eq(self.deck.cheat, restored.cheat) self.eq(self.deck.deck, restored.deck) def test_cheat_draw(self): cards = [Card.from_id(cid) for cid in [12, 15, 17]] cheat = Deck(cheat=True, cheat_card_ids=[12, 15, 17]) self.eq(cheat.draw_cards(3), cards) def test_cheat_restore(self): cards = [Card.from_id(cid) for cid in [12, 15, 17]] cheat = Deck(cheat=True, cheat_card_ids=[12, 15, 17]) cheat.draw_cards(2) cheat.restore() self.eq(cheat.draw_cards(3), cards) def test_cheat_serialization(self): cards = [Card.from_id(cid) for cid in [12, 15, 17]] cheat = Deck(cheat=True, cheat_card_ids=[12, 15, 17]) serial = cheat.serialize() restored = Deck.deserialize(serial) self.eq(cheat.deck, restored.deck) self.eq(cheat.cheat, restored.cheat) self.eq(cheat.cheat_card_ids, restored.cheat_card_ids)
def test_gen_deck_without_some_card(self): expected = Deck(deck_ids=range(2, 52)) exclude_obj = [Card.from_id(1), Card.from_id(52)] exclude_str = [str(card) for card in exclude_obj] self.eq(expected.serialize(), U.gen_deck(exclude_obj).serialize()) self.eq(expected.serialize(), U.gen_deck(exclude_str).serialize())