Exemplo n.º 1
0
 @Test
 public void testPushPop() {
   // Stack stack = new Stack(5);
   stack.push(0);
   stack.pop();
   assertTrue("Stack is empty", stack.isEmpty());
 }
Exemplo n.º 2
0
 @Test
 public void PushNull() {
   // Stack stack = new Stack(2);
   Integer i = null;
   stack.push(i);
   assertFalse("Stack size = 1", stack.isEmpty());
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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());
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 9
0
 @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());
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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());
  }
Exemplo n.º 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);
  }
Exemplo n.º 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);
  }
Exemplo n.º 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");
 }
Exemplo n.º 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());
 }
Exemplo n.º 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());
  }
Exemplo n.º 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"));
  }
Exemplo n.º 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());
  }
Exemplo n.º 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());
 }
Exemplo n.º 21
0
 @Test
 public void shouldReturnNullOnEmptyPeak() throws Exception {
   Stack stack = new Stack();
   String peek = stack.peek();
   assertThat(peek, is(nullValue()));
 }
Exemplo n.º 22
0
 @Test(expected = NullPointerException.class)
 public void shouldThrowExceptionOnNullInput() {
   Stack stack = new Stack();
   stack.push(null);
 }
Exemplo n.º 23
0
 @Test(expected = NoSuchElementException.class)
 public void testPopEmptyStack() {
   // Stack stack = new Stack(2);
   stack.pop();
   fail("pop empty stack");
 }
Exemplo n.º 24
0
 @Test(expected = StackUnderflowException.class)
 public void testUnderflowException() {
   Stack<String> testStack = new Stack<String>();
   testStack.pop();
 }
Exemplo n.º 25
0
 @Test
 public void testIsEmpty() {
   // Stack stack = new Stack(5);
   boolean empty = stack.isEmpty();
   assertTrue("Stack is empty", empty);
 }