laser.alphabet.test
Class IndexedAlphabetTest

java.lang.Object
  extended by laser.alphabet.test.IndexedAlphabetTest

public class IndexedAlphabetTest
extends java.lang.Object

The IndexedAlphabetTest class provides testing for the IndexedLabel, IndexedAlphabetFactory, and IndexedAlphabet classes.

Author:
Nathan A. Jokel (laser-software@cs.umass.edu)

Field Summary
static IndexedAlphabetFactory factory
          An IndexedAlphabetFactory to use with the tests.
static java.lang.String PERSISTENCE_FILENAME
          The filename used to test persistence for IndexedAlphabet.
static java.lang.String TEST
          A test String to use for some of the tests.
static int TEST_INDEX
          A test index used in some of the tests (must be less than TEST_MAX_INDEX and greater than 0).
static int TEST_MAX_INDEX
          A test value of maxIndex used in some of the tests.
static int TEST_REPOSITORY_CAPACITY
          The number of Labels to create when testing the capacity of the repository (must be less than TEST_MAX_INDEX)
static java.lang.String TEST2
          A test String to use for some of the tests.
static java.lang.String VISUALIZE_STRING_FILENAME
          The filename used to test the IndexedAlphabet.visualize(String) method.
static java.lang.String VISUALIZE_WRITER_FILENAME
          The filename used to test the IndexedAlphabet.visualize(Writer) method.
 
Constructor Summary
IndexedAlphabetTest()
           
 
Method Summary
static void main(java.lang.String[] args)
          Performs the tests.
static void testIndexedAlphabetAdd()
          Tests the IndexedAlphabet.add() method.
static void testIndexedAlphabetAddAll()
          Tests the IndexedAlphabet.addAll() method.
static void testIndexedAlphabetClear()
          Tests the IndexedAlphabet.clear() method.
static void testIndexedAlphabetClone()
          Tests the IndexedAlphabet.clone() method.
static void testIndexedAlphabetContains()
          Tests the IndexedAlphabet.contains() method.
static void testIndexedAlphabetContainsAll()
          Tests the IndexedAlphabet.containsAll() method.
static void testIndexedAlphabetCreateAlphabetInterface()
          Tests the IndexedAlphabet.createAlphabetInterface() method.
static void testIndexedAlphabetCreateLabelInterface()
          Tests the IndexedAlphabet.createLabelInterface() method.
static void testIndexedAlphabetEquals()
          Tests the IndexedAlphabet.equals() method.
static void testIndexedAlphabetFactoryCreateAlphabetInterface()
          Tests the IndexedAlphabetFactory.createAlphabetInterface() method.
static void testIndexedAlphabetFactoryCreateLabelInterface()
          Tests the IndexedAlphabetFactory.createLabelInterface() method.
static void testIndexedAlphabetFactoryGetLargestIndex()
          Tests the IndexedAlphabetFactory.getLargestIndex() method.
static void testIndexedAlphabetFactoryIsValidLabel()
          Tests the IndexedAlphabetFactory.isValidLabel() method.
static void testIndexedAlphabetFactoryUnmodifiableAlphabet()
          Tests the IndexedAlphabetFactory.unmodifiableAlphabet() method.
static void testIndexedAlphabetGetMaxIndex()
          Tests the IndexedAlphabet.getMaxIndex() method.
static void testIndexedAlphabetGetVisExtension()
          Tests the IndexedAlphabet.getVisExtension() method.
static void testIndexedAlphabetHashCode()
          Tests the IndexedAlphabet.hashCode() method.
static void testIndexedAlphabetIsEmpty()
          Tests the IndexedAlphabet.isEmpty() method.
static void testIndexedAlphabetIsValidLabel()
          Tests the IndexedAlphabet.isValidLabel() method.
static void testIndexedAlphabetIterator()
          Tests the IndexedAlphabet.iterator() method.
static void testIndexedAlphabetPersistent()
          Tests the IndexedAlphabet.readPersistent() and IndexedAlphabet.writePersistent() methods.
static void testIndexedAlphabetRemove()
          Tests the IndexedAlphabet.remove() method.
static void testIndexedAlphabetRemoveAll()
          Tests the IndexedAlphabet.removeAll() method.
static void testIndexedAlphabetRetainAll()
          Tests the IndexedAlphabet.retainAll() method.
