def main(): myMap = CvtdMap() command = "help" while command not in ["quit", "exit", "q", "e"]: if command == "1": new_street(myMap) elif command == "2": search_streets(myMap) elif command == "3": pass elif command == "4": search_nodes(myMap) elif command == "5": new_route(myMap) elif command == "6": pass elif command == "7": pass elif command == "8": pass elif command == "11": myMap.import_google_directory() elif command == "12": import_osm(myMap) elif command == 'v': myMap.validate() elif command.lower().strip().split()[0] in ['r', 'read', 'o', 'open']: myMap.read_roads(get_filename(command)) elif command.lower().strip().split()[0] in ['w', 'write', 's', 'save']: myMap.write_roads(get_filename(command)) else: show_help() command = input("\n>>> ") print("ROAD LIST COUNT = {}".format(len(myMap.roadList)))
def test_read_write_roads(self): myMap = CvtdMap() myMap.nodeDict[0] = (CvtdNode(1, 1)) myMap.nodeDict[1] = (CvtdNode(4, 4)) myMap.nodeDict[2] = (CvtdNode(1, 4)) myMap.nodeDict[3] = (CvtdNode(4, 1)) myMap.nodeDict[4] = (CvtdNode(3, 4)) myMap.nodeDict[5] = (CvtdNode(4, 3)) thisRoad = CvtdRoad() thisRoad.name = "Road from 0 to 60" thisRoad.dir = "Up" thisRoad.points.append(CvtdRoadPoint(0, 0)) thisRoad.points.append(CvtdRoadPoint(1, 30)) thisRoad.points.append(CvtdRoadPoint(2, 60)) myMap.roadList.append(thisRoad) thisRoad = CvtdRoad() thisRoad.name = "Road from 0 to 60" thisRoad.dir = "Up" thisRoad.points.append(CvtdRoadPoint(1, 0)) thisRoad.points.append(CvtdRoadPoint(3, 30)) thisRoad.points.append(CvtdRoadPoint(4, 50)) thisRoad.points.append(CvtdRoadPoint(5, 60)) myMap.roadList.append(thisRoad) thisRoad = CvtdRoad() thisRoad.name = "Road from 0 to 50" thisRoad.dir = "Up" thisRoad.points.append(CvtdRoadPoint(0, 0)) thisRoad.points.append(CvtdRoadPoint(5, 50)) myMap.roadList.append(thisRoad) myMap.write_roads("tmp_roads.txt") myCmpMap = CvtdMap() myCmpMap.read_roads("tmp_roads.txt") self.assertEqual(len(myMap.nodeDict), len(myCmpMap.nodeDict)) self.assertEqual(len(myMap.roadList), len(myCmpMap.roadList)) self.assertEqual(myMap.nodeDict[0].lat, myCmpMap.nodeDict[0].lat) self.assertEqual(myMap.nodeDict[0].lon, myCmpMap.nodeDict[0].lon) self.assertEqual(myMap.nodeDict[1].lat, myCmpMap.nodeDict[1].lat) self.assertEqual(myMap.nodeDict[1].lon, myCmpMap.nodeDict[1].lon) self.assertEqual(myMap.nodeDict[2].lat, myCmpMap.nodeDict[2].lat) self.assertEqual(myMap.nodeDict[2].lon, myCmpMap.nodeDict[2].lon) self.assertEqual(myMap.nodeDict[3].lat, myCmpMap.nodeDict[3].lat) self.assertEqual(myMap.nodeDict[3].lon, myCmpMap.nodeDict[3].lon) self.assertEqual(myMap.nodeDict[4].lat, myCmpMap.nodeDict[4].lat) self.assertEqual(myMap.nodeDict[4].lon, myCmpMap.nodeDict[4].lon) self.assertEqual(myMap.nodeDict[5].lat, myCmpMap.nodeDict[5].lat) self.assertEqual(myMap.nodeDict[5].lon, myCmpMap.nodeDict[5].lon) self.assertEqual(myMap.roadList[0].name, myCmpMap.roadList[0].name) self.assertEqual(myMap.roadList[0].dir, myCmpMap.roadList[0].dir) self.assertEqual(myMap.roadList[0].points[0].node, myCmpMap.roadList[0].points[0].node) self.assertEqual(myMap.roadList[0].points[0].addr, myCmpMap.roadList[0].points[0].addr) self.assertEqual(myMap.roadList[0].points[1].node, myCmpMap.roadList[0].points[1].node) self.assertEqual(myMap.roadList[0].points[1].addr, myCmpMap.roadList[0].points[1].addr) self.assertEqual(myMap.roadList[0].points[2].node, myCmpMap.roadList[0].points[2].node) self.assertEqual(myMap.roadList[0].points[2].addr, myCmpMap.roadList[0].points[2].addr) self.assertEqual(myMap.roadList[1].name, myCmpMap.roadList[1].name) self.assertEqual(myMap.roadList[1].dir, myCmpMap.roadList[1].dir) self.assertEqual(myMap.roadList[1].points[0].node, myCmpMap.roadList[1].points[0].node) self.assertEqual(myMap.roadList[1].points[0].addr, myCmpMap.roadList[1].points[0].addr) self.assertEqual(myMap.roadList[1].points[1].node, myCmpMap.roadList[1].points[1].node) self.assertEqual(myMap.roadList[1].points[1].addr, myCmpMap.roadList[1].points[1].addr) self.assertEqual(myMap.roadList[1].points[2].node, myCmpMap.roadList[1].points[2].node) self.assertEqual(myMap.roadList[1].points[2].addr, myCmpMap.roadList[1].points[2].addr) self.assertEqual(myMap.roadList[1].points[3].node, myCmpMap.roadList[1].points[3].node) self.assertEqual(myMap.roadList[1].points[3].addr, myCmpMap.roadList[1].points[3].addr) self.assertEqual(myMap.roadList[2].name, myCmpMap.roadList[2].name) self.assertEqual(myMap.roadList[2].dir, myCmpMap.roadList[2].dir) self.assertEqual(myMap.roadList[2].points[0].node, myCmpMap.roadList[2].points[0].node) self.assertEqual(myMap.roadList[2].points[0].addr, myCmpMap.roadList[2].points[0].addr) self.assertEqual(myMap.roadList[2].points[1].node, myCmpMap.roadList[2].points[1].node) self.assertEqual(myMap.roadList[2].points[1].addr, myCmpMap.roadList[2].points[1].addr) os.remove("tmp_roads.txt")