/**  * InputSeparator test class.  *  * @author Kurt Mammen, Ben Woskow  * @version Lab 2  * @version CPE102-X (replace the X with your section number)  * @version Winter 2008  */ import static org.junit.Assert.*; import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; public class InputSeparatorTest { /** * Test method for {@link InputSeparator()}. * Here we are testing to ensure that newly-created * InputSeparators have empty contents. */ @Test public void testInputSeparatorConstructor() { // Construct an InputSeparator object InputSeparator separator = new InputSeparator(); // Check to see if all ArrayLists and new (and therefore empty) ArrayLists assertEquals(new ArrayList(), separator.getIntegers()); assertEquals(new ArrayList(), separator.getDoubles()); assertEquals(new ArrayList(), separator.getOthers()); } /** * Test method for {@link InputSeparator#add(String)}. * Here we are testing to ensure that Integer * objects are added properly. */ @Test public void testAddIntegers() { // Create two Integer objects Integer ints[] = { new Integer(5), new Integer(123) }; // Construct an InputSeparator object InputSeparator separator = new InputSeparator(); // Add the objects to the separator for (int i=0; i < ints.length; i++) { separator.add(ints[i].toString()); } // Get the Integer ArrayList ArrayList arrayListInts = separator.getIntegers(); // Check to see if the Integer contents equal their expected values for (int i=0; i < ints.length; i++) { assertEquals(ints[i], arrayListInts.get(i)); } // Check to see that the Integer contents are of the expected length assertEquals(ints.length, arrayListInts.size()); } /** * Test method for {@link InputSeparator#add(String)}. * Here we are testing in more concise manner to ensure that Integer * objects are added properly. */ @Test public void testAddIntegers2() { // Create two Integer objects Integer ints[] = { new Integer(5), new Integer(123) }; // Construct an InputSeparator object InputSeparator separator = new InputSeparator(); // Add the objects to the separator for (int i=0; i < ints.length; i++) { separator.add(ints[i].toString()); } // Get the Integer ArrayList ArrayList arrayListInts = separator.getIntegers(); // Check to see if the Integer contents equal their expected values assertEquals(arrayListInts, Arrays.asList(ints)); } /** * Test method for {@link InputSeparator#add(String)}. * Here we are testing to ensure that Double * objects are added properly. */ @Test public void testAddDoubles() { // Create two Double objects Double doubles[] = { new Double(3.14), new Double(123.321) }; // Construct an InputSeparator object InputSeparator separator = new InputSeparator(); // Add the objects to the separator for (int i=0; i < doubles.length; i++) { separator.add(doubles[i].toString()); } // Get the Double ArrayList ArrayList arrayListDoubles = separator.getDoubles(); // Check to see if the Integer contents equal their expected values assertEquals(arrayListDoubles, Arrays.asList(doubles)); } /** * Test method for {@link InputSeparator#add(String)}. * Here we are testing to ensure that random text * is added properly. */ @Test public void testAddOthers() { // Create two String objects String others[] = { "random", "text" }; // Construct an InputSeparator object InputSeparator separator = new InputSeparator(); // Add the objects to the separator for (int i=0; i < others.length; i++) { separator.add(others[i]); } // Get the Other ArrayList ArrayList arrayListOthers = separator.getOthers(); // Check to see if the Other contents equal their expected values assertEquals(arrayListOthers, Arrays.asList(others)); } /** * Test method for {@link InputSeparator#add(String)}. * Here we are testing to ensure that all objects * are added properly, even when mixed. */ @Test public void testAddAll() { // Create multiple objects of each type Integer integers[] = /* fill this in */; Double doubles[] = /* fill this in */; String others[] = /* fill this in */; // Merge the three arrays into one String all[] = new String[integers.length + doubles.length + others.length]; int allCnt = 0; for (int i=0; i < integers.length; i++) { all[allCnt] = integers[i].toString(); allCnt++; } for (int i=0; i < doubles.length; i++) { all[allCnt] = doubles[i].toString(); allCnt++; } for (int i=0; i < others.length; i++) { all[allCnt] = others[i]; allCnt++; } // Construct an InputSeparator object /* fill this in */ // Add the objects to the separator /* fill this in */ // Get the three ArrayLists /* fill this in */ // Check to see if the Integer contents equal their expected values /* fill this in */ // Check to see if the Double contents equal their expected values /* fill this in */ // Check to see if the Other contents equal their expected values /* fill this in */ } /** * Test method for {@link InputSeparator(ArrayList)}. * Here we are testing to ensure that newly-created * InputSeparators have expected contents. */ @Test public void testInputSeparatorConstructor2() { /* fill this in */ } }