Example #1
0
    def testOneFile(self):
        self.shortDescription()
        fsm = parseFSM(self.fsmlFile)
        with open(self.inputFile) as inputFile, open(
                self.correctOutputFile) as outFile:
            correctInputJson = json.load(inputFile)

            # (1) this is the correct output which is created together with the input
            correctJsonOutput = json.load(outFile)

            # (2) this is the output of the Simulator.py module of assignment 2
            simulatedJsonOutput = simulateFSM(fsm, list(correctInputJson))

            # (3) what follows is the output of the dynamically generated TurnstileStepper modules
            generateCode(fsm)  # generate Stepper and Handler
            import TurnstileHandler_generated  # import the newly generated modules (& update their reference)
            reload(TurnstileHandler_generated)
            import TurnstileStepper_generated
            reload(TurnstileStepper_generated)
            stepper = TurnstileStepper_generated.Stepper()
            generatedJsonOutput = stepper.simulateFSM_generated(
                list(correctInputJson))
            try:
                os.remove('./TurnstileStepper_generated.pyc')
                os.remove('./TurnstileHandler_generated.pyc')
            except OSError:
                pass

            # assert all 3 are equal
            self.assertEqual(correctJsonOutput, simulatedJsonOutput)
            self.assertEqual(correctJsonOutput, generatedJsonOutput)
Example #2
0
    def testOneFile(self):
        self.shortDescription()
        fsm = parseFSM(self.fsmlFile)
        with open(self.inputFile) as inputFile, open(self.correctOutputFile) as outFile:
            correctInputJson = json.load(inputFile)

            # (1) this is the correct output which is created together with the input
            correctJsonOutput = json.load(outFile)

            # (2) this is the output of the Simulator.py module of assignment 2
            simulatedJsonOutput = simulateFSM(fsm, list(correctInputJson))

             # (3) what follows is the output of the dynamically generated TurnstileStepper modules
            generateCode(fsm)  # generate Stepper and Handler
            import TurnstileHandler_generated  # import the newly generated modules (& update their reference)
            reload(TurnstileHandler_generated)
            import TurnstileStepper_generated
            reload(TurnstileStepper_generated)
            stepper = TurnstileStepper_generated.Stepper()
            generatedJsonOutput = stepper.simulateFSM_generated(list(correctInputJson))
            try:
                os.remove('./TurnstileStepper_generated.pyc')
                os.remove('./TurnstileHandler_generated.pyc')
            except OSError:
                pass

            # assert all 3 are equal
            self.assertEqual(correctJsonOutput, simulatedJsonOutput)
            self.assertEqual(correctJsonOutput, generatedJsonOutput)
Example #3
0
def main():
    try:
        fsm = parseFSM("./sample.fsml")
        sampleInput = json.load(open("./sample_input.json", "r"))

        # just for visualization of the fsm dict (not needed anywhere in the code)
        jsonFile = open("./sample_fsml.json", 'w')
        jsonFile.write(json.dumps(fsm))

        # check the ok constraints
        ok(fsm)
        #simulate the fsm
        output = simulateFSM(fsm, sampleInput)
        # dump the simulation output to file
        outFile = open("./sample_output.json", 'w')
        outFile.write(json.dumps(output))

        #generate Code
        generateCode(fsm)

        #draw fsm
        drawFSM(fsm)

    except FsmException:
        raise
Example #4
0
def main():
    try:
        fsm = parseFSM("./sample.fsml")
        sampleInput = json.load(open("./sample_input.json", "r"))

        # just for visualization of the fsm dict (not needed anywhere in the code)
        jsonFile = open("./sample_fsml.json", 'w')
        jsonFile.write(json.dumps(fsm))

        # check the ok constraints
        ok(fsm)
        #simulate the fsm
        output = simulateFSM(fsm, sampleInput)
        # dump the simulation output to file
        outFile = open("./sample_output.json", 'w')
        outFile.write(json.dumps(output))

        #generate Code
        generateCode(fsm)

        #draw fsm
        drawFSM(fsm)

    except FsmException:
        raise
Example #5
0
    def testSimulationOutput(self):
        # load the base line output
        correctJsonOutput = json.load(open("../baseline_output.json"))

        # produce the output of the generated modules
        generatedJsonOutput = self.stepper.simulateFSM_generated(self.input)

        # produce the output of the hand-written simulator module
        simulatedJsonOutput = simulateFSM(self.fsm, self.input)

        # assert all 3 types of output are equal
        self.assertEqual(correctJsonOutput, simulatedJsonOutput)
        self.assertEqual(correctJsonOutput, generatedJsonOutput)