StackTest.java
class StackTest {
static public void main(String[] args) {
ListStack stack = new ListStack();
//Empty stack should say its empty
Tester.test(stack.notEmpty(), false);
//Test to make sure pop from empty stack returns null
Tester.test(stack.pop(), null);
stack.push("one");
//Stack should say its not empty now
Tester.test(stack.notEmpty(), true);
stack.push("two");
stack.push("three");
Tester.test(stack.pop(),"three");
Tester.test(stack.pop(),"two");
//Test to see if stack accept different kinds of objects
stack.push(new Integer(100000));
Tester.test((Integer)stack.pop(), new Integer(100000));
//Empty the stack and make sure it acts empty
drain(stack);
stack.pop();
Tester.test(stack.notEmpty(), false);
Tester.test(stack.pop(), null);
//See if we can push lots of things onto stack
for (int i=0; i<1000; i++) {
stack.push(new Integer(i));
}
Tester.test((Integer)stack.pop(),new Integer(999));
//pop off all but final value
for (int i=998; i>=0; i--) {
Tester.test((Integer) stack.pop(), new Integer(i));
}
//Should be empty again
Tester.test(stack.notEmpty(), false);
Tester.printResults();
}
static void drain(ListStack s) {
while (s.notEmpty()) {
s.pop();
}
}
}
Generated by GNU enscript 1.6.3.