Last active
December 6, 2021 13:53
Revisions
-
mtov revised this gist
Jul 28, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ public void push(T elem) { public T pop() throws EmptyStackException { if (isEmpty()) throw new EmptyStackException(); T elem = elements.remove(size-1); size--; return elem; } -
mtov renamed this gist
Nov 14, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
mtov revised this gist
Nov 14, 2019 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,6 @@ public class StackTest { public void init() { stack = new Stack<Integer>(); } @Test public void testEmptyStack() { -
mtov created this gist
Nov 14, 2019 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ import java.util.ArrayList; import java.util.EmptyStackException; public class Stack<T> { private ArrayList<T> elements = new ArrayList<T>(); private int size = 0; public int size() { return size; } public boolean isEmpty(){ return (size == 0); } public void push(T elem) { elements.add(elem); size++; } public T pop() throws EmptyStackException { if (isEmpty()) throw new EmptyStackException(); T elem = elements.get(size-1); size--; return elem; } } This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ import org.junit.Test; import org.junit.Before; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertEquals; public class StackTest { Stack<Integer> stack; @Before public void init() { stack = new Stack<Integer>(); } @Test public void testEmptyStack() { assertTrue(stack.isEmpty()); } @Test public void testNotEmptyStack() { stack.push(10); assertFalse(stack.isEmpty()); } @Test public void testSizeStack() { stack.push(10); stack.push(20); stack.push(30); int size = stack.size(); assertEquals(3,size); } @Test public void testPushPopStack() { stack.push(10); stack.push(20); stack.push(30); int result = stack.pop(); result = stack.pop(); assertEquals(20,result); } @Test(expected = java.util.EmptyStackException.class) public void testEmptyStackException() { stack.push(10); int result = stack.pop(); result = stack.pop(); } }