sofya.tools.th
Class TestHistory

java.lang.Object
  extended by sofya.tools.th.TestHistory

public class TestHistory
extends java.lang.Object

A TestHistory encapsulates test history information for a traced method.

This class is modeled loosely upon the dbh_th_info struct found in the Aristotle system, with appropriate affordances for object-oriented design. Test history information is stored per block in bit vectors, which are allocated on a need basis to reduce the memory footprint. The usual methods for accessing and building test history information for the method are provided. The TestHistoryHandler coordinates the management of test histories for every method in a class.

Once constructed, the number of method blocks in a test history cannot be changed. The number of tests associated with a block can grow as needed, however.

Version:
07/21/2005
Author:
Alex Kinneer
See Also:
TestHistoryBuilder, TestHistoryHandler, TestHistoryViewer, ProgramEventDispatcher

Constructor Summary
TestHistory(int highestBlockID, int highestTestID)
          Default constructor, creates a test history with the specified number of method blocks and an initial number of tests.
 
Method Summary
 void clear()
          Clears the test history for every method block.
 java.lang.Object clone()
          Creates a deep clone of this test history object.
 boolean equals(java.lang.Object obj)
          Tests whether this test history object is equal to another test history.
 int getHighestBlockID()
          Gets the highest block ID present in the method.
 int getHighestTestID()
          Gets the current highest test number.
 boolean isEmpty(int blockID)
          Reports whether the history for a block is empty, that is, no tests traversed that block.
 boolean isHistoryEmpty()
          Reports whether the entire test history is empty, that is, no tests traversed any blocks in the method.
 boolean query(int blockID, int testID)
          Queries whether a block is exercised by a given test.
 void set(int blockID, int testID)
          Marks that a block is exercised by a given test.
 TestHistory union(TestHistory th)
          Creates a test history that is the union of this test history and another test history.
 void unset(int blockID, int testID)
          Marks that a block is not exercised by a given test.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestHistory

public TestHistory(int highestBlockID,
                   int highestTestID)
Default constructor, creates a test history with the specified number of method blocks and an initial number of tests.

Parameters:
highestBlockID - Highest possible block number in the method, cannot be changed after instantiation.
highestTestID - Initial number of tests to be associated with the test history.
Method Detail

getHighestBlockID

public int getHighestBlockID()
Gets the highest block ID present in the method.

Returns:
The highest ID of any block found in the method.

getHighestTestID

public int getHighestTestID()
Gets the current highest test number.

Returns:
The highest test number associated with this test history.

isHistoryEmpty

public boolean isHistoryEmpty()
Reports whether the entire test history is empty, that is, no tests traversed any blocks in the method.

Returns:
true if no tests hit any block in the method, false otherwise.

isEmpty

public boolean isEmpty(int blockID)
Reports whether the history for a block is empty, that is, no tests traversed that block.

Parameters:
blockID - ID of the block to be checked.
Returns:
true if no tests hit the specified block in the method, false otherwise.

set

public void set(int blockID,
                int testID)
Marks that a block is exercised by a given test.

Parameters:
blockID - ID of the block for which a new test is being added.
testID - Number of the new test that exercised the block.

query

public boolean query(int blockID,
                     int testID)
Queries whether a block is exercised by a given test.

Parameters:
blockID - ID of the method block to be queried.
testID - Number of the test for which is it is being checked whether it exercises the given block.
Returns:
true if the test exercises the given block, false otherwise.

unset

public void unset(int blockID,
                  int testID)
Marks that a block is not exercised by a given test.

Parameters:
blockID - ID of the block for which a test is being removed.
testID - Number of the test that no longer exercises the block.

clear

public void clear()
Clears the test history for every method block.


clone

public java.lang.Object clone()
Creates a deep clone of this test history object.

This method is the object-oriented Java analogue to the Aristotle dbh_th_copy procedure.

Overrides:
clone in class java.lang.Object
Returns:
A new test history object with the same number of method blocks and the same test histories associated with each block.

equals

public boolean equals(java.lang.Object obj)
Tests whether this test history object is equal to another test history.

This method first compares the number of method blocks and highest test ID in this test history to that of the specified object. If both are equal, it then performs a block-by-block comparison of the test history bit vectors. The test histories are considered equal if and only if every test history bit vector is equivalent.

This method is the object-oriented Java analogue to the Aristotle dbh_th_equal procedure.

Overrides:
equals in class java.lang.Object
Parameters:
obj - Test history to which this test history should be compared for equality.
Returns:
true if the specified test history is equal to this test history, false otherwise.

union

public TestHistory union(TestHistory th)
Creates a test history that is the union of this test history and another test history.

The specified test history must have the same number of method blocks as this test history. The method will then take the logical union of every test history bit vector in the two test histories. In the event of a mismatch in the size of the bit vectors, the resultant bit vector will always be the size of the larger vector. The resulting test history will be an entirely new object, neither the current test history or the specified test history will be modified by this method.

This method is the object-oriented Java analogue to the Aristotle dbh_th_union procedure.

Parameters:
th - Test history for which the union should be taken with this test history.
Returns:
An entirely new test history object, representing the union of this test history and the specified test history.