nz.ac.waikato.modeljunit.examples
Class AlarmClock

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

public class AlarmClock
extends java.lang.Object
implements TimedFsmModel


Field Summary
 int alarmTimer
          The time that the alarm will go off.
 int currentTime
          The current time of the clock
 
Constructor Summary
AlarmClock()
           
 
Method Summary
 void alarmOff()
           
 boolean alarmOffGuard()
           
 void alarmOn()
           
 boolean alarmOnGuard()
           
 void cancelAlarm()
           
 boolean cancelAlarmGuard()
           
 int getNextTimeIncrement()
          Function used to get the amount of time to move forward the next time that the time is incremented.
 java.lang.Object getState()
          Return the current state of the FSM model.
static void main(java.lang.String[] args)
           
 void printAction(java.lang.String action)
           
 void reset(boolean testing)
          Reset the model to its initial state.
 void setAlarm()
           
 boolean setAlarmGuard()
          Guard for the setAlarm action, only allows the action to occur if the alarm is not currently set
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

alarmTimer

public int alarmTimer
The time that the alarm will go off. (-1 == not set)


currentTime

public int currentTime
The current time of the clock

Constructor Detail

AlarmClock

public AlarmClock()
Method Detail

getState

public java.lang.Object 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.

setAlarmGuard

public boolean setAlarmGuard()
Guard for the setAlarm action, only allows the action to occur if the alarm is not currently set

Returns:
true if the alarm is not set, otherwise false

setAlarm

public void setAlarm()

cancelAlarmGuard

public boolean cancelAlarmGuard()

cancelAlarm

public void cancelAlarm()

alarmOnGuard

public boolean alarmOnGuard()

alarmOn

public void alarmOn()

alarmOffGuard

public boolean alarmOffGuard()

alarmOff

public void alarmOff()

getNextTimeIncrement

public int getNextTimeIncrement()
Description copied from interface: TimedFsmModel
Function used to get the amount of time to move forward the next time that the time is incremented. The framework will check whether this increment would advance the time past any enabled timeout(s) and handles execution of the timeout(s).

Specified by:
getNextTimeIncrement in interface TimedFsmModel
Returns:
an integer value greater than zero.

printAction

public void printAction(java.lang.String action)

main

public static void main(java.lang.String[] args)


Copyright © 2009 ModelJUnit Project. All Rights Reserved.