コード例 #1
0
 @Test
 public void testIsEmpty() {
   MyStack<Integer> test = new MyStack<Integer>();
   test.push(2);
   test.push(230);
   test.pop();
   test.pop();
   assertTrue(test.isEmpty());
 }
コード例 #2
0
  @Test
  public void testPeek() {
    MyStack<Integer> testStack = new MyStack<Integer>();

    testStack.push(23);
    assertTrue(testStack.peek() == 23);
    // Ensure the next pushed item is on top
    testStack.push(2);
    assertTrue(testStack.peek() == 2);
  }
コード例 #3
0
  @Test
  public void testPush() {
    MyStack<Integer> testStack = new MyStack<Integer>();
    testStack.push(23);
    testStack.push(43);
    testStack.push(21);

    // Ensure the correct size after doing a number of pushes
    assertFalse(testStack.isEmpty());
    assertTrue(testStack.size() == 3);
  }
コード例 #4
0
  @Test
  public void testPop() {
    MyStack<String> testStack = new MyStack<String>();
    testStack.push("hello");
    testStack.push("dog");
    testStack.push("cat");

    assertEquals("cat", testStack.pop());
    assertTrue(testStack.size() == 2);
    // Ensure the popped object is gone
    assertEquals("dog", testStack.peek());
  }
コード例 #5
0
  @Test
  public void testClear() {
    MyStack<Integer> testStack = new MyStack<Integer>();
    testStack.push(23);
    testStack.push(2039);
    testStack.push(220);

    assertTrue(testStack.size() == 3);
    // Ensure quality of the clear method.
    testStack.clear();
    assertTrue(testStack.size() == 0);
    assertTrue(testStack.isEmpty());
  }
コード例 #6
0
  @Test
  public void canPushAndPeekTag() {
    MyStack testStack = new MyStack();
    HtmlTag testTag = new HtmlTag("b");

    testStack.push(testTag);
    assertEquals(testStack.peek().getElement(), testTag.getElement());
  }
コード例 #7
0
 // Testing Stack
 @Test
 public void testStack() {
   MyStack<Integer> testStack = new MyStack<Integer>();
   testStack.push(5);
   testStack.push(2);
   testStack.push(3);
   assertEquals(3, testStack.size());
   assertEquals(3, testStack.peek(), 0);
   testStack.pop();
   assertEquals(2, testStack.size());
   assertEquals(2, testStack.peek(), 0);
   testStack.pop();
   assertEquals(1, testStack.size());
   assertEquals(5, testStack.peek(), 0);
   testStack.pop();
   assertEquals(0, testStack.size());
 }
コード例 #8
0
  @Test
  public void canPushAndPopTag() {
    MyStack testStack = new MyStack();
    HtmlTag testTag = new HtmlTag("html");

    testStack.push(testTag);
    assertEquals(testStack.pop().getElement(), testTag.getElement());
    assertTrue(testStack.isEmpty());
  }
コード例 #9
0
  @Test
  public void pushShouldAddToEmptyStack() {
    MyStack testStack = new MyStack();
    HtmlTag testTag = new HtmlTag("html");

    assertTrue(testStack.isEmpty());
    testStack.push(testTag);
    assertFalse(testStack.isEmpty());
  }