package com.github.davidmoten.util;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class ImmutableStackTest {

    private final Object a = new Object();
    private final Object b = new Object();
    
    @Test
    public void testNewStackIsEmpty() {
        ImmutableStack<Object> s = ImmutableStack.empty();
        assertTrue(s.isEmpty());
    }

    @Test(expected = RuntimeException.class)
    public void testPopOnEmptyStackThrowsException() {
        ImmutableStack.empty().pop();
    }

    @Test(expected = RuntimeException.class)
    public void testPeekOnEmptyStackThrowsException() {
        ImmutableStack.empty().peek();
    }

    @Test
    public void testStackIsEmptyAfterPushThenPop() {
        assertTrue(ImmutableStack.empty().push(new Object()).pop().isEmpty());
    }

    @Test
    public void testPeekGivesLastPushed() {
        assertEquals(b,ImmutableStack.empty().push(a).push(b).peek());
    }

    @Test
    public void testPopPeekGivesSecondLastPushed() {
        assertEquals(a,ImmutableStack.empty().push(a).push(b).pop().peek());
    }
    
}

@@ -112,20 +112,92 @@
 t.assert
-True
+False;%0Aimport static org.junit.Assert.assertTrue;%0A%0Aimport java.util.Iterator
 ;%0A%0Aimpor
@@ -1214,10 +1214,851 @@
  %7D%0A    %0A
+    @Test%0A    public void testIteratorWhenEmpty() %7B%0A        assertFalse(ImmutableStack.empty().iterator().hasNext());%0A    %7D%0A    %0A    @Test%0A    public void testIteratorWhenHasOneItem() %7B%0A        assertTrue(ImmutableStack.empty().push(a).iterator().hasNext());%0A    %7D%0A    %0A    @Test%0A    public void testIteratorReturnsOneItem() %7B%0A        assertEquals(a, ImmutableStack.empty().push(a).iterator().next());%0A    %7D%0A    %0A    @Test%0A    public void testIteratorReturnsLastPushedFirst() %7B%0A        assertEquals(b, ImmutableStack.empty().push(a).push(b).iterator().next());%0A    %7D%0A    %0A    @Test%0A    public void testIteratorReturnsTwoItemsInOrderOfPop() %7B%0A        Iterator%3CObject%3E it = ImmutableStack.empty().push(a).push(b).iterator();%0A        assertEquals(b, it.next());%0A        assertEquals(a, it.next());%0A        assertFalse(it.hasNext());%0A    %7D%0A    %0A
 %7D%0A

add test for ImmutableStack