static void testIndexedAlphabetSize()
          Tests the IndexedAlphabet.size() method.
static void testIndexedAlphabetSortedIterator()
          Tests the IndexedAlphabet.sortedIterator() method.
static void testIndexedAlphabetToArray()
          Tests the IndexedAlphabet.toArray() method.
static void testIndexedAlphabetToString()
          Tests the IndexedAlphabet.toString() method.
static void testIndexedAlphabetUnmodifiableAlphabet()
          Tests the IndexedAlphabet.unmodifiableAlphabet() method.
static void testIndexedAlphabetVisualize()
          Tests the IndexedAlphabet.visualize() method.
static void testIndexedLabelClone()
          Tests the IndexedLabel.clone() method.
static void testIndexedLabelCompareTo()
          Tests the IndexedLabel.compareTo() method.
static void testIndexedLabelEquals()
          Tests the IndexedLabel.equals() method.
static void testIndexedLabelHashCode()
          Tests the IndexedLabel.hashCode() method.
static void testIndexedLabelToString()
          Tests the IndexedLabel.toString() method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TEST

public static final java.lang.String TEST
A test String to use for some of the tests.

See Also:
Constant Field Values

TEST2

public static final java.lang.String TEST2
A test String to use for some of the tests.

See Also:
Constant Field Values

TEST_INDEX

public static final int TEST_INDEX
A test index used in some of the tests (must be less than TEST_MAX_INDEX and greater than 0).

See Also:
Constant Field Values

TEST_MAX_INDEX

public static final int TEST_MAX_INDEX
A test value of maxIndex used in some of the tests. (must be > 2)

See Also:
Constant Field Values

TEST_REPOSITORY_CAPACITY

public static final int TEST_REPOSITORY_CAPACITY
The number of Labels to create when testing the capacity of the repository (must be less than TEST_MAX_INDEX)

See Also:
Constant Field Values

VISUALIZE_STRING_FILENAME

public static final java.lang.String VISUALIZE_STRING_FILENAME
The filename used to test the IndexedAlphabet.visualize(String) method. This should be different from the other filenames used.

See Also:
Constant Field Values

VISUALIZE_WRITER_FILENAME

public static final java.lang.String VISUALIZE_WRITER_FILENAME
The filename used to test the IndexedAlphabet.visualize(Writer) method. This should be different from the other filenames used.

See Also:
Constant Field Values

PERSISTENCE_FILENAME

public static final java.lang.String PERSISTENCE_FILENAME
The filename used to test persistence for IndexedAlphabet. This should be different from the other filenames used. This file is deleted after the test is complete.

See Also:
Constant Field Values

factory

public static IndexedAlphabetFactory factory
An IndexedAlphabetFactory to use with the tests.

Constructor Detail

IndexedAlphabetTest

public IndexedAlphabetTest()
Method Detail

testIndexedAlphabetFactoryCreateLabelInterface

public static void testIndexedAlphabetFactoryCreateLabelInterface()
Tests the IndexedAlphabetFactory.createLabelInterface() method. The equivalence classes for input parameters are 1) a null String 2) a String that does not represent an integer, 3) a String that represents an integer < 0, 4) a String that represents an integer >= 0, 5) a null Integer, 6) an Integer < 0, 7) an Integer >= 0, 8) an int < 0, 9) an int >= 0, 10) and an integer more than 1 > the index of the current largest IndexedLabel. We also want to ensure that flyweighting is working properly, thus executing this method twice with the same input should return two references to the same object. Also, create a number of distinct labels to make sure the repository does not become full.

This test relies on the fact that the IndexedAlphabetFactory.getLargestIndex() method works properly.

Note if this test fails, it invalidates the results of subsequent tests, therefore the test program will exit.


testIndexedAlphabetFactoryCreateAlphabetInterface

public static void testIndexedAlphabetFactoryCreateAlphabetInterface()
Tests the IndexedAlphabetFactory.createAlphabetInterface() method. The equivalence classes for the input are 1) null input, 2) a single non-Integer/int parameter, 3) more than one parameter, 4) a single Integer <= 0, 5) a single Integer > 0, 6) a single int <= 0, 7) a single int > 0, and 8) no parameters.

This test relies on the fact that the IndexedAlphabet.contains() and IndexedAlphabetFactory.createLabelInterface() methods work properly.

