JavaAlgorithms
Elementary and no so elementary Java algorithms
listAlgorithms/TestStack.java
Go to the documentation of this file.
00001 
00009 package listAlgorithms;
00010 
00011 import static org.junit.Assert.*;
00012 
00013 import org.junit.Test;
00014 
00015 public class TestStack {
00016 
00017     @Test
00018     public void test() {
00019         Character vals[] = new Character[] { 'A', 'B', 'C', 'D', 'E' };
00020         Stack<Character> charStack = new Stack<Character>();
00021         for (Character ch : vals) {
00022             charStack.push(ch);
00023         }
00024         boolean OK = true;
00025         int ix = vals.length - 1;
00026         while (charStack.peek() != null) {
00027             Character ch = charStack.pop();
00028             if (!ch.equals(vals[ix])) {
00029                 OK = false;
00030                 break;
00031             }
00032             ix--;
00033         } // while
00034         assertTrue("Queue failed", OK);
00035     } // test
00036 
00037 }
 All Classes Namespaces Files Functions Variables