Amy Gill преди 6 години
родител
ревизия
05596b328b
променени са 3 файла, в които са добавени 53 реда и са изтрити 42 реда
  1. 5
    0
      src/main/java/Stack.java
  2. 7
    1
      src/main/java/StackArray/GenericStack.java
  3. 41
    41
      src/test/java/StackArray/GenericStackTest.java

+ 5
- 0
src/main/java/Stack.java Целия файл

@@ -0,0 +1,5 @@
1
+public class Stack{
2
+    public boolean isEmpty(){
3
+        return false;
4
+    }
5
+}

+ 7
- 1
src/main/java/StackArray/GenericStack.java Целия файл

@@ -1,15 +1,21 @@
1 1
 package StackArray;
2 2
 
3 3
 import java.util.Arrays;
4
+import java.util.Stack;
4 5
 
5 6
 /**
6 7
  * Expand the ArrayList implementation of stack here to use an E[] array.  Still implement push, pop, and isEmpty.
7 8
  * Remember, you might need to resize the stack in the push method.
8 9
  * @param <E>
9 10
  */
10
-public class GenericStack<E> {
11
+public class GenericStack<E> extends Stack<E> {
11 12
     private E[] elements;
12 13
 
13 14
     public GenericStack() {
14 15
     }
16
+
17
+    @Override
18
+    public synchronized boolean isEmpty() {
19
+        return super.isEmpty();
20
+    }
15 21
 }

+ 41
- 41
src/test/java/StackArray/GenericStackTest.java Целия файл

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