Пример #1
0
 /**
  * Check that a newly created stack isn't full, and doesn't become full when we push several
  * things on it. In fact _no_ stack in this implementation should ever be full.
  *
  * <p>Note that this is a <em>classic</em> example of how testing can never <em>prove</em> that
  * code is correct. No matter how many items we push on this stack, we can never be sure that it
  * we just pushed <em>one</em> more on we could cause full to return true.
  */
 @Ignore
 @Test
 public void testIsFull() {
   final StackIF<Integer> stack = makeIntegerStack();
   assertFalse("Stacks should never be full", stack.isFull());
   for (int i = 0; i < 100; ++i) {
     stack.push(i);
     assertFalse("Stacks should never be full", stack.isFull());
   }
 }
Пример #2
0
 /** A simple test to show that top() is working correctly when items are being pushed/popped */
 @Ignore
 @Test
 public void testPushPopTop() {
   final StackIF<String> stack = makeStringStack();
   stack.push(values[2]);
   assertEquals("The top item of the stack should be 'Three'", stack.top(), "Three");
   stack.push(values[2]);
   stack.push(values[0]);
   stack.pop();
   assertEquals("The top item of the stack should be 'Three'", stack.top(), "Three");
   stack.pop();
   stack.push(values[1]);
   stack.push(values[1]);
   stack.pop();
   assertEquals("The top item of the stack should be 'Two'", stack.top(), "Two");
 }
Пример #3
0
 /** Tests that isEmpty() is working correctly when items are being pushed/popped. */
 @Ignore
 @Test
 public void testEmptyMethod() {
   final StackIF<Integer> stack = makeIntegerStack();
   assertTrue("Stack should be empty", stack.isEmpty());
   stack.push(1);
   stack.push(2);
   assertFalse("Stack should not be empty", stack.isEmpty());
   stack.pop();
   stack.pop();
   assertTrue("Stack should be empty", stack.isEmpty());
 }
Пример #4
0
 /** Tests that calling top on an empty stack throws a StackUnderflowException. */
 @Ignore
 @Test(expected = StackUnderflowException.class)
 public void topOnEmptyThrowsException() {
   final StackIF<Integer> stack = makeIntegerStack();
   stack.top();
 }
Пример #5
0
 /** Tests that a stack is empty when it's initially created. */
 @Ignore
 @Test
 public void isNewStackEmpty() {
   final StackIF<Integer> stack = makeIntegerStack();
   assertEquals("Empty stack should have size 0", 0, stack.size());
 }
Пример #6
0
 /** Simple test to show that size() is working correctly as items are being pushed/popped. */
 @Ignore
 @Test
 public void testPushPopSize() {
   final StackIF<String> stack = makeStringStack();
   stack.push(values[0]);
   stack.push(values[1]);
   stack.push(values[1]);
   assertEquals("Stack should have a size of 3", stack.size(), 3);
   stack.pop();
   stack.push(values[2]);
   stack.push(values[1]);
   stack.push(values[0]);
   assertEquals("Stack should have a size of 5", stack.size(), 5);
   stack.pop();
   stack.pop();
   stack.pop();
   stack.pop();
   stack.pop();
   assertEquals("Stack should be empty", stack.size(), 0);
 }