Note if this test fails, it invalidates the results of subsequent tests, therefore the test program will exit.


testIndexedAlphabetFactoryGetLargestIndex

public static void testIndexedAlphabetFactoryGetLargestIndex()
Tests the IndexedAlphabetFactory.getLargestIndex() method. Try an empty repository, then after creating each IndexedLabel with indices up to TEST_MAX_INDEX.

This method relies on the fact that the IndexedAlphabetFactory.createLabelInterface() method works properly.

Note if this test fails, it invalidates the results of subsequent tests, therefore the test program will exit.


testIndexedAlphabetFactoryIsValidLabel

public static void testIndexedAlphabetFactoryIsValidLabel()
Tests the IndexedAlphabetFactory.isValidLabel() method. Try null input, a String not representing an integer, a String representing an integer < 0, and a String representing an integer >= 0.


testIndexedAlphabetFactoryUnmodifiableAlphabet

public static void testIndexedAlphabetFactoryUnmodifiableAlphabet()
Tests the IndexedAlphabetFactory.unmodifiableAlphabet() method. Try null input and AlphabetInterface<IndexedLabel> input.

This test relies on the fact that the IndexedAlphabetFactory.createAlphabetInterface(), IndexedAlphabetFactory.createLabelInterface(), IndexedAlphabet.add(), IndexedAlphabet.clear(), and IndexedAlphabet.getMaxIndex() methods work properly.


testIndexedLabelCompareTo

public static void testIndexedLabelCompareTo()
Tests the IndexedLabel.compareTo() method. The equivalence classes for input parameters are 1) null input, 2) IndexedLabels that preceed the label whose compareTo method is being called 3) IndexedLabels that equal in ordering to the IndexedLabel whose compareTo method is being called (which, due to flyweighting should be only the label itself) and 4) IndexedLabels that follow the label whose compareTo method is being called.


testIndexedLabelHashCode

public static void testIndexedLabelHashCode()
Tests the IndexedLabel.hashCode() method. Make sure the IndexedLabel returns the same hash value as the String it represents.


testIndexedLabelToString

public static void testIndexedLabelToString()
Tests the IndexedLabel.toString() method. Make sure the IndexedLabel returns the String it represents.


testIndexedLabelClone

public static void testIndexedLabelClone()
Tests the IndexedLabel.clone() method. Make sure the returned object is a reference to the same object.


testIndexedLabelEquals

public static void testIndexedLabelEquals()
Tests the IndexedLabel.equals() method. Test with both equal and unequal input.


testIndexedAlphabetClone

public static void testIndexedAlphabetClone()
Tests the IndexedAlphabet.clone() method. This relies on the fact that the add and equals methods work. Make sure that the returned value is not simply a reference to the object being cloned.


testIndexedAlphabetCreateLabelInterface

public static void testIndexedAlphabetCreateLabelInterface()
Tests the IndexedAlphabet.createLabelInterface() method. The equivalence classes for input parameters are 1) a null String 2) a String that does not represent an integer, 3) a String that represents an integer < 0, 4) a String that represents an integer >= 0 and < N, 5) a String that represents an integer >= N 6) a null Integer, 7) an Integer < 0, 8) an Integer >= 0 and < N, 9) an Integer >= N, 10) an int < 0, 11) an int >= 0 and < N, and 12) an int >= N. We also want to ensure that flyweighting is working properly, thus executing this method twice with the same input should return two references to the same object. Also, create a number of distinct labels to make sure the repository does not become full.

Note if this test fails, it invalidates the results of subsequent tests, therefore the test program will exit.


testIndexedAlphabetCreateAlphabetInterface

public static void testIndexedAlphabetCreateAlphabetInterface()
Tests the IndexedAlphabet.createAlphabetInterface() method. The equivalence classes for the input are 1) null input, 2) a single non-Integer/int parameter, 3) more than one parameter, 4) a single Integer <= 0, 5) a single Integer > 0, 6) a single int <= 0, 7) a single int > 0, and 8) no parameters.

This test relies on the fact that the contains method works properly.

Note if this test fails, it invalidates the results of subsequent tests, therefore the test program will exit.


testIndexedAlphabetIsValidLabel

