nz.ac.waikato.modeljunit
Class LookaheadTester

java.lang.Object
  extended by nz.ac.waikato.modeljunit.Tester
      extended by nz.ac.waikato.modeljunit.LookaheadTester

public class LookaheadTester
extends Tester

A test generator that looks N-levels ahead in the graph. It chooses the highest-valued transition (action) that is enabled in the current state. The value of transitions/actions and states is determined by three parameters, NEWTRANS, NEWACTION and DEPTH. In a given state, the value of an action that has never been taken before in that state (so its destination state is unknown) is NEWACTION if its action has never been taken anywhere in the graph, or NEWTRANS if its action has been taken elsewhere. The value of an action that has been taken before is the value of the state that it leads to (*), minus the number of times that the transition has been taken. So previously-taken paths gradually become less and less attractive. (*) if the action is non-deterministic, then there are several transitions labelled with that action, and the value of the action is the maximum of the value of those transitions. The value of a state is zero if it is the current state, or if it is at least DEPTH steps away from the current state, otherwise it is the maximum value of its outgoing transitions. This means that the lookahead is limited to paths of length DEPTH. The get/setMaxLength methods can be used to control the maximum length of each generated test. If the test generation has not reached a terminal state before that length, it does a reset.

Author:
Pele Douangsavanh and Mark Utting

Field Summary
protected  CoverageMetric actions_
           
protected  int currLength_
          The length of the current test sequence generated by this tester.
protected  int DEPTH
          How far should we look ahead?
protected  GraphListener graph_
           
protected  int maxLength_
          The maximum length of each generated test
protected  int NEW_ACTION
          How worthwhile is it to use a completely new action?
protected  int NEW_TRANS
          How worthwhile is it to explore a new transition?
protected  CoverageMetric transitions_
           
 
Fields inherited from class nz.ac.waikato.modeljunit.Tester
FIXEDSEED, model_, rand_
 
Constructor Summary
LookaheadTester(FsmModel fsm)
          A convenience constructor that puts a Model wrapper around an FsmModel.
LookaheadTester(Model model)
          Creates a test generator that can does smart look ahead.
 
Method Summary
 int evalState(java.lang.Object state, int depth)
          Evaluate the desirability of reaching state.
 int generate()
          Generate one more test step in the current sequence.
 int getDepth()
           
 java.lang.String getDescription()
          A brief description of this test generation algorithm.
 int getMaxLength()
          The maximum length of each generated test.
 java.lang.String getName()
          The name of this test generation algorithm.
 int getNewActionValue()
           
 int getNewTransValue()
           
static void main(java.lang.String[] args)
           
 void reset()
          Performs a user-requested reset of the model.
 void setDepth(int depth)
          Set the lookahead depth.
 void setMaxLength(int maxLength)
          Set the maximum length of each generated test.
 void setNewActionValue(int value)
          Set the NEW_ACTION parameter.
 void setNewTransValue(int value)
          Set the NEW_TRANS parameter.
 
Methods inherited from class nz.ac.waikato.modeljunit.Tester
addCoverageMetric, addListener, addListener, addListener, buildGraph, buildGraph, buildGraph, buildGraphBreadthFirst, generate, getModel, getRandom, printCoverage, setRandom
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NEW_TRANS

protected int NEW_TRANS
How worthwhile is it to explore a new transition?


NEW_ACTION

protected int NEW_ACTION
How worthwhile is it to use a completely new action?


DEPTH

protected int DEPTH
How far should we look ahead?


maxLength_

protected int maxLength_
The maximum length of each generated test


currLength_

protected int currLength_
The length of the current test sequence generated by this tester.


graph_

protected GraphListener graph_

transitions_

protected CoverageMetric transitions_

actions_

protected CoverageMetric actions_
Constructor Detail

LookaheadTester

public LookaheadTester(Model model)
Creates a test generator that can does smart look ahead.

Parameters:
model - Must be non-null;

LookaheadTester

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

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

getDepth

public int getDepth()
Returns:
the depth of the recursive lookahead

setDepth

public void setDepth(int depth)
Set the lookahead depth. depth=N means explore all known paths ahead upto length N. depth=1 means look only at the outgoing transitions of the current state, so this gives similar behaviour to GreedyTester (but not exactly the same, because this tester uses alphabetical ordering of the transition names to decide between equally good transitions, whereas GreedyTester makes a random choice between them).

Parameters:
depth - the depth of the recursive lookahead (1..n) This should be reasonably small, otherwise the lookahead may be exponentially slow. The default value is 3.

getNewActionValue

public int getNewActionValue()

setNewActionValue

public void setNewActionValue(int value)
Set the NEW_ACTION parameter. Higher values make the lookahead more eager to try new actions.

Parameters:
value -

getNewTransValue

public int getNewTransValue()

setNewTransValue

public void setNewTransValue(int value)
Set the NEW_TRANS parameter. Higher values make the lookahead more eager to try new transitions (actions that are in the TODO list of a given state).

Parameters:
value -

getMaxLength

public int getMaxLength()
The maximum length of each generated test.


setMaxLength

public void setMaxLength(int maxLength)
Set the maximum length of each generated test.


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

evalState

public int evalState(java.lang.Object state,
                     int depth)
Evaluate the desirability of reaching state. However, at the top level of recursion (when depth equals getDepth()), it returns the number of the best action to take.

Parameters:
state -
depth - The depth of lookahead
Returns:
A desirability integer, or an action number.

reset

public void reset()
Description copied from class: Tester
Performs a user-requested reset of the model.

Overrides:
reset in class Tester

generate

public int generate()
Description copied from class: Tester
Generate one more test step in the current sequence. This may reset and start a new test sequence if necessary.

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

main

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


Copyright © 2009 ModelJUnit Project. All Rights Reserved.