Exemple #1
0
 def testAddNode(self):
   my_mox = mox.Mox()
   my_mox.StubOutWithMock(map_data_node.db.Model, 'key')
   my_mox.StubOutWithMock(map_data_node.db.Model, '__init__')
   map_data_node.db.Model.key().MultipleTimes('1').AndReturn('key')
   map_data_node.db.Model.__init__(
       parent=IsA(map_data.MapData))
   my_map_data = MapData('map_id_0')
   my_map_data.nodes = []
   
   my_mox.ReplayAll()
   my_map_data.add_node()
   self.assertEqual(my_map_data.nodes, ['key'], my_map_data.nodes)
Exemple #2
0
 def testDelNode(self):
   my_mox = mox.Mox()
   mock_node = my_mox.CreateMock(MapDataNode)
   my_map_data = MapData('map_id_0')
   my_map_data.nodes = ['key']
   my_mox.StubOutWithMock(map_data_node.db.Model, 'get')
   map_data_node.db.Model.get('key').AndReturn(mock_node)
   mock_node.del_all_connect()
   mock_node.delete()
   my_mox.ReplayAll()
   
   my_map_data.del_node(key='key')
   self.assertEqual(my_map_data.nodes, [], my_map_data.nodes)
Exemple #3
0
    def parse(location_txt_file):
        text_file = open(location_txt_file, "r")
        locations = []
        passive_locations = []
        paths = []
        name_to_coord = {}

        for line in text_file.readlines():
            line = line.strip()
            if len(line) == 0 or line[0] == '#':
                continue
            tokens = line.split(" ")
            command = tokens[0]

            if command == "location":
                locations.append((tokens[1], int(tokens[2]), int(tokens[3])))
                name_to_coord[tokens[1]] = (int(tokens[2]), int(tokens[3]))

            elif command == "passive_location":
                passive_locations.append(
                    (tokens[1], int(tokens[2]), int(tokens[3])))
                name_to_coord[tokens[1]] = (int(tokens[2]), int(tokens[3]))

            elif command == "path":
                path1 = tokens[1]
                path2 = tokens[2]
                paths.append((name_to_coord[path1], name_to_coord[path2]))

        return MapData(locations=locations,
                       passive_locations=passive_locations,
                       paths=paths,
                       name_to_coord=name_to_coord)
Exemple #4
0
from map_data import MapData, map_40
from route_finder import RouteFinder
from space import Space

# Create the test data
map_data = MapData(intersections={
    0: [1, 2],
    1: [2, 3],
    2: [3, 4],
    3: [5, 6]
},
                   roads=[[1, 2], [0, 3], [0, 2], [1, 2]])

# Initialise the space and route finder
space = Space(map_data.intersections, map_data.roads)
finder = RouteFinder(space)

# Find a route between invalid nodes
assert finder.find_route(10, 0) == None
assert finder.find_route(0, 10) == None

# Now for the real deal
space = Space(map_40.intersections, map_40.roads)
finder = RouteFinder(space)

assert finder.find_route(5, 34) == [5, 16, 37, 12, 34]
assert finder.find_route(5, 5) == [5]
assert finder.find_route(8, 24) == [8, 14, 16, 37, 12, 17, 10, 24]