Amy Gill пре 6 година
родитељ
комит
05596b328b

+ 5
- 0
src/main/java/Stack.java Прегледај датотеку

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

+ 7
- 1
src/main/java/StackArray/GenericStack.java Прегледај датотеку

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