示例#1
0
 @Test
 public void testPushPop() {
   // Stack stack = new Stack(5);
   stack.push(0);
   stack.pop();
   assertTrue("Stack is empty", stack.isEmpty());
 }
示例#2
0
 @Test
 public void PushNull() {
   // Stack stack = new Stack(2);
   Integer i = null;
   stack.push(i);
   assertFalse("Stack size = 1", stack.isEmpty());
 }
示例#3
0
 /** Test of isEmpty method, of class Stack. Stack is empty. */
 @Test
 public void testIsEmpty() {
   System.out.println("isEmpty");
   Stack instance = new Stack(1);
   boolean expResult = true;
   boolean result = instance.isEmpty();
   assertEquals(expResult, result);
 }
示例#4
0
 @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);
 }
示例#5
0
 @SuppressWarnings("unused")
 @Test
 public void testTopWithIsEmpty() {
   // Stack stack = new Stack(2);
   stack.push(0);
   int top = stack.top();
   assertFalse("Stack size = 1", stack.isEmpty());
 }
示例#6
0
 @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);
 }
示例#7
0
 @Test
 public void testPushPop() {
   String expected = "Test";
   Stack<String> testStack = new Stack<String>();
   testStack.push(expected);
   String actual = testStack.pop();
   assertEquals(expected, actual);
 }
示例#8
0
 /** 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 testMin() {
   Stack<Integer> s1 = new Stack<>();
   s1.push(4);
   s1.push(2);
   s1.push(7);
   s1.push(12);
   assertEquals(2, (int) s1.min());
 }
示例#10
0
 @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);
 }
示例#11
0
 @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);
 }
示例#12
0
  @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());
  }
示例#13
0
  @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);
  }
示例#14
0
  @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);
  }
示例#15
0
 @SuppressWarnings("unused")
 @Test(expected = NoSuchElementException.class)
 public void testTopEmptyStack() {
   // tack stack = new Stack(2);
   Integer top = stack.top();
   fail("Top on empty stack");
 }
示例#16
0
 @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());
 }
示例#17
0
  @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());
  }
示例#18
0
  @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"));
  }
示例#19
0
  @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());
  }
示例#20
0
 @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());
 }
示例#21
0
 @Test
 public void shouldReturnNullOnEmptyPeak() throws Exception {
   Stack stack = new Stack();
   String peek = stack.peek();
   assertThat(peek, is(nullValue()));
 }
示例#22
0
 @Test(expected = NullPointerException.class)
 public void shouldThrowExceptionOnNullInput() {
   Stack stack = new Stack();
   stack.push(null);
 }
示例#23
0
 @Test(expected = NoSuchElementException.class)
 public void testPopEmptyStack() {
   // Stack stack = new Stack(2);
   stack.pop();
   fail("pop empty stack");
 }
示例#24
0
 @Test(expected = StackUnderflowException.class)
 public void testUnderflowException() {
   Stack<String> testStack = new Stack<String>();
   testStack.pop();
 }
示例#25
0
 @Test
 public void testIsEmpty() {
   // Stack stack = new Stack(5);
   boolean empty = stack.isEmpty();
   assertTrue("Stack is empty", empty);
 }