|
4 | 4 |
|
5 | 5 | import com.galvanize.Stack;
|
6 | 6 |
|
7 |
| -public class StackTestCase { |
| 7 | +class StackTestCase { |
8 | 8 |
|
9 | 9 | @Test()
|
10 | 10 | @DisplayName("Stack.push() adds a new object")
|
11 |
| - public void testStackPush() { |
| 11 | + void testStackPush() { |
12 | 12 | Stack newStack = new Stack();
|
13 |
| - assertEquals(0, newStack.count()); |
| 13 | + assertEquals(0, newStack.count(),"Stack should be empty on initialization"); |
14 | 14 | newStack.push(100);
|
15 |
| - assertEquals(1, newStack.count()); |
16 |
| - assertFalse(newStack.empty); |
| 15 | + assertEquals(1, newStack.count(), "Stack should contain only 1 object."); |
| 16 | + assertFalse(newStack.empty, "Stack should not be empty."); |
17 | 17 | }
|
18 | 18 |
|
19 | 19 | @Test
|
20 | 20 | @DisplayName("Stack.pop() removes and returns last item added.")
|
21 |
| - public void testStackPopRemovesAndReturnsLastItemIn() { |
| 21 | + void testStackPopRemovesAndReturnsLastItemIn() { |
22 | 22 | Stack newStack = new Stack();
|
23 | 23 | newStack.push(1);
|
24 | 24 | newStack.push(2);
|
25 | 25 | newStack.push(3);
|
26 |
| - assertEquals(3, newStack.count()); |
| 26 | + assertEquals(3, newStack.count(), "Stack should contain 3 objects."); |
27 | 27 | Object item = newStack.pop();
|
28 |
| - assertEquals(2, newStack.count()); |
29 |
| - assertEquals(3, item); |
| 28 | + assertEquals(2, newStack.count(), "Stack should contain only 2 items after .pop()"); |
| 29 | + assertEquals(3, item, "The removed object should have a value of 3"); |
30 | 30 | }
|
31 | 31 |
|
32 | 32 | @Test
|
33 | 33 | @DisplayName("Stack.peek() returns the last item added without removing it.")
|
34 |
| - public void testStackPeek() { |
| 34 | + void testStackPeek() { |
35 | 35 | Stack newStack = new Stack();
|
36 | 36 | newStack.push("sock");
|
37 | 37 | newStack.push("shoe");
|
38 |
| - assertEquals("shoe", newStack.peek()); |
| 38 | + assertEquals("shoe", newStack.peek(), "The last object should be 'shoe'."); |
| 39 | + assertEquals(2, newStack.count(), "The stack size should be unchanged after peek()."); |
39 | 40 | }
|
40 | 41 | }
|
0 commit comments