/** Test method for clear. */ @Test public void testClear() { my_stack.clear(); // test if size decremented back to 0 assertTrue("clear() failed to decrement size", my_stack.size() == 0); // test if top decremented back to -1 assertTrue("clear() failed to decrement top", my_stack.size() - 1 == -1); }
/** Test method for Pop. */ @Test public void testPop() { pushElements(); final String return_value = my_stack.pop(); // test if the right element is returned; popped element should be "World" assertTrue("pop() returned the wrong element!", "World".equals(return_value)); // test size was decremented; size should be 1 assertTrue("pop() didn't decrement size correctly!", my_stack.size() == 1); // test top was decremented; top should be 0 assertTrue("pop() didn't decrement top correctly!", my_stack.size() - 1 == 0); }
/** Test method for Size. */ @Test public void testSize() { pushElements(); // test if size is correct; size should be 2 assertTrue("size() returned the wrong size!", my_stack.size() == 2); }
/** Test method for Push. */ @Test public void testPush() { pushElements(); // test size was incremented correctly after two pushes; size should be 2 assertTrue("push() failed to increment size", my_stack.size() == 2); // test top was incremented correctly after two pushes; top should be 1 assertTrue("push() failed to increment top", my_stack.size() - 1 == 1); final String return_value1 = my_stack.pop(); // test if top element is in correct position; element should be "World" assertTrue("push() failed to put element in correctly!", "World".equals(return_value1)); final String return_value2 = my_stack.pop(); // test if the last element is in correct position; element should be "Hello" assertTrue("push() failed to put element in correctly!", "Hello".equals(return_value2)); }
/** Test method for Generic Simple Array Stack. */ @Test public void testGenericSimpleArrayStack() { assertTrue("New Stack should be empty. Size should equal 0", my_stack.size() == 0); }