@Test public void testMin() { Stack<Integer> s1 = new Stack<>(); s1.push(4); s1.push(2); s1.push(7); s1.push(12); assertEquals(2, (int) s1.min()); }
@Test public void testCorrectOrder() { Stack stack = new Stack(); stack.push("first"); stack.push("second"); stack.push("third"); assertThat(stack.pop(), is("third")); assertThat(stack.pop(), is("second")); assertThat(stack.pop(), is("first")); }
@Test public void testPush() { // Stack stack = new Stack(5); Integer i = 0; stack.push(i); assertFalse("Stack size = 1", stack.isEmpty()); Stack<Double> stackDouble = new Stack<Double>(); Double f = 0.1; stackDouble.push(f); assertFalse("Stack size = 1", stackDouble.isEmpty()); }
@Test public void testSort() { Stack<Integer> s1 = new Stack<>(); s1.push(3); s1.push(1); s1.push(5); s1.push(2); s1.push(8); s1.push(2); assertEquals("|315282", s1.toString()); Stack.sort(s1); assertEquals("|853221", s1.toString()); }
@Test public void testPushPop() { // Stack stack = new Stack(5); stack.push(0); stack.pop(); assertTrue("Stack is empty", stack.isEmpty()); }
@Test public void PushNull() { // Stack stack = new Stack(2); Integer i = null; stack.push(i); assertFalse("Stack size = 1", stack.isEmpty()); }
@Test public void testTop1() { // Stack stack = new Stack(2); int value = 460; stack.push(value); int top = stack.top(); assertEquals("Stack value is ok", value, top); }
@SuppressWarnings("unused") @Test public void testTopWithIsEmpty() { // Stack stack = new Stack(2); stack.push(0); int top = stack.top(); assertFalse("Stack size = 1", stack.isEmpty()); }
@Test public void testPushPop() { String expected = "Test"; Stack<String> testStack = new Stack<String>(); testStack.push(expected); String actual = testStack.pop(); assertEquals(expected, actual); }
@Test public void testPushPop1Object() { // Stack stack = new Stack(1); int test = 155; stack.push(test); int pop = stack.pop(); assertEquals("Stack value is the same", test, pop); }
/** Test of isEmpty method, of class Stack. Stack is not empty. */ @Test public void testIsEmpty2() { System.out.println("isEmpty2"); Stack instance = new Stack(1); instance.push(1); boolean expResult = false; boolean result = instance.isEmpty(); assertEquals(expResult, result); }
/** Test of push and pop method, of class Stack. */ @Test public void testPop() { System.out.println("pop"); Stack instance = new Stack(1); instance.push(1); int expResult = 1; int result = instance.pop(); assertEquals(expResult, result); }
@Test public void testTopN() { // Stack stack = new Stack(10); int values[] = {460, 6, 9, 8, 7, 41, 3, 67, 5}; for (int i = 0; i < values.length; i++) { stack.push(values[i]); } int top = stack.top(); assertEquals("Top value is ok", values[values.length - 1], top); }
@Test public void testNTop() { // Stack stack = new Stack(2); int value = 460; int top = 0; stack.push(value); for (int i = 0; i < 10; i++) { top = stack.top(); } assertEquals("Top value is the same", value, top); }
@Test public void testPushPopNTime() { // Stack stack = new Stack(3); int value[] = {15641, 99877, 3269710}; int popValue = 0; for (int i = 0; i < 3; i++) { stack.push(value[i]); popValue = stack.pop(); } assertEquals("Stack value is the same", value[2], popValue); }
@Test public void testEmpty() { Stack<String> testStack = new Stack<String>(); assertTrue(testStack.isEmpty()); String test = "Test"; testStack.push(test); assertFalse(testStack.isEmpty()); testStack.pop(); assertTrue(testStack.isEmpty()); }
@Test public void testLiFo() { String test1 = "Test1"; String test2 = "Test2"; Stack<String> testStack = new Stack<String>(); testStack.push(test1); testStack.push(test2); String actual1 = testStack.pop(); String actual2 = testStack.pop(); assertEquals(test2, actual1); assertEquals(test1, actual2); }
@Test public void testBasicFeatures() { Stack stack = new Stack(); assertTrue(stack.isEmpty()); stack.push("first"); assertFalse(stack.isEmpty()); String peek = stack.peek(); assertThat(peek, is("first")); assertFalse(stack.isEmpty()); String pop = stack.pop(); assertThat(pop, is("first")); assertTrue(stack.isEmpty()); }
@Test public void testTowersOfHanoi() { Stack<Integer> src = new Stack<>(); Stack<Integer> temp = new Stack<>(); Stack<Integer> dest = new Stack<>(); for (int i = 5; i > 0; i--) { src.push(i); } System.out.println(src.toString()); System.out.println(temp.toString()); System.out.println(dest.toString()); System.out.println(); Stack.towersOfHanoi(5, src, temp, dest); System.out.println(src.toString()); System.out.println(temp.toString()); System.out.println(dest.toString()); System.out.println(); assertEquals("|54321", dest.toString()); }
@Test(expected = NullPointerException.class) public void shouldThrowExceptionOnNullInput() { Stack stack = new Stack(); stack.push(null); }