nz.ac.waikato.modeljunit.coverage
Class CoverageHistory

java.lang.Object
  extended by nz.ac.waikato.modeljunit.AbstractListener
      extended by nz.ac.waikato.modeljunit.coverage.CoverageHistory
All Implemented Interfaces:
CoverageMetric, ModelListener

public class CoverageHistory
extends AbstractListener
implements CoverageMetric

A wrapper class that adds history recording to any CoverageMetric. This is useful for drawing graphs of how the coverage changes over time etc. For example, new CoverageHistory(new ActionCoverage(), 10) behaves exactly the same as the ActionCoverage metric, but also records a snapshot of its coverage level each 10 calls to doneTransition(...).

Note that you must add this CoverageHistory wrapper as the listener to the model, rather than adding the underlying metric. If you add both, the metrics will be recorded twice as fast, which is probably not what you want!

Author:
marku

Field Summary
 
Fields inherited from class nz.ac.waikato.modeljunit.AbstractListener
model_
 
Constructor Summary
CoverageHistory(CoverageMetric metric, int interval)
          Create a history version of the coverage metric.
 
Method Summary
 void clear()
          This resets the history, as well as calling getMetric().reset();
 void doneGuard(java.lang.Object state, int action, boolean enabled, int value)
          The Model calls this after each guard evaluation.
 void doneReset(java.lang.String reason, boolean testing)
          The Model calls this after each reset(boolean) action.
 void doneTransition(int action, Transition tr)
          Delegates to getMetric().doneTransition(...), and records the resulting coverage.
 void failure(TestFailureException ex)
          The Model calls this when an action has found an error.
 int getCoverage()
          Returns getMetric().getCoverage().
 java.lang.String getDescription()
          Delegates to getMetric().getDescription().
 java.util.Map<java.lang.Object,java.lang.Integer> getDetails()
          Returns getMetric().getDetails().
 java.util.List<java.lang.Integer> getHistory()
          Returns the list of coverage snapshots.
 int getMaximum()
          Returns getMetric().getMaximum().
 CoverageMetric getMetric()
          Returns the underlying coverage metric.
 java.lang.String getName()
          Delegates to getMetric().getName().
 float getPercentage()
          Returns getMetric().getPercentage().
 void setGraph(InspectableGraph graph, java.util.Map<java.lang.Object,Vertex> state2vertex)
          Delegates to getMetric().setModel(...).
 void setModel(Model model)
          This tells the underlying metric about the model, even though the model will not be sending events directly to that metric (the events come through this wrapper).
 void startAction(java.lang.Object state, int action, java.lang.String name)
          This is called just before an action is about to be executed.
 java.lang.String toCSV()
          Converts the history coverage values to a comma-separated string.
 java.lang.String toString()
          Returns getMetric().toString().
 
Methods inherited from class nz.ac.waikato.modeljunit.AbstractListener
getModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface nz.ac.waikato.modeljunit.ModelListener
getModel
 

Constructor Detail

CoverageHistory

public CoverageHistory(CoverageMetric metric,
                       int interval)
Create a history version of the coverage metric. It records the value of metric.getCoverage() each interval calls to doneTransition.

Parameters:
metric - The coverage metric to add history to.
interval - How often to take snapshots.
Method Detail

getMetric

public CoverageMetric getMetric()
Returns the underlying coverage metric.


getName

public java.lang.String getName()
Delegates to getMetric().getName().

Specified by:
getName in interface ModelListener

getDescription

public java.lang.String getDescription()
Delegates to getMetric().getDescription().

Specified by:
getDescription in interface CoverageMetric

setModel

public void setModel(Model model)
This tells the underlying metric about the model, even though the model will not be sending events directly to that metric (the events come through this wrapper).

Specified by:
setModel in interface ModelListener
Overrides:
setModel in class AbstractListener

clear

public void clear()
This resets the history, as well as calling getMetric().reset();

Specified by:
clear in interface CoverageMetric

setGraph

public void setGraph(InspectableGraph graph,
                     java.util.Map<java.lang.Object,Vertex> state2vertex)
Delegates to getMetric().setModel(...).

Specified by:
setGraph in interface CoverageMetric

getCoverage

public int getCoverage()
Returns getMetric().getCoverage().

Specified by:
getCoverage in interface CoverageMetric

getMaximum

public int getMaximum()
Returns getMetric().getMaximum().

Specified by:
getMaximum in interface CoverageMetric

getPercentage

public float getPercentage()
Returns getMetric().getPercentage().

Specified by:
getPercentage in interface CoverageMetric

getHistory

public java.util.List<java.lang.Integer> getHistory()
Returns the list of coverage snapshots.


getDetails

public java.util.Map<java.lang.Object,java.lang.Integer> getDetails()
Returns getMetric().getDetails().

Specified by:
getDetails in interface CoverageMetric
Returns:
Map of how many times each object has been covered, or null.

toString

public java.lang.String toString()
Returns getMetric().toString().

Overrides:
toString in class java.lang.Object

toCSV

public java.lang.String toCSV()
Converts the history coverage values to a comma-separated string.

Returns:
A string, like "0,1,3,5,5,5"

doneGuard

public void doneGuard(java.lang.Object state,
                      int action,
                      boolean enabled,
                      int value)
Description copied from interface: ModelListener
The Model calls this after each guard evaluation. Note that this will be called even after an implicit guard (which always returns true) has been evaluated. The enabled boolean says whether the guard of action is enabled or not, while value gives the actual value returned by the guard method (0 for false, 1 for true, or other positive integer values for Markov chain guards).

Specified by:
doneGuard in interface ModelListener
Overrides:
doneGuard in class AbstractListener

doneReset

public void doneReset(java.lang.String reason,
                      boolean testing)
Description copied from interface: ModelListener
The Model calls this after each reset(boolean) action.

Specified by:
doneReset in interface ModelListener
Overrides:
doneReset in class AbstractListener
Parameters:
reason - An adjective that describe why the reset was done.
testing - The parameter that was passed to the FsmModel reset call.

startAction

public void startAction(java.lang.Object state,
                        int action,
                        java.lang.String name)
Description copied from interface: ModelListener
This is called just before an action is about to be executed. (The guard of that action is known to be true at this point).

Specified by:
startAction in interface ModelListener
Overrides:
startAction in class AbstractListener
Parameters:
state - The current state of the model.
action - The number of the action.
name - The name of the action.

doneTransition

public void doneTransition(int action,
                           Transition tr)
Delegates to getMetric().doneTransition(...), and records the resulting coverage.

Specified by:
doneTransition in interface ModelListener
Overrides:
doneTransition in class AbstractListener
Parameters:
action - The number of the action just taken.
tr - The transition just taken.

failure

public void failure(TestFailureException ex)
Description copied from interface: ModelListener
The Model calls this when an action has found an error. The failure exception contains lots of information about the test failure. If a listener throws this exception, then the test generation process will stop with this exception. (after all listeners have been notified of the failure).

Specified by:
failure in interface ModelListener
Overrides:
failure in class AbstractListener


Copyright © 2009 ModelJUnit Project. All Rights Reserved.