def test_Negative_build_Route(self): self.testRoute = RouteFinder(self.testRoutes[0][0], self.testRoutes[0][1], self.systems) with self.assertRaises(TypeError): self.testRoute.buildRoute("TEST",0,self.testRoutes[0][0]) with self.assertRaises(TypeError): self.testRoute.buildRoute(self.testRoutes[0][1], 0, "TEST") with self.assertRaises(TypeError): self.testRoute.buildRoute(self.testRoutes[0][1], "Fail", self.testRoutes[0][0])
def test_Negative_jumps_Route(self): self.testRoute = RouteFinder(self.testRoutes[0][0], self.testRoutes[0][1], self.systems) self.testSys = System() line = self.testSysLine self.testSys.build(line[0], line[1], line[2], line[3], line[4], line[5], line[6],line[7]) with self.assertRaises(GeneralError): self.testRoute.jumpsRoute('normal',start=self.testSys) with self.assertRaises(GeneralError): self.testRoute.jumpsRoute('normal',end=self.testSys)
def test_PositiveInitiliseRoute(self): avoidence = [self.testRoutes[0][0]] self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], self.systems[self.sysNames["Jita"]], self.systems,avoidence) self.assertEqual(self.testRoute.mainStart, self.systems[self.sysNames["Amarr"]], "Fail: Start system not loaded/stored correctly") self.assertEqual(self.testRoute.mainEnd, self.systems[self.sysNames["Jita"]], "Fail: End system not loaded/stored correctly") self.assertEqual(self.testRoute.systems, self.systems, "Fail: Systems not loaded/stored correctly") self.assertEqual(self.testRoute.currentCalcs, 0, "Fail: Current Calcs not setup correctly") self.assertEqual(self.testRoute.avoidence, avoidence, "Fail: Avoidence list not loaded/stored correctly") self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], self.systems[self.sysNames["Jita"]], self.systems) self.assertEqual(self.testRoute.avoidence, [], "Fail: Avoidence not loaded correctly when none passed")
def test_Positive_get_Route_Jumps_LessSafe2(self): self.testRoute = RouteFinder(self.systems[self.sysNames["Jita"]], self.systems[self.sysNames['Amarr']], self.systems, []) expectedResult = 40 actualResult = self.testRoute.getRoute('lessSafe') for sys in actualResult: print sys.getName() print len(actualResult)-1 print self.systems[self.sysNames["Reblier"]].getSecurity() self.assertEqual(expectedResult, len(actualResult)-1, "Fail: Route length not correct, must be a fault somewhere in route generation")
def setupRouteFinder(self, origin, destiniation): settings = [] try: settings = self.ui.getSettings() #Get route type setting from UI except AttributeError: settings = [[self.systems[self.sysNames["Perimeter"]]]] #Get which type of algorithm to use algorithm = 'j' #TEMP #Get ship settings #Get Security filter setting avoidence = settings[0] #Get avoidance list #Get specific security status filtering #Get Sov setting #Generate route finder based on settings routeFinder = RouteFinder(origin, destiniation, self.systems, avoidence, algorithm) #Setup the route finder return routeFinder
def runRandomTester(main): runs = 20000 incons = 0 type2Better, type1Better = 0, 0 os.chdir(os.path.dirname(__file__)) file = open("AutoTestLog.txt", 'w') print("File open, running") for i in xrange(0, runs): start = main.systems[random.choice(list(main.systems.keys()))] end = main.systems[random.choice(list(main.systems.keys()))] avoidence = [] for j in xrange(0, 100): avoidence.append(main.systems[random.choice( list(main.systems.keys()))]) while (start == end): end = main.systems[random.choice(list(main.systems.keys()))] print(i) routeFinder = RouteFinder(start, end, main.systems, avoidence) jumps = [0, 0] ctime = 0 dtime = 0 if i % 2 == 0: result1 = test1(routeFinder, file, ctime, start, end) result2 = test2(routeFinder, file, dtime, start, end) else: result2 = test2(routeFinder, file, dtime, start, end) result1 = test1(routeFinder, file, ctime, start, end) ctime = result1[1] dtime = result2[1] jumps[0] = result1[0] jumps[1] = result2[0] file.write("\n") if (dtime < ctime): type2Better += 1 if (ctime < dtime): type1Better += 1 if (jumps[0] != jumps[1]): file.write("INCONSISTENCY!!!!!!!!!!!!!!!\n\n\n\n") incons += 1 file.write("Runs: " + str(runs) + " Inconsistencys : " + str(incons) + " Type 1 Better: " + str(type1Better) + "\t Type 2 Better: " + str(type2Better) + "/" + str(runs)) file.close() print("Done")
def test_NegativeInitiliseRoute(self): line= self.testRoutes fails4= {} with self.assertRaises(TypeError): self.testRoute = RouteFinder("Fails1", self.systems[self.sysNames["Jita"]], self.systems) with self.assertRaises(TypeError): self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], "Fails2", self.systems) with self.assertRaises(TypeError): self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], self.systems[self.sysNames["Jita"]], "Fails3") with self.assertRaises(IndexError): self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], self.systems[self.sysNames["Jita"]], fails4) with self.assertRaises(TypeError): self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], self.systems[self.sysNames["Jita"]], self.systems, "Fails") with self.assertRaises(GeneralError): self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], self.systems[self.sysNames["Jita"]], self.systems, ["Fails"])
def test_Positive_get_Route_Jumps_Avoidence(self): self.testRoute = RouteFinder(self.systems[self.sysNames["Jita"]], self.systems[self.sysNames['Amarr']], self.systems, [self.systems[self.sysNames["Perimeter"]]]) expectedResult = 10 actualResult = len(self.testRoute.getRoute('normal'))-1 self.assertEqual(expectedResult, actualResult, "Fail: Route length not correct, must be a fault somewhere in route generation")
class TestRouteMethods(unittest.TestCase): def setUp(self): main = Main("Unit Tests") main.loadSystems() main.loadGates() self.systems = main.systems self.sysNames = main.sysNames lines = [] path = os.path.dirname(__file__) os.chdir(path) fileName= "TestData.txt" with open(fileName, 'r') as testFile: for line in testFile: lines.append(line.strip("\n")) testFile.close() self.testSysLine = lines[0].split("\t") self.testRoutes = [] for i in xrange(0, len(lines)): if 13 <= i <= 22: self.testRoutes.append(lines[i].split("\t")) for i in xrange(0, len(self.testRoutes)): self.testRoutes[i][0] = self.systems[self.sysNames[self.testRoutes[i][0]]] self.testRoutes[i][1] = self.systems[self.sysNames[self.testRoutes[i][1]]] def test_PositiveInitiliseRoute(self): avoidence = [self.testRoutes[0][0]] self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], self.systems[self.sysNames["Jita"]], self.systems,avoidence) self.assertEqual(self.testRoute.mainStart, self.systems[self.sysNames["Amarr"]], "Fail: Start system not loaded/stored correctly") self.assertEqual(self.testRoute.mainEnd, self.systems[self.sysNames["Jita"]], "Fail: End system not loaded/stored correctly") self.assertEqual(self.testRoute.systems, self.systems, "Fail: Systems not loaded/stored correctly") self.assertEqual(self.testRoute.currentCalcs, 0, "Fail: Current Calcs not setup correctly") self.assertEqual(self.testRoute.avoidence, avoidence, "Fail: Avoidence list not loaded/stored correctly") self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], self.systems[self.sysNames["Jita"]], self.systems) self.assertEqual(self.testRoute.avoidence, [], "Fail: Avoidence not loaded correctly when none passed") def test_NegativeInitiliseRoute(self): line= self.testRoutes fails4= {} with self.assertRaises(TypeError): self.testRoute = RouteFinder("Fails1", self.systems[self.sysNames["Jita"]], self.systems) with self.assertRaises(TypeError): self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], "Fails2", self.systems) with self.assertRaises(TypeError): self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], self.systems[self.sysNames["Jita"]], "Fails3") with self.assertRaises(IndexError): self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], self.systems[self.sysNames["Jita"]], fails4) with self.assertRaises(TypeError): self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], self.systems[self.sysNames["Jita"]], self.systems, "Fails") with self.assertRaises(GeneralError): self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], self.systems[self.sysNames["Jita"]], self.systems, ["Fails"]) def test_Positive_get_Sys(self): self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], self.systems[self.sysNames["Jita"]], self.systems) expectedResult = self.systems[self.sysNames["Tanoo"]] actualResult = self.testRoute.getSys("30000001") self.assertEqual(expectedResult, actualResult, "Fail: Did not return correct System") def test_Negative_get_Sys(self): self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], self.systems[self.sysNames["Jita"]], self.systems) with self.assertRaises(KeyError): self.testRoute.getSys("301") def test_Positive_get_Adj(self): self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], self.systems[self.sysNames["Jita"]], self.systems) sys = self.systems[self.sysNames["Tanoo"]] expectedResult = sys.getadjSyss() actualResult = self.testRoute.getAdj(sys) self.assertEqual(expectedResult, actualResult, "Fail: getAdj not fetching the correct adj sys list") def test_Negative_get_Adj(self): self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], self.systems[self.sysNames["Jita"]], self.systems) with self.assertRaises(TypeError): self.testRoute.getAdj("Fails") def test_Positive_get_Route_Jumps(self): for i in xrange(0,len(self.testRoutes)): self.testRoute = RouteFinder(self.testRoutes[i][0], self.testRoutes[i][1], self.systems) expectedResult = int(self.testRoutes[i][2]) actualResult = len(self.testRoute.getRoute('normal'))-1 self.assertEqual(expectedResult, actualResult, "Fail: Route length not correct, must be a fault somewhere in route generation") def test_Negative_get_Route(self): self.testRoute = RouteFinder(self.testRoutes[0][0], self.testRoutes[0][1], self.systems) with self.assertRaises(GeneralError): self.testRoute.getRoute("Fails") def test_Negative_build_Route(self): self.testRoute = RouteFinder(self.testRoutes[0][0], self.testRoutes[0][1], self.systems) with self.assertRaises(TypeError): self.testRoute.buildRoute("TEST",0,self.testRoutes[0][0]) with self.assertRaises(TypeError): self.testRoute.buildRoute(self.testRoutes[0][1], 0, "TEST") with self.assertRaises(TypeError): self.testRoute.buildRoute(self.testRoutes[0][1], "Fail", self.testRoutes[0][0]) def test_Negative_jumps_Route(self): self.testRoute = RouteFinder(self.testRoutes[0][0], self.testRoutes[0][1], self.systems) self.testSys = System() line = self.testSysLine self.testSys.build(line[0], line[1], line[2], line[3], line[4], line[5], line[6],line[7]) with self.assertRaises(GeneralError): self.testRoute.jumpsRoute('normal',start=self.testSys) with self.assertRaises(GeneralError): self.testRoute.jumpsRoute('normal',end=self.testSys) def test_Positive_get_Route_Jumps_Avoidence(self): self.testRoute = RouteFinder(self.systems[self.sysNames["Jita"]], self.systems[self.sysNames['Amarr']], self.systems, [self.systems[self.sysNames["Perimeter"]]]) expectedResult = 10 actualResult = len(self.testRoute.getRoute('normal'))-1 self.assertEqual(expectedResult, actualResult, "Fail: Route length not correct, must be a fault somewhere in route generation") def test_Positive_get_Route_Jumps_Safe(self): self.testRoute = RouteFinder(self.systems[self.sysNames["Jita"]], self.systems[self.sysNames['Hek']], self.systems, []) expectedResult = 19 actualResult = len(self.testRoute.getRoute('safe'))-1 self.assertEqual(expectedResult, actualResult, "Fail: Route length not correct, must be a fault somewhere in route generation") def test_Positive_get_Route_Jumps_LessSafe(self): self.testRoute = RouteFinder(self.systems[self.sysNames["6-CZ49"]], self.systems[self.sysNames['Dodixie']], self.systems, []) expectedResult = 16 actualResult = self.testRoute.getRoute('lessSafe') def test_Positive_get_Route_Jumps_LessSafe2(self): self.testRoute = RouteFinder(self.systems[self.sysNames["Jita"]], self.systems[self.sysNames['Amarr']], self.systems, []) expectedResult = 40 actualResult = self.testRoute.getRoute('lessSafe') for sys in actualResult: print sys.getName() print len(actualResult)-1 print self.systems[self.sysNames["Reblier"]].getSecurity() self.assertEqual(expectedResult, len(actualResult)-1, "Fail: Route length not correct, must be a fault somewhere in route generation")
def test_Positive_get_Route_Jumps(self): for i in xrange(0,len(self.testRoutes)): self.testRoute = RouteFinder(self.testRoutes[i][0], self.testRoutes[i][1], self.systems) expectedResult = int(self.testRoutes[i][2]) actualResult = len(self.testRoute.getRoute('normal'))-1 self.assertEqual(expectedResult, actualResult, "Fail: Route length not correct, must be a fault somewhere in route generation")
def test_Negative_get_Route(self): self.testRoute = RouteFinder(self.testRoutes[0][0], self.testRoutes[0][1], self.systems) with self.assertRaises(GeneralError): self.testRoute.getRoute("Fails")
def test_Positive_get_Adj(self): self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], self.systems[self.sysNames["Jita"]], self.systems) sys = self.systems[self.sysNames["Tanoo"]] expectedResult = sys.getadjSyss() actualResult = self.testRoute.getAdj(sys) self.assertEqual(expectedResult, actualResult, "Fail: getAdj not fetching the correct adj sys list")
def test_Negative_get_Adj(self): self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], self.systems[self.sysNames["Jita"]], self.systems) with self.assertRaises(TypeError): self.testRoute.getAdj("Fails")
def test_Negative_get_Sys(self): self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], self.systems[self.sysNames["Jita"]], self.systems) with self.assertRaises(KeyError): self.testRoute.getSys("301")
def test_Positive_get_Sys(self): self.testRoute = RouteFinder(self.systems[self.sysNames["Amarr"]], self.systems[self.sysNames["Jita"]], self.systems) expectedResult = self.systems[self.sysNames["Tanoo"]] actualResult = self.testRoute.getSys("30000001") self.assertEqual(expectedResult, actualResult, "Fail: Did not return correct System")
def test_Positive_get_Route_Jumps_Safe(self): self.testRoute = RouteFinder(self.systems[self.sysNames["Jita"]], self.systems[self.sysNames['Hek']], self.systems, []) expectedResult = 19 actualResult = len(self.testRoute.getRoute('safe'))-1 self.assertEqual(expectedResult, actualResult, "Fail: Route length not correct, must be a fault somewhere in route generation")
def test_Positive_get_Route_Jumps_LessSafe(self): self.testRoute = RouteFinder(self.systems[self.sysNames["6-CZ49"]], self.systems[self.sysNames['Dodixie']], self.systems, []) expectedResult = 16 actualResult = self.testRoute.getRoute('lessSafe')