laser.alphabet.test
Class StringAlphabetTest

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

public class StringAlphabetTest
extends java.lang.Object

The StringAlphabetTest class provides testing for the StringLabel, StringAlphabetFactory, and StringAlphabet classes.

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

Field Summary
static StringAlphabetFactory factory
          A StringAlphabetFactory to use with the tests.
static java.lang.String PERSISTENCE_FILENAME
          The filename used to test persistence for StringAlphabet.
static java.lang.String TEST
          A test String to use for some of the tests.
static int TEST_REPOSITORY_CAPACITY
          The number of Labels to create when testing the capacity of the repository.
static java.lang.String VISUALIZE_STRING_FILENAME
          The filename used to test the StringAlphabet.visualize(String) method.
static java.lang.String VISUALIZE_WRITER_FILENAME
          The filename used to test the StringAlphabet.visualize(Writer) method.
 
Constructor Summary
StringAlphabetTest()
           
 
Method Summary
static void main(java.lang.String[] args)
          Performs the tests.
static void testStringAlphabetAdd()
          Tests the StringAlphabet.add() method.
static void testStringAlphabetAddAll()
          Tests the StringAlphabet.addAll() method.
static void testStringAlphabetClear()
          Tests the StringAlphabet.clear() method.
static void testStringAlphabetClone()
          Tests the StringAlphabet.clone() method.
static void testStringAlphabetContains()
          Tests the StringAlphabet.contains() method.
static void testStringAlphabetContainsAll()
          Tests the StringAlphabet.containsAll() method.
static void testStringAlphabetCreateAlphabetInterface()
          Tests the StringAlphabet.createAlphabetInterface() method.
static void testStringAlphabetCreateLabelInterface()
          Tests the StringAlphabet.createLabelInterface() method.
static void testStringAlphabetEquals()
          Tests the StringAlphabet.equals() method.
static void testStringAlphabetFactoryCreateAlphabetInterface()
          Tests the StringAlphabetFactory.createAlphabetInterface() method.
static void testStringAlphabetFactoryCreateLabelInterface()
          Tests the StringAlphabetFactory.createLabelInterface() method.
static void testStringAlphabetFactoryIsValidLabel()
          Tests the StringAlphabetFactory.isValidLabel() method.
static void testStringAlphabetFactoryUnmodifiableAlphabet()
          Tests the StringAlphabetFactory.unmodifiableAlphabet() method.
static void testStringAlphabetGetVisExtension()
          Tests the StringAlphabet.getVisExtension() method.
static void testStringAlphabetHashCode()
          Tests the StringAlphabet.hashCode() method.
static void testStringAlphabetIsEmpty()
          Tests the StringAlphabet.isEmpty() method.
static void testStringAlphabetIsValidLabel()
          Tests the StringAlphabet.isValidLabel() method.
static void testStringAlphabetIterator()
          Tests the StringAlphabet.iterator() method.
static void testStringAlphabetPersistent()
          Tests the StringAlphabet.readPersistent() and StringAlphabet.writePersistent() methods.
static void testStringAlphabetRemove()
          Tests the StringAlphabet.remove() method.
static void testStringAlphabetRemoveAll()
          Tests the StringAlphabet.removeAll() method.
static void testStringAlphabetRetainAll()
          Tests the StringAlphabet.retainAll() method.
static void testStringAlphabetSize()
          Tests the StringAlphabet.size() method.
static void testStringAlphabetSortedIterator()
          Tests the StringAlphabet.sortedIterator() method.
static void testStringAlphabetToArray()
          Tests the StringAlphabet.toArray() method.
static void testStringAlphabetToString()
          Tests the StringAlphabet.toString() method.
static void testStringAlphabetUnmodifiableAlphabet()
          Tests the StringAlphabet.unmodifiableAlphabet() method.
static void testStringAlphabetVisualize()
          Tests the StringAlphabet.visualize() method.
static void testStringLabelClone()
          Tests the StringLabel.clone() method.
static void testStringLabelCompareTo()
          Tests the StringLabel.compareTo() method.
static void testStringLabelEquals()
          Tests the StringLabel.equals() method.
static void testStringLabelHashCode()
          Tests the StringLabel.hashCode() method.
static void testStringLabelToString()
          Tests the StringLabel.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

TEST_REPOSITORY_CAPACITY

public static final int TEST_REPOSITORY_CAPACITY
The number of Labels to create when testing the capacity of the repository.

See Also:
Constant Field Values

VISUALIZE_STRING_FILENAME

public static final java.lang.String VISUALIZE_STRING_FILENAME
The filename used to test the StringAlphabet.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 StringAlphabet.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 StringAlphabet. 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 StringAlphabetFactory factory
A StringAlphabetFactory to use with the tests.

Constructor Detail

StringAlphabetTest

public StringAlphabetTest()
Method Detail

testStringAlphabetFactoryCreateLabelInterface

public static void testStringAlphabetFactoryCreateLabelInterface()
Tests the StringAlphabetFactory.createLabelInterface() method. The two equivalence classes for input parameters are 1) null input and 2) any input String. We also want to ensure that flyweighting is working properly, thus executing this method twice with the same input String 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.


testStringAlphabetFactoryCreateAlphabetInterface

public static void testStringAlphabetFactoryCreateAlphabetInterface()
Tests the StringAlphabetFactory.createAlphabetInterface() method. Try null input and non-null input

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


testStringAlphabetFactoryIsValidLabel

public static void testStringAlphabetFactoryIsValidLabel()
Tests the StringAlphabetFactory.isValidLabel() method. Try null input and non-null input.


testStringAlphabetFactoryUnmodifiableAlphabet

