X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=core%2Ftest%2Fnet%2Fsf%2Fopenrocket%2Futil%2FSimpleStackTest.java;fp=core%2Ftest%2Fnet%2Fsf%2Fopenrocket%2Futil%2FSimpleStackTest.java;h=16cd312bed1de27305cec98bbf749a42c655ddfa;hb=9349577cdfdff682b2aabd6daa24fdc3a7449b58;hp=0000000000000000000000000000000000000000;hpb=30ba0a882f0c061176ba14dbf86d3d6fad096c02;p=debian%2Fopenrocket diff --git a/core/test/net/sf/openrocket/util/SimpleStackTest.java b/core/test/net/sf/openrocket/util/SimpleStackTest.java new file mode 100644 index 00000000..16cd312b --- /dev/null +++ b/core/test/net/sf/openrocket/util/SimpleStackTest.java @@ -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 s = new SimpleStack(); + + assertNull(s.peek()); + + s.pop(); + } + + @Test + public void testPushAndPop() { + + SimpleStack s = new SimpleStack(); + + 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() ); + + } + +}