nz.ac.waikato.modeljunit.examples
Class TrafficLight

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

public class TrafficLight
extends java.lang.Object
implements TimedFsmModel


Nested Class Summary
static class TrafficLight.STATE
           
 
Field Summary
 int allowCarsTimer
          Timer to control the safety period where both lights are red because the lights are changing from allowing pedestrians to cross to allowing cars through
 int allowPedestriansTimer
          Timer to control the saftey period where both lights are red because the lights are changing from allowing cars through to allowing predestrians to cross
 int crossingTimer
          This timer controls the period in which the light is green for pedestrians to cross.
 int now
          The current time of the model
 int trafficFlowTimer
          This timer controls the minimum 20 second period in which the light must be green for cars.When the timer expires the minimumWaitElapsed action will be called
 
Constructor Summary
TrafficLight()
           
 
Method Summary
 void allowCars()
           
 boolean allowCarsGuard()
           
 void allowPedestrians()
           
 boolean allowPedestriansGuard()
          Guard for the safetyPeriodEnd action.
 void finishPedestrianPeriod()
           
 boolean finishPedestrianPeriodGuard()
           
 int getNextTimeIncrement()
          Take random steps of between 1 and 10 time units (inclusive)
 java.lang.Object getState()
          Return the current state of the FSM model.
static void main(java.lang.String[] args)
           
 void minimumWaitElapsed()
           
 boolean minimumWaitElapsedGuard()
           
 void pedestrianArrive()
          Action for pedestrians arriving at the crossing.
 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
 

Field Detail

trafficFlowTimer

public int trafficFlowTimer
This timer controls the minimum 20 second period in which the light must be green for cars.When the timer expires the minimumWaitElapsed action will be called


crossingTimer

public int crossingTimer
This timer controls the period in which the light is green for pedestrians to cross.


allowPedestriansTimer

public int allowPedestriansTimer
Timer to control the saftey period where both lights are red because the lights are changing from allowing cars through to allowing predestrians to cross


allowCarsTimer

public int allowCarsTimer
Timer to control the safety period where both lights are red because the lights are changing from allowing pedestrians to cross to allowing cars through


now

public int now
The current time of the model

Constructor Detail

TrafficLight

public TrafficLight()
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.

pedestrianArrive

public void pedestrianArrive()
Action for pedestrians arriving at the crossing. This can happen at any time so no guard is needed because it would always return true


allowPedestriansGuard

public boolean allowPedestriansGuard()
Guard for the safetyPeriodEnd action. We only want this action to occur when the safetyTimer expires so the guard is set up to do this.

Returns:
true when the allowPedestrians action is enabled.

allowPedestrians

public void allowPedestrians()

allowCarsGuard

public boolean allowCarsGuard()

allowCars

public void allowCars()

minimumWaitElapsedGuard

public boolean minimumWaitElapsedGuard()

minimumWaitElapsed

public void minimumWaitElapsed()

finishPedestrianPeriodGuard

public boolean finishPedestrianPeriodGuard()

finishPedestrianPeriod

public void finishPedestrianPeriod()

main

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

getNextTimeIncrement

public int getNextTimeIncrement()
Take random steps of between 1 and 10 time units (inclusive)

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


Copyright © 2009 ModelJUnit Project. All Rights Reserved.