public static void testIndexedAlphabetIsValidLabel()
Tests the IndexedAlphabet.isValidLabel() method. Try null input, a String not representing an integer, a String representing an integer < 0, a String representing an integer >= 0 and < N, and a String representing an integer >= N.


testIndexedAlphabetUnmodifiableAlphabet

public static void testIndexedAlphabetUnmodifiableAlphabet()
Tests the IndexedAlphabet.unmodifiableAlphabet() method. Try null input and AlphabetInterface<IndexedLabel> input.

This test relies on the fact that the IndexedAlphabetFactory.createAlphabetInterface(), IndexedAlphabetFactory.createLabelInterface(), IndexedAlphabet.add(), IndexedAlphabet.clear(), and IndexedAlphabet.getMaxIndex() methods work properly.


testIndexedAlphabetEquals

public static void testIndexedAlphabetEquals()
Tests the IndexedAlphabet.equals() method. The equivalence classes for the input are 1) null input, 2) objects that are not IndexedAlphabets, 3) IndexedAlphabets with some different element labels, 4) IndexedAlphabets that contain exactly the same element labels, and 5) IndexedAlphabets with different values for N that contain the same element labels.

Note that this test uses the add and clear methods and must assume they work correctly. Also, if this test fails, it invalidates the results of other tests thus the test program will exit.


testIndexedAlphabetGetMaxIndex

public static void testIndexedAlphabetGetMaxIndex()
Tests the IndexedAlphabet.getMaxIndex() method.


testIndexedAlphabetAdd

public static void testIndexedAlphabetAdd()
Tests the IndexedAlphabet.add() method. This test relies on the fact that the contains and remove methods work properly. The equivalence classes for the input are 1) null input, 2) an IndexedLabel not contained in the alphabet already outside of 0 to (N - 1), 3) an IndexedLabel not contained in the alphabet already within 0 to (N - 1), 4) a IndexedLabel already contained in the alphabet, and 5) non-IndexedLabel input.

If this test fails, it invalidates the results of other tests thus the test program will exit.


testIndexedAlphabetAddAll

public static void testIndexedAlphabetAddAll()
Tests the IndexedAlphabet.addAll() method. This test relies on the fact that the containsAll and remove methods work. The equivalence classes for the input are 1) null input, 2) a Collection containing null elements, 3) a Collection containing an IndexedLabel with an index outside of the range 0 to (N - 1), 4) a Collection containing IndexedLabels that are not contained in the alphabet already that fall in the range 0 to (N - 1), 5) a Collection containing some IndexedLabels that are contained in the alphabet already and some that are not so contained, all of which fall in the range 0 to (N - 1), 6) a Collection containing only IndexedLabels that are contained in the alphabet already, and 7) a Collection that contains a non-IndexedLabel.


testIndexedAlphabetClear

public static void testIndexedAlphabetClear()
Tests the IndexedAlphabet.clear() method. This test relies on the fact that the add and isEmpty methods work properly.

Note that the failure of this test invalidates the results of other tests, thus the test program will exit if this test fails.


testIndexedAlphabetContains

public static void testIndexedAlphabetContains()
Tests the IndexedAlphabet.contains() method. The equivalence classes for the input are 1) null input, 2) non-IndexedLabel input, 3) an IndexedLabel not contained in the alphabet, and 4) a IndexedLabel contained in the alphabet. If this test fails, it invalidates the results of other tests thus the test program will exit.


testIndexedAlphabetContainsAll

public static void testIndexedAlphabetContainsAll()
Tests the IndexedAlphabet.containsAll() method. The equivalence classes for the input are 1) null input, 2) a Collection containing a null element, 3) input that is a Collection not of IndexedLabels, 4) a Collection containing no IndexedLabels that are contained in the alphabet, 5) a Collection containing some IndexedLabels that are contained in the alphabet and some that are not so contained, and 6) a Collection containing only IndexedLabels that are contained in the alphabet.

If this test fails, it invalidates the results of other tests thus the test program will exit.


testIndexedAlphabetGetVisExtension

public static void testIndexedAlphabetGetVisExtension()
Tests the IndexedAlphabet.getVisExtension() method.


testIndexedAlphabetHashCode

public static void testIndexedAlphabetHashCode()
Tests the IndexedAlphabet.hashCode() method. This should return the sum of the hash values of all contained labels. This test relies on the fact that the add method works properly.


testIndexedAlphabetIsEmpty

