|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnz.ac.waikato.modeljunit.AbstractListener
nz.ac.waikato.modeljunit.coverage.AbstractCoverage
public abstract class AbstractCoverage
A partial implementation of CoverageMetric.
This maintains the map from Object to Integer,
and calculates the coverage metrics from that.
Note that currCoverage_ is the number of keys
in the coverage_ map that have non-zero values.
(The addItem and
incrementItem
methods maintain this invariant.)
Subclasses must implement the setGraph method so that
it calls addItem for every item in
the FSM graph. After doing this,
it should also set maxCoverage_ to coverage_.size().
Subclasses must also implement doneTransition (and
perhaps doneReset) so that it calls incrementCount(item)
each time a coverage item is covered. Of course, they
must also implement getName() and
getDescription() so that this metric has a
meaningful name and some documentation.
| Field Summary | |
|---|---|
protected java.util.Map<java.lang.Object,java.lang.Integer> |
coverage_
Records the number of times each item has been covered. |
protected int |
currCoverage_
The number of items that have been 'covered'. |
protected int |
maxCoverage_
The maximum number of coverage items. |
| Fields inherited from class nz.ac.waikato.modeljunit.AbstractListener |
|---|
model_ |
| Constructor Summary | |
|---|---|
AbstractCoverage()
This default constructor sets up the coverage_ map,
sets maxCoverage=-1 (meaning unknown), and sets
currCoverage_=0. |
|
| Method Summary | |
|---|---|
protected void |
addItem(java.lang.Object item)
Add a coverage item to the coverage_ map. |
void |
clear()
Reset all coverage data. |
void |
doneReset(java.lang.String reason,
boolean testing)
The Model calls this after each reset(boolean) action. |
int |
getCoverage()
The number of 'items' covered so far. |
java.util.Map<java.lang.Object,java.lang.Integer> |
getDetails()
Details of which items have been covered and how many times. |
int |
getMaximum()
The maximum number of items that can be covered. |
float |
getPercentage()
The current coverage percentage. |
protected void |
incrementItem(java.lang.Object item)
Increments the count of item in the coverage_ map. |
void |
setGraph(InspectableGraph model,
java.util.Map<java.lang.Object,Vertex> state2vertex)
A default implementation that does nothing. |
java.lang.String |
toString()
|
static Transition |
transition(Edge e,
InspectableGraph model)
A convenience method for converting a graph edge into a Transition. |
| Methods inherited from class nz.ac.waikato.modeljunit.AbstractListener |
|---|
doneGuard, doneTransition, failure, getModel, setModel, startAction |
| 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.coverage.CoverageMetric |
|---|
getDescription |
| Methods inherited from interface nz.ac.waikato.modeljunit.ModelListener |
|---|
doneGuard, doneTransition, failure, getModel, getName, setModel, startAction |
| Field Detail |
|---|
protected java.util.Map<java.lang.Object,java.lang.Integer> coverage_
reset,
addItem and
incrementItem,
because they preserve the invariant that currCoverage_
is the number of non-zero entries in the coverage_ map.
protected int maxCoverage_
coverage_ map.
protected int currCoverage_
coverage_.
| Constructor Detail |
|---|
public AbstractCoverage()
coverage_ map,
sets maxCoverage=-1 (meaning unknown), and sets
currCoverage_=0.
| Method Detail |
|---|
public void clear()
The default implementation iterates through the coverage_ map and resets all counts to zero, and also resets currCoverage_ to zero, to maintain the invariant.
clear in interface CoverageMetricprotected void addItem(java.lang.Object item)
coverage_ map.
If the item is already in the map, its value is left
unchanged. If the item is new, its value is set to zero.
item - The object that is to be added to the coverage_ map.protected void incrementItem(java.lang.Object item)
item in the coverage_ map.
This should be called by doneTransition
(and perhaps doneReset) whenever a coverage item is covered.
If item was not already in the map, then it is added to the map
and its value is set to one.
item - The object that has just been 'covered'.public int getCoverage()
CoverageMetric
getCoverage in interface CoverageMetricpublic int getMaximum()
getMaximum in interface CoverageMetricpublic float getPercentage()
CoverageMetric
getPercentage in interface CoverageMetricpublic java.util.Map<java.lang.Object,java.lang.Integer> getDetails()
CoverageMetricThe type of objects in the domain of the result map will depend upon the kind of coverage (Action, Transition, TransitionPair etc.). However, all of them should provide a useful toString() method, so that you can print coverage results. A typical use of this method is to iterate through the result map and print all the objects that map to zero, because they have not been covered.
getDetails in interface CoverageMetricpublic java.lang.String toString()
toString in class java.lang.Object
public static Transition transition(Edge e,
InspectableGraph model)
public void doneReset(java.lang.String reason,
boolean testing)
The default implementation does nothing.
doneReset in interface ModelListenerdoneReset in class AbstractListenerreason - An adjective that describe why the reset was done.testing - The parameter that was passed to the FsmModel reset call.
public void setGraph(InspectableGraph model,
java.util.Map<java.lang.Object,Vertex> state2vertex)
setGraph in interface CoverageMetric
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||