public static void testStringAlphabetFactoryUnmodifiableAlphabet()
Tests the StringAlphabetFactory.unmodifiableAlphabet() method. Try null input and AlphabetInterface<StringLabel> input.

This test relies on the fact that the StringAlphabetFactory.createAlphabetInterface(), StringAlphabetFactory.createLabelInterface(), and Alphabet.add() methods work properly.


testStringLabelCompareTo

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


testStringLabelHashCode

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


testStringLabelToString

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


testStringLabelClone

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


testStringLabelEquals

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


testStringAlphabetClone

public static void testStringAlphabetClone()
Tests the StringAlphabet.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.


testStringAlphabetCreateLabelInterface

public static void testStringAlphabetCreateLabelInterface()
Tests the StringAlphabet.createLabelInterface() method. The two equivalence classes for input parameters are 1) null input and 2) any input String. We also want to ensure that flyweighting is working properly, thus executing this method twice with the same input String 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.


testStringAlphabetCreateAlphabetInterface

public static void testStringAlphabetCreateAlphabetInterface()
Tests the StringAlphabet.createAlphabetInterface() method. Try null input and non-null input

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


testStringAlphabetIsValidLabel

public static void testStringAlphabetIsValidLabel()
Tests the StringAlphabet.isValidLabel() method. Try null input and non-null input.


testStringAlphabetUnmodifiableAlphabet

public static void testStringAlphabetUnmodifiableAlphabet()
Tests the StringAlphabet.unmodifiableAlphabet() method. Try null input and AlphabetInterface<StringLabel> input.

This test relies on the fact that the StringAlphabetFactory.createAlphabetInterface(), StringAlphabetFactory.createLabelInterface(), and Alphabet.add() methods work properly.


testStringAlphabetEquals

public static void testStringAlphabetEquals()
Tests the StringAlphabet.equals() method. The equivalence classes for the input are 1) null input, 2) objects that are not StringAlphabets, 3) StringAlphabets with some different element labels, and 4) StringAlphabets that contain exactly the same element labels.

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


testStringAlphabetAdd

public static void testStringAlphabetAdd()
Tests the StringAlphabet.add() method. This test relies on the fact that the contains method works properly. The equivalence classes for the input are 1) null input, 2) a StringLabel not contained in the alphabet already, 3) a StringLabel already contained in the alphabet, and 4) non-StringLabel input.

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


testStringAlphabetAddAll

public static void testStringAlphabetAddAll()
Tests the StringAlphabet.addAll() method. This test relies on the fact that the containsAll and add methods work. The equivalence classes for the input are 1) null input, 2) a Collection containing null elements, 3) a Collection containing no StringLabels that are contained in the alphabet already, 4) a Collection containing some StringLabels that are contained in the alphabet already and some that are not so contained, and 5) a Collection containing only StringLabels that are contained in the alphabet already, and 6) a Collection containing a non-StringLabel.


testStringAlphabetClear

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


testStringAlphabetContains

public static void testStringAlphabetContains()
Tests the StringAlphabet.contains() method. This test relies on the fact that the add method works. The equivalence classes for the input are 1) null input, 2) non-StringLabel input, 3) a StringLabel not contained in the alphabet, and 4) a StringLabel contained in the alphabet. If this test fails, it invalidates the results of other tests thus the test program will exit.


testStringAlphabetContainsAll

public static void testStringAlphabetContainsAll()
Tests the StringAlphabet.containsAll() method. This test relies on the fact that the add and addAll methods work. The equivalence classes for the input are 1) null input, 2) an input Collection containing a null element, 3) input that is a Collection not of StringLabels, 4) a Collection containing no StringLabels that are contained in the alphabet, 5) a Collection containing some StringLabels that are contained in the alphabet and some that are not so contained, and 6) a Collection containing only StringLabels that are contained in the alphabet.

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


testStringAlphabetGetVisExtension

public static void testStringAlphabetGetVisExtension()
Tests the StringAlphabet.getVisExtension() method.


testStringAlphabetHashCode

public static void testStringAlphabetHashCode()
Tests the StringAlphabet.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.


testStringAlphabetIsEmpty

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

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


testStringAlphabetIterator

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


testStringAlphabetSortedIterator

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


testStringAlphabetRemove

public static void testStringAlphabetRemove()
Tests the StringAlphabet.remove() method. This test relies on the face that the contains and add methods work. The equivalence classes for the input are 1) null input, 2) non-StringLabel input, 3) a StringLabel not contained in the alphabet, and 4) a StringLabel contained in the alphabet.


testStringAlphabetRemoveAll

public static void testStringAlphabetRemoveAll()
Tests the StringAlphabet.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 StringLabels, 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.


testStringAlphabetRetainAll

public static void testStringAlphabetRetainAll()
Tests the StringAlphabet.retainAll() 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 StringLabels, 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.


testStringAlphabetSize

public static void testStringAlphabetSize()
Tests the StringAlphabet.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 to which a label was added, 3) an alphabet with labels to which a label was added, 4) an alphabet with labels from which a label was removed, and 5) a cleared alphabet.


testStringAlphabetToArray

public static void testStringAlphabetToArray()
Tests the StringAlphabet.toArray() method. This test relies on the fact that the add method works properly. 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 StringLabel that is larger than the number of labels in the alphabet, and 5) an array of StringLabel that is smaller than the number of labels in the alphabet.


testStringAlphabetToString

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


testStringAlphabetVisualize

public static void testStringAlphabetVisualize()
Tests the StringAlphabet.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.


testStringAlphabetPersistent

public static void testStringAlphabetPersistent()
Tests the StringAlphabet.readPersistent() and StringAlphabet.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).