nz.ac.waikato.modeljunit.examples
Class FSM

java.lang.Object
  extended by nz.ac.waikato.modeljunit.examples.FSM
All Implemented Interfaces:
FsmModel

public class FSM
extends java.lang.Object
implements FsmModel

Simple example of a finite state machine (FSM) for testing.


Constructor Summary
FSM()
           
 
Method Summary
 void action0()
           
 boolean action0Guard()
           
 void action1()
           
 boolean action1Guard()
           
 void action2()
           
 boolean action2Guard()
           
 void actionNone()
           
 boolean actionNoneGuard()
           
 java.lang.String getState()
          Return the current state of the FSM model.
static void main(java.lang.String[] args)
          This main method illustrates how we can use ModelJUnit to generate a small test suite.
 void reset(boolean testing)
          Reset the model to its initial state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FSM

public FSM()
Method Detail

getState

public java.lang.String getState()
Description copied from interface: FsmModel
Return the current state of the FSM model. The objects returned by this method define the states (the nodes) of the finite state machine. The objects that are returned must have a correct implementation of the equals method, since this is used to decide whether two states are the same or not. It is common to return a string, but other kinds of objects can be used if desired (in which case, their toString() method will be used to get a printable form of each FSM state).

Advanced Feature: This method can be used to define equivalence classes over the states, if you want to reduce the number of states to keep the FSM small. For example, if you have a integer state variable I that can have a huge number of possible values, you could define your getState() method to return new Integer(I % 10). This would reduce the FSM to just 10 states, where FSM state 0 represents all the states where I=0 or I=10 or I=20 etc., and FSM state 1 represents all the states where I=1 or I=11 or I=21 etc.

Specified by:
getState in interface FsmModel
Returns:
An object that represents the current state.

reset

public void reset(boolean testing)
Description copied from interface: FsmModel
Reset the model to its initial state. If the testing parameter is true, then this reset and all the following actions should affect the SUT.

Specified by:
reset in interface FsmModel
Parameters:
testing - true means the SUT should be reset too.

action0Guard

public boolean action0Guard()

action0

public void action0()

action1Guard

public boolean action1Guard()

action1

public void action1()

action2Guard

public boolean action2Guard()

action2

public void action2()

actionNoneGuard

public boolean actionNoneGuard()

actionNone

public void actionNone()

main

public static void main(java.lang.String[] args)
This main method illustrates how we can use ModelJUnit to generate a small test suite. If we had an implementation of this model that we wanted to test, we would extend each of the above methods so that they called the methods of the implementation and checked the results of those methods. We also report the transition coverage of the model.



Copyright © 2009 ModelJUnit Project. All Rights Reserved.