def test_genreMonthCount(self): '''Test that the function creates a dictionary counting the frequency of words''' # Expected result dataCount_result = { 'adventure': 2, 'drama': 16, 'crime': 4, 'comedy': 3, 'biography': 4, '6': 1, 'action': 1, 'none': 1, 'history': 1, 'romance': 1, '7.8': 1, 'sport': 1, 'december': 3, 'november': 5, 'october': 3, 'july': 1, 'january': 3, '112': 1, 'february': 1, 'may': 1 } # Call the genreMonthCount function and pass the test string data self.assertEqual(FileEditor.genreMonthCount(self.test_matrixString), dataCount_result)
def run(self): r = Runner.DynamicRunner(self.net, self.runFile) i = 0 #start simulation and log simTime startTime = time.time() r.createRandomTrips(self.pop) rc = RouteChanger.RouteChanger() rc.getFile() rc.writeFile() r.runNoGui() # r.runNoGui() simTime = time.time() - startTime #Analyse for traffic density fitness densityFitness = getFitness.main() #Create FileEditor object f = FileEditor.FileEditor(simTime, densityFitness) f.getOutput() f.getTimeStamps() #f.setBreakpoints() #f.writeFile() if f.getTeleports() > 0: fitness = round((densityFitness / f.getTeleports()), 2) print("Fitness: " + str(fitness)) else: fitness = densityFitness print("Fit: " + str(fitness)) print(str("Teleports: " + str(f.getTeleports()))) return fitness
def run(self): r = Runner.Runner(self.net, self.runFile) i = 0 while i < self.simNum: #start simulation and log simTime print("Count: " + str(i)) startTime = time.time() r.createRandomTrips() r.runNoGui() simTime = time.time() - startTime #Analyse for traffic density fitness densityFitness = getFitness.main() #Create FileEditor object f = FileEditor.FileEditor(simTime, densityFitness) f.getOutput() f.getTimeStamps() f.setBreakpoints() f.writeFile() if f.getTeleports() > 0: fitness = round((densityFitness / f.getTeleports()), 2) else: fitness = densityFitness f.setFitness(fitness) print("SimRun F: " + str(fitness)) #if collisions occur copy route data, warning file and breakpoint file print("Collision Num: " + str(f.getCollisionWarnings())) if f.getWarnings() > 0 and f.getTeleports() < 10: f.copyDir() f.copyFile() f.writeBreakPointFile() i += 1
def testValidInput(self): '''Test that the function passes through data that is valid and shows error for invalid data''' # Expected result for valid data movie1_result = (2018, 5, 7.7, 140, 64, 175, 136.73, 'action', 'adventure', 'march') # Call the validInput function to input data and create data in tuple self.assertEqual(FileEditor.validInput(), movie1_result)
#!/usr/bin/env python from FileEditor import * editor = FileEditor() editor.setIsTest(True) #editor.setBlockSize(5) #editor.setFilter(r'^ *namespace MolMcD *\n *{') #editor.setOld(r'MolMcD *\n *{( *\n)*') #editor.setNew(r'Util\n{\n\n') #for directory in mcmd_directories: # editor.editFiles(directory, "*.h") # editor.editFiles(directory, "*.cpp") #editor.setFilter(r'#define +([A-Z]+_)+H *$') #editor.setOld(r'#define +') #editor.setNew(r'#define ') #editor.editFiles(".", "*.h") #editor.setFilter(r'#ifndef +([A-Z]+_)+H *$') #editor.setOld(r'#ifndef +') #editor.setNew(r'#ifndef ') #editor.editFiles(".", "*.h") #editor.setFilter(r'MCMD_MCMD_') #editor.setOld(r'MCMD_MCMD_') #editor.setNew(r'MCMD_') #editor.editFiles(".", "*.h") #editor.editFiles(".", "*.cpp")
def yamlToMap(self): fileEditor=FileEditor() yamlFile=open('YamlFile.yml','r') testMap=fileEditor.fileToMap(yamlFile) return testMap
def createYamlFile(self,costMap): fileEditor=FileEditor() costmap=fileEditor.modifyValuesList(costMap) fileEditor.mapToFile(costMap)
def yamlToMap(self): fileEditor = FileEditor() yamlFile = open('YamlFile.yml', 'r') testMap = fileEditor.fileToMap(yamlFile) return testMap
def createYamlFile(self, costMap): fileEditor = FileEditor() costmap = fileEditor.modifyValuesList(costMap) fileEditor.mapToFile(costMap)