def generate_scenes_test(): # 100 trials for x in xrange(100): a_map = map_.Map('story') map_gen.ID_SEQ = 1 map_gen.generate_scenes(a_map) scene_dict = map_gen.create_scene_dict(a_map) # Test if any scenes overlap in location so_far = [] for sc in a_map.scenes.values(): ok_(sc.location not in so_far) so_far.append(sc.location) # Test if enough links are added for a connected map ok_(count_links(a_map) == len(a_map.scenes.values())-1) # Test if every generated scene is adjacent to at least one other scene for s in a_map.scenes.values(): # create list of all adjacent locations to s adj_list = map_gen.all_adjacent(s.location) linked = False # test if there is at least one adjacent scene to s for adj_loc in adj_list: if adj_loc in scene_dict: linked = True else: pass ok_(linked is True, "Unconnected scene at {}: {}".format( s.location, scene_dict)) # Test for map connectedness ok_(check_map_connectedness(a_map))
def add_lair_test(): # Test adding the boss' lair a_map = map_.Map('story') map_gen.generate_scenes(a_map) map_gen.add_lair(a_map) # Test that the map has exactly one lair count = 0 for sc in a_map.scenes.values(): for f in sc.features: if isinstance(f, map_.Lair): # found a scene with a lair # test if it's the scene the map thinks the lair is in ok_(sc.name == a_map.lair_scene_name) count +=1 ok_(count == 1)
def add_item_stashes_test(): # Test if the correct number of item stashes are added a_map = map_.Map('story') map_gen.generate_scenes(a_map) map_gen.add_item_stashes(a_map) # Test that no scene has more than one item stash nmap = 0 # total number of stashes in a map for sc in a_map.scenes.values(): nsc = 0 # number of stashes in one scene for f in sc.features: if isinstance(f, map_.ItemStash): nsc +=1 ok_(nsc <= 1) if nsc: nmap += 1 # Test if the correct number of item stashes are added to the map n = len(a_map.scenes.values()) ok_(nmap >= 3 and nmap <= int(0.15*n))