def generateIllegalInput(fsm): correctInput, _ = generateCorrectInput(fsm) errorPosition = randint(0, len(correctInput) - 1) feasibleInputs = [] for state in fsm: feasibleInputs += [transition["input"] for transition in state["transitions"]] wrongInput = randomWord() while wrongInput in feasibleInputs: wrongInput = randomWord() correctInput[errorPosition] = wrongInput return correctInput
def generateIllegalInput(fsm): correctInput, _ = generateCorrectInput(fsm) errorPosition = randint(0, len(correctInput) - 1) feasibleInputs = [] for state in fsm: feasibleInputs += [ transition['input'] for transition in state['transitions'] ] wrongInput = randomWord() while wrongInput in feasibleInputs: wrongInput = randomWord() correctInput[errorPosition] = wrongInput return correctInput
def generatePositiveTestData(depth): removeOldCorrectTestFiles() templatefiles = generateRawTemplates(depth) env = Environment(loader=FileSystemLoader('.')) count = 0 for file in templatefiles: # after this command, the placeholders of the file are replaced with jinja placeholders transList = generateJinjaTemplateFile(file) try: # generate correct .fsml File fsm = createSpecificFSM(transList) template = env.get_template(file) fsmlData = template.render(states=fsm) fsmlFile = open( os.path.join("./testdata/positive/fsm", "sample" + file.split("template")[2] + ".fsml"), 'w') fsmlFile.write(fsmlData) fsmlFile.close() # generate correct input .json File correctInput, correctOutput = generateCorrectInput(fsm) inputFile = open( "./testdata/positive/input/input" + file.split("template")[2] + ".json", 'w') inputFile.write(json.dumps(correctInput)) inputFile.close() outputFile = open( "./testdata/positive/output/output" + file.split("template")[2] + ".json", 'w') outputFile.write(json.dumps(correctOutput)) outputFile.close() count += 1 except ValueError: os.remove(file) print str(count) + " test-data files generated"
def generatePositiveTestData(depth): removeOldCorrectTestFiles() templatefiles = generateRawTemplates(depth) env = Environment(loader=FileSystemLoader('.')) count = 0 for file in templatefiles: # after this command, the placeholders of the file are replaced with jinja placeholders transList = generateJinjaTemplateFile(file) try: # generate correct .fsml File fsm = createSpecificFSM(transList) template = env.get_template(file) fsmlData = template.render(states=fsm) fsmlFile = open(os.path.join("./testdata/positive/fsm", "sample"+file.split("template")[2]+".fsml"), 'w') fsmlFile.write(fsmlData) fsmlFile.close() # generate correct input .json File correctInput, correctOutput = generateCorrectInput(fsm) inputFile = open("./testdata/positive/input/input"+file.split("template")[2]+".json", 'w') inputFile.write(json.dumps(correctInput)) inputFile.close() outputFile = open("./testdata/positive/output/output"+file.split("template")[2]+".json", 'w') outputFile.write(json.dumps(correctOutput)) outputFile.close() count += 1 except ValueError: os.remove(file) print str(count)+" test-data files generated"