public static void testIndexedAlphabetIsEmpty()
Tests the IndexedAlphabet.isEmpty() method. This test relies on the fact that the add and clear methods work properly. The input is 1) a newly created IndexedAlphabet, 2) a IndexedAlphabet which has been cleared, and 3) a IndexedAlphabet which has been cleared and then has had a label added.

If this test fails, it invalidates the results of other tests thus the test program will exit.


testIndexedAlphabetIterator

public static void testIndexedAlphabetIterator()
Tests the IndexedAlphabet.iterator() method. This test relies on the fact that the add method works properly.


testIndexedAlphabetSortedIterator

public static void testIndexedAlphabetSortedIterator()
Tests the IndexedAlphabet.sortedIterator() method. This test relies on the fact that the add method works properly. Makes sure the elements are returned in the correct order.


testIndexedAlphabetRemove

public static void testIndexedAlphabetRemove()
Tests the IndexedAlphabet.remove() method. This test relies on the face that the contains and method works. The equivalence classes for the input are 1) null input, 2) non-IndexedLabel input, 3) an IndexedLabel not contained in the alphabet, and 4) an IndexedLabel contained in the alphabet.


testIndexedAlphabetRemoveAll

public static void testIndexedAlphabetRemoveAll()
Tests the IndexedAlphabet.removeAll() method. This test relies on the fact that the add and contains methods work properly. The equivalence classes for input are 1) null input, 2) a Collection containing a null element, 3) a Collection not containing IndexedLabels, 4) a Collection containing no labels contained in this alphabet, 5) a Collection containing only labels contained in this alphabet, and 6) a Collection containing some labels contained in this alphabet, and some labels not so contained.


testIndexedAlphabetRetainAll

public static void testIndexedAlphabetRetainAll()
Tests the IndexedAlphabet.retainAll() method. This test relies on the fact that the add, contains, and isEmpty methods work properly. The equivalence classes for input are 1) null input, 2) a Collection containing a null element, 3) a Collection not containing IndexedLabels, 4) a Collection containing no labels contained in this alphabet, 5) a Collection containing only labels contained in this alphabet, and 6) a Collection containing some labels contained in this alphabet, and some labels not so contained.


testIndexedAlphabetSize

public static void testIndexedAlphabetSize()
Tests the IndexedAlphabet.size() method. This test relies on the fact that the add, remove, and clear methods work properly. The equivalence classes for input are 1) a newly created alphabet, 2) an empty alphabet which was cleared, 3) an empty alphabet to which a label was added, 4) an alphabet with labels to which a label was added, and 5) an alphabet with labels from which a label was removed.


testIndexedAlphabetToArray

public static void testIndexedAlphabetToArray()
Tests the IndexedAlphabet.toArray() method. First the method is tested with no parameters. The equivalence classes for testing are an empty alphabet and a non-empty alphabet.

Then the method is tested with an array of AbstractLabel as a parameter. The equivalence classes for the input are 1) null input, 2) an array not of type AbstractLabel, 3) an array of AbstractLabel that is larger than the number of labels in the alphabet, 4) an array of AbstractLabel that is smaller than the number of labels in the alphabet. 5) an array of IndexedLabel that is larger than the number of labels in the alphabet, and 5) an array of IndexedLabel that is smaller than the number of labels in the alphabet.


testIndexedAlphabetToString

public static void testIndexedAlphabetToString()
Tests the IndexedAlphabet.toString() method. This test relies on the fact that the clear method works properly. Tests both an empty alphabet and one with labels.


testIndexedAlphabetVisualize

public static void testIndexedAlphabetVisualize()
Tests the IndexedAlphabet.visualize() method. Since there is no easy way to verify that the correct output is written to the visual file, it is left to the tester to check this. Two files are written, one using a String filename as input, and another using a Writer as input.


testIndexedAlphabetPersistent

public static void testIndexedAlphabetPersistent()
Tests the IndexedAlphabet.readPersistent() and IndexedAlphabet.writePersistent() methods. This test relies on the fact that the add and equals methods work properly. Note that the only way to verify that the writePersistent and readPersistent methods are working is to use both together, thus if a failure occurs, it is unclear whether it is the readPersistent or writePersistent method that caused the failure. Both methods are tested with both stream and String filename input.


main

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

Parameters:
args - Input parameters (should be none).