def reduced_deck(self) -> Deck: cards = list() for city in CITIES[:10]: new_card = Card(id_=city.id_, city=city) cards.append(new_card) reduced_deck = Deck() reduced_deck.cards = cards return reduced_deck
class TestCard: @pytest.fixture def city(self) -> City: return City(0, "Atlanta", "USA", 10.0, 0) @pytest.fixture def city_card(self, city) -> Card: return Card(id_=0, city=city) @pytest.fixture def action_card(self) -> Card: return Card(id_=1, action="Epidemic") @pytest.mark.parametrize("check_card, serialized", [(Card(id_=0, city=City(0, "Atlanta", "USA", 10.0, 0)), { 'id': 0, 'city': { 'id': 0, 'name': 'Atlanta', 'country': 'USA', 'color': 0, 'connections': {}, 'population': 10.0, 'infections': [0, 0, 0, 0] }, 'type': 'city' }), (Card(id_=0, action='Epidemic'), { 'id': 0, 'action': 'Epidemic', 'type': 'action' })]) def test_serialization(self, check_card, serialized): assert check_card.serialize() == serialized @pytest.mark.parametrize("check_card", [ Card(id_=0, action='Epidemic'), Card(id_=0, city=City(0, "Atlanta", "USA", 10.0, 0)) ]) def test_deserialization(self, check_card: Card): card_serialized = check_card.serialize() card_deserialized = Card.deserialize(card_serialized) assert card_deserialized == check_card
def add_epidemics(self): decks_quant = int(len(self.cards) / self.difficulty) decks = [ self.cards[x * decks_quant:(decks_quant * x) + decks_quant if x < self.difficulty - 1 else None] for x in range(self.difficulty) ] for i in range(self.difficulty): card = Card(self.card_id, action='Epidemic') self.card_id += 1 decks[i].append(card) shuffle(decks[i]) self.cards = list() for deck_with_epidemic in decks: self.cards += deck_with_epidemic
def action_card(self) -> Card: return Card(id_=1, action="Epidemic")
def city_card(self, city) -> Card: return Card(id_=0, city=city)
def init_infection(self): card_id = 0 for city in CITIES: card_ = Card(id_=card_id, city=city) self.cards.append(card_) card_id += 1
def test_deserialize(self, board, player, serialized): card = Card(id_=0, city=board.locations[0]) player.add_card(card) assert Player.deserialize(data=serialized, board=board) == player
def test_serialize(self, board, player, serialized): card = Card(id_=0, city=board.locations[0]) player.add_card(card) assert player.serialize() == serialized
def test_travel_to(self, board, player): card = Card(id_=36, city=board.locations[36]) player.add_card(card) assert player.possible_travel_to() == [board.locations[36]]
def test_possible_travel_from(self, board, player): card = Card(id_=0, city=board.locations[0]) player.add_card(card) assert player.possible_travel_from()
def test_add_card(self, board, player): card = Card(id_=0, city=board.locations[0]) player.add_card(card) assert player.cards == [card]
def init_player_deck(self): self.card_id = 0 for city in CITIES: card = Card(self.card_id, city) self.cards.append(card) self.card_id += 1
def create_cards(card_names): cards = [] for card_name in card_names: for _ in range(CARD_INSTANCES): cards.append(Card(card_name)) return cards