def test_interact(self): name = 'tavern' pos = (3, 2) sprite = 'imgs/houses/blue_house.png' interaction = None items = [random_item(), random_item()] shop = Shop(name, pos, sprite, interaction, items) actor = random_character_entity() entries = shop.interact(actor) print(entries)
def test_init_shop(self): name = 'tavern' pos = (3, 2) sprite = 'imgs/houses/blue_house.png' interaction = None items = [random_item(), random_item()] shop = Shop(name, pos, sprite, interaction, items) self.assertEqual(name, shop.name) self.assertEqual(pos, shop.pos) self.assertEqual('Tavern', str(shop)) self.assertTrue(items[0] in shop.items) self.assertTrue(items[1] in shop.items)
def test_add_multiple_items(self): movable_entity = random_movable_entity() item = random_item() other_item = random_item() self.assertTrue(movable_entity.has_free_space()) self.assertEqual(0, len(movable_entity.items)) self.assertTrue(movable_entity.set_item(item)) self.assertTrue(movable_entity.set_item(other_item)) self.assertEqual(2, len(movable_entity.items)) self.assertEqual(item, movable_entity.get_item(0)) self.assertEqual(other_item, movable_entity.get_item(1))
def test_id_uniqueness(self): items = [] for i in range(NB_TESTS_FOR_PROPORTIONS): items.append(random_item()) self.assertTrue(len(set(map(lambda it: it.id, items))), NB_TESTS_FOR_PROPORTIONS)
def test_init_shop(self): name = 'tavern' pos = (3, 2) sprite = 'imgs/houses/blue_house.png' interaction = None items = [{ 'item': random_item(), 'quantity': rd.randint(1, 10) }, { 'item': random_item(), 'quantity': rd.randint(1, 10) }] shop = Shop(name, pos, sprite, interaction, items) self.assertEqual(name, shop.name) self.assertEqual(pos, shop.pos) self.assertEqual('Tavern', str(shop)) self.assertTrue(items[0] in shop.stock) self.assertTrue(items[1] in shop.stock)
def test_remove_item(self): movable_entity = random_movable_entity() item = random_item() self.assertTrue(movable_entity.has_free_space()) self.assertEqual(0, len(movable_entity.items)) self.assertTrue(movable_entity.set_item(item)) self.assertEqual(item, movable_entity.remove_item(item)) self.assertEqual(0, len(movable_entity.items)) self.assertFalse(movable_entity.get_item(0))
def test_init_building_interactive(self): name = 'house' pos = (3, 2) sprite = 'imgs/houses/blue_house.png' interaction = { 'talks': [ random_string(min_len=10, max_len=100), random_string(min_len=10, max_len=100) ], 'gold': rd.randint(10, 1000), 'item': random_item() } house = Building(name, pos, sprite, interaction) self.assertEqual(name, house.name) self.assertEqual(pos, house.pos) self.assertEqual(interaction, house.interaction) self.assertEqual('House', str(house))
def test_init_mision(self): is_main = True nature = MissionType.POSITION positions = [(1 * TILE_SIZE, 2 * TILE_SIZE), (3 * TILE_SIZE, 4 * TILE_SIZE)] description = 'Test main mission' nb_players = 2 turn_limit = 10 gold_reward = 200 items_reward = [random_item()] mission = Mission(is_main, nature, positions, description, nb_players, turn_limit, gold_reward, items_reward) self.assertEqual(is_main, mission.main) self.assertEqual(nature, mission.type) self.assertEqual(positions, mission.positions) self.assertEqual(description, mission.desc) self.assertFalse(mission.ended) self.assertEqual(turn_limit, mission.turn_limit) self.assertEqual(gold_reward, mission.gold) self.assertEqual(items_reward, mission.items) self.assertEqual(nb_players, mission.min_chars) self.assertEqual(0, len(mission.succeeded_chars))
def test_open_chest_item(self): item = random_item() potential_items = [(item, 1.0)] chest = random_chest(item_set=potential_items) self.assertEqual(item, chest.open())