|
@@ -1,39 +1,39 @@
|
1
|
|
-//package StackArray;
|
2
|
|
-//
|
3
|
|
-//import org.junit.Assert;
|
4
|
|
-//import org.junit.Test;
|
5
|
|
-//
|
6
|
|
-//public class ObjectStackTest {
|
7
|
|
-// @Test
|
8
|
|
-// public void testPushingGrowsTheStack() throws Exception {
|
9
|
|
-// // Given an empty stack
|
10
|
|
-// ObjectStack<String> stack = new ObjectStack<>();
|
11
|
|
-// // Assert that it is empty.
|
12
|
|
-// Assert.assertEquals(true, stack.isEmpty());
|
13
|
|
-// // When we push something onto the stack
|
14
|
|
-// stack.push("foobar");
|
15
|
|
-// // Then it shouldn't be empty
|
16
|
|
-// Assert.assertEquals(false, stack.isEmpty());
|
17
|
|
-// }
|
18
|
|
-//
|
19
|
|
-// @Test
|
20
|
|
-// public void testPushingAndPoppingOrder() throws Exception {
|
21
|
|
-// // Given an empty stack
|
22
|
|
-// ObjectStack<String> stack = new ObjectStack<>();
|
23
|
|
-// // When we push two elements on it
|
24
|
|
-// stack.push("foo");
|
25
|
|
-// stack.push("bar");
|
26
|
|
-// // Then we should see them returned in the correct order
|
27
|
|
-// Assert.assertEquals("bar", stack.pop());
|
28
|
|
-// Assert.assertEquals("foo", stack.pop());
|
29
|
|
-// }
|
30
|
|
-//
|
31
|
|
-// @Test(expected = IndexOutOfBoundsException.class)
|
32
|
|
-// public void testPopFirst() throws Exception {
|
33
|
|
-// // Given an empty stack
|
34
|
|
-// ObjectStack<String> stack = new ObjectStack<>();
|
35
|
|
-// // When it's popped
|
36
|
|
-// stack.pop();
|
37
|
|
-// // Then we should get an exception
|
38
|
|
-// }
|
39
|
|
-//}
|
|
1
|
+package StackArray;
|
|
2
|
+
|
|
3
|
+import org.junit.Assert;
|
|
4
|
+import org.junit.Test;
|
|
5
|
+
|
|
6
|
+public class ObjectStackTest {
|
|
7
|
+ @Test
|
|
8
|
+ public void testPushingGrowsTheStack() throws Exception {
|
|
9
|
+ // Given an empty stack
|
|
10
|
+ ObjectStack<String> stack = new ObjectStack<>();
|
|
11
|
+ // Assert that it is empty.
|
|
12
|
+ Assert.assertEquals(true, stack.isEmpty());
|
|
13
|
+ // When we push something onto the stack
|
|
14
|
+ stack.push("foobar");
|
|
15
|
+ // Then it shouldn't be empty
|
|
16
|
+ Assert.assertEquals(false, stack.isEmpty());
|
|
17
|
+ }
|
|
18
|
+
|
|
19
|
+ @Test
|
|
20
|
+ public void testPushingAndPoppingOrder() throws Exception {
|
|
21
|
+ // Given an empty stack
|
|
22
|
+ ObjectStack<String> stack = new ObjectStack<>();
|
|
23
|
+ // When we push two elements on it
|
|
24
|
+ stack.push("foo");
|
|
25
|
+ stack.push("bar");
|
|
26
|
+ // Then we should see them returned in the correct order
|
|
27
|
+ Assert.assertEquals("bar", stack.pop());
|
|
28
|
+ Assert.assertEquals("foo", stack.pop());
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+ @Test(expected = IndexOutOfBoundsException.class)
|
|
32
|
+ public void testPopFirst() throws Exception {
|
|
33
|
+ // Given an empty stack
|
|
34
|
+ ObjectStack<String> stack = new ObjectStack<>();
|
|
35
|
+ // When it's popped
|
|
36
|
+ stack.pop();
|
|
37
|
+ // Then we should get an exception
|
|
38
|
+ }
|
|
39
|
+}
|