nz.ac.waikato.modeljunit
Class RandomTester

java.lang.Object
  extended by nz.ac.waikato.modeljunit.Tester
      extended by nz.ac.waikato.modeljunit.RandomTester
Direct Known Subclasses:
GreedyTester

public class RandomTester
extends Tester

Test a system by making random walks through an EFSM model of the system.


Field Summary
static double DEFAULT_RESET_PROBABILITY
          During random walk (including buildGraph), this is the default probability of doing reset() rather than choosing a random transition.
 
Fields inherited from class nz.ac.waikato.modeljunit.Tester
FIXEDSEED, model_, rand_
 
Constructor Summary
RandomTester(FsmModel fsm)
          A convenience constructor that puts a Model wrapper around an FsmModel.
RandomTester(Model model)
          Creates a test generator that can generate random walks.
 
Method Summary
 int doRandomAction()
          Take any randomly-chosen Action that is enabled.
 int doRandomActionOrReset()
          Randomly take an enabled transition, or do a reset with a certain probability (see getResetProbability()).
 int generate()
          Generates one step of a random walk through the model.
 java.lang.String getDescription()
          A brief description of this test generation algorithm.
 java.lang.String getName()
          The name of this test generation algorithm.
 double getResetProbability()
          The probability of spontaneously doing a reset rather than a normal transition during random walks etc.
 void setResetProbability(double prob)
          Set the probability of doing a reset during random walks.
 
Methods inherited from class nz.ac.waikato.modeljunit.Tester
addCoverageMetric, addListener, addListener, addListener, buildGraph, buildGraph, buildGraph, buildGraphBreadthFirst, generate, getModel, getRandom, printCoverage, reset, setRandom
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_RESET_PROBABILITY

public static final double DEFAULT_RESET_PROBABILITY
During random walk (including buildGraph), this is the default probability of doing reset() rather than choosing a random transition.

See Also:
Constant Field Values
Constructor Detail

RandomTester

public RandomTester(Model model)
Creates a test generator that can generate random walks.

Parameters:
model - Must be non-null;

RandomTester

public RandomTester(FsmModel fsm)
A convenience constructor that puts a Model wrapper around an FsmModel.

Parameters:
fsm - Must be non-null.
Method Detail

getName

public java.lang.String getName()
Description copied from class: Tester
The name of this test generation algorithm.

Specified by:
getName in class Tester

getDescription

public java.lang.String getDescription()
Description copied from class: Tester
A brief description of this test generation algorithm.

Specified by:
getDescription in class Tester

getResetProbability

public double getResetProbability()
The probability of spontaneously doing a reset rather than a normal transition during random walks etc.

Returns:
the reset probability

setResetProbability

public void setResetProbability(double prob)
Set the probability of doing a reset during random walks. Note that the average length of each test sequence will be roughly proportional to the inverse of this probability.

If this is set to 0.0, then resets will only be done when we reach a dead-end state (no enabled actions). This means that if the FSM contains a loop that does not have a path back to the initial state, then the random walks may get caught in that loop forever. For this reason, a non-zero probability is recommended.

The default probability is DEFAULT_RESET_PROBABILITY.

Parameters:
prob - Must be at least 0.0 and less than 1.0.

doRandomAction

public int doRandomAction()
Take any randomly-chosen Action that is enabled. Returns the number of the Action taken, -1 if all are disabled.

Returns:
The Action taken, or -1 if none are enabled.

doRandomActionOrReset

public int doRandomActionOrReset()
Randomly take an enabled transition, or do a reset with a certain probability (see getResetProbability()). If this method is called in a state where there are no Actions enabled, then it will perform a reset to start from the initial state again.

Returns:
The number of the transition taken, or -1 for a reset.

generate

public int generate()
Generates one step of a random walk through the model. This calls doRandomActionOrReset().

Specified by:
generate in class Tester
Returns:
the number of the action taken, or -1 if a reset was done.


Copyright © 2009 ModelJUnit Project. All Rights Reserved.