def test_get_destination_on_edge(): # Given the default map and a line that ends on an edge m = Map() point_i, point_f = (0.5, 0.5), (0.5, 1.0) # When we attempt to get the destination dest = m.get_destination(*point_i, *point_f) # Then we get the collision assert dest == point_f
def test_get_destination_no_collision(): # Given the default map and a line that does not intersect the edges m = Map() point_i, point_f = (0.2, 0.5), (0.5, 0.5) # When we attempt to get the destination dest = m.get_destination(*point_i, *point_f) # Then we get the expected destination assert dest == point_f
def test_get_destination_vortex(): # Given the default map and a line that intersects the vortex m = Map() point_i, point_f = (0.5, 0.5), (1.5, 1.5) # When we attempt to get the destination dest = m.get_destination(*point_i, *point_f) # Then we get the collision assert dest == (1.0, 1.0)
def get_map(self, map_nb): # Initialize map if map_nb > 0: areas = self.default_map(map_nb) else: areas = self.make_map() if areas: if len(areas) > 1: return Map(areas[0], areas[1:]) else: return Map(areas[0]) else: return Map()
def test_map_empty(): # Given a map with no arguments m = Map() # Then we have a map defined by the max regions, and no obstacles x_range, y_range = (m.x_min, m.x_max), (m.y_min, m.y_max) assert sorted(m.map_region.corners) == sorted( [p for p in product(*[x_range, y_range])]) assert not m.obstacles
def test_map_standard(): # Given a map with defined arguments map_borders = [(0.2, 0.2), (0.1, 0.7), (0.5, 0.9), (0.8, 0.6), (0.7, 0.3)] boundaries = [[(0.3, 0.35), (0.5, 0.35), (0.5, 0.45), (0.3, 0.45)], [(0.3, 0.7), (0.4, 0.78), (0.42, 0.65)]] m = Map(map_borders, boundaries) # Then we obtained the expected map assert m.map_region.corners == map_borders assert all(obstacle.corners in boundaries for obstacle in m.obstacles)
def __init__(self, borders=(((0,0),(0,1),(1,1),(1,0)))): if len(borders)>1: self.map=Map(borders[0],borders[1:]) else: self.map=Map(borders[0]) self.grid=[[Square]]
class Grid(): def __init__(self, borders=(((0,0),(0,1),(1,1),(1,0)))): if len(borders)>1: self.map=Map(borders[0],borders[1:]) else: self.map=Map(borders[0]) self.grid=[[Square]] Borders=[[(0.2, 0.2), (0.1, 0.7), (0.5, 0.9), (0.8, 0.6), (0.7, 0.3)], [(0.3, 0.35), (0.5, 0.35), (0.5, 0.45), (0.3, 0.45)], [(0.3, 0.7), (0.4, 0.78), (0.42, 0.65)], [(0.5, 0.7), (0.7, 0.6), (0.7, 0.45), (0.6, 0.46), (0.65, 0.57)]] m=Map(Borders[0], Borders[1:]) def split_square(square): # Splits square area into 4 equal square areas width=square.width/2 height=square.height/2 square1=[coords,width,height,new_wall_prob(coords,width,height)] square2=[(coords[0],coords[1]+width),width,height,new_wall_prob((coords[0],coords[1]+width),width,height)] square3=[(coords[0]+height,coords[1]),width,height,new_wall_prob((coords[0]+height,coords[1]),width,height)] square4=[(coords[0]+height,coords[1]+width),width,height,new_wall_prob((coords[0]+height,coords[1]+width),width,height)] def new_wall_prob(world_map, point, width, height): # Checks probability of area containing an obstacle