Merge commit '42b2e5ca519766e37ce6941ba4faecc9691cc403' into upstream
[debian/openrocket] / core / test / net / sf / openrocket / util / SimpleStackTest.java
diff --git a/core/test/net/sf/openrocket/util/SimpleStackTest.java b/core/test/net/sf/openrocket/util/SimpleStackTest.java
new file mode 100644 (file)
index 0000000..16cd312
--- /dev/null
@@ -0,0 +1,43 @@
+package net.sf.openrocket.util;
+
+import java.util.NoSuchElementException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
+public class SimpleStackTest {
+
+       @Test(expected=NoSuchElementException.class)
+       public void testEmptyStack() {
+               SimpleStack<Integer> s = new SimpleStack<Integer>();
+               
+               assertNull(s.peek());
+               
+               s.pop();
+       }
+       
+       @Test
+       public void testPushAndPop() {
+               
+               SimpleStack<Integer> s = new SimpleStack<Integer>();
+               
+               for( int i = 0; i< 10; i++ ) {
+                       s.push(i);
+                       assertEquals(i+1, s.size());
+               }
+       
+               for( int i=9; i>= 0; i-- ) {
+                       assertEquals( i, s.peek().intValue() );
+                       Integer val = s.pop();
+                       assertEquals( i, val.intValue() );
+                       assertEquals( i, s.size() );
+               }
+               
+               assertNull( s.peek() );
+               assertEquals( 0, s.size() );
+               
+       }
+       
+}