Have a look at the "step" method in the "State" class in the "fsm.kmt" file.
// Go to the next state operation step(c : String) : String raises FSMException is // Declaration of the pre-condition pre notVoidInput is c != void and c != "" do // Get the valid transitions var validTransitions : Collection<Transition> validTransitions := outgoingTransition.select { t | t.input.equals(c) } // Check if there is one and only one valid transition if validTransitions.empty then raise NoTransition.new end if validTransitions.size > 1 then raise NonDeterminism.new end // Fire the transition result := validTransitions.one.fire end // Declaration of the post-condition post notVoidOutput is result != void and result != ""
There is a pre condition which says that the character given as a parameter must not be void or empty string. The post condition says that the result must not be void or empty string. For each "step" method call, the pre and post conditions will be checked. If there are evaluated as false, the program is aborted otherwise the program goes on. Look at the run configuration named "loaderFSM4prepost". Open the file (../models/sample1postv.fsm) used as parameter for this configuration. Observe the finite state diagram.
Execute "loaderFSM4prepost" configuration. When you are asked for a letter , just press enter to send an empty string. Normally, it should provoke the violation of the pre condition. before loading after loading State : s1 Transition : s1-(c/NC)->s2 State : s2 Transition : s2-(x/y)->s2 Current state : s1 give me a letter : stepping... [kermeta::exceptions::ConstraintViolatedPre:8670] pre notVoidInput of operation step of class State violated
Execute "loaderFSM4prepost" configuration. When you are asked for a letter , press c and then press enter. Normally, the post condition will be violated because the result will be an empty string. before loading after loading State : s1 Transition : s1-(c/NC)->s2 State : s2 Transition : s2-(x/y)->s2 Current state : s1 give me a letter : c c stepping... [kermeta::exceptions::ConstraintViolatedPost:9684] post notVoidOutput of operation step of class State violated