A Test Suite III

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]

ArrayedStackTester.java
public void testStorage(int size, int numberOfObjects) {
   ArrayedStack stack = new ArrayedStack(size);
   String stackdesc = "for a stack of size " + size;
   String[] expectedObjects = new String[numberOfObjects];

   // create the required number of objects and store
   // them onto the stack
   for (int i = 0; i < numberOfObjects; ++i) {
      expectedObjects[i] = "Object #" + i;
      stack.push(expectedObjects[i]);
      protocol.compare("empty() " + stackdesc,
         stack.empty(), false);
      protocol.compare("full() " + stackdesc,
         stack.full(), size == i + 1);
   }

   // retrieve all stored objects from the stack
   for (int i = numberOfObjects - 1; i >= 0; --i) {
      String returnedObject = (String) stack.pop();
      protocol.compare("pop() " + stackdesc,
         returnedObject, expectedObjects[i]);
   }

   // test the (now) empty stack
   protocol.compare("empty() " + stackdesc,
      stack.empty(), true);
   protocol.compare("full() " + stackdesc,
      stack.full(), false);
}

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]
Copyright © 2001, 2002 Andreas Borchert, converted to HTML on February 11, 2002