| Home >> All >> javatools >> util >> [ test Javadoc ] |
Source code: javatools/util/test/TestQueue.java
1 /* 2 Javatools (modified version) - Some useful general classes. 3 Copyright (C) 2002 Chris Bitmead (original) Antonio Petrelli (modified) 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 Contact me at: brenmcguire@users.sourceforge.net 20 */ 21 package javatools.util.test; 22 import java.util.*; 23 import javatools.util.JQueue; 24 25 public class TestQueue { 26 JQueue q; 27 28 public static void main(String argv[]) { 29 TestQueue t = new TestQueue(); 30 try { 31 t.q = new JQueue(1); 32 t.test(); 33 34 t.q = new JQueue(2); 35 t.test(); 36 37 t.q = new JQueue(10); 38 t.test(); 39 40 t.q = new JQueue(100); 41 t.test(); 42 43 t.q = new JQueue(10000); 44 t.test(); 45 46 System.out.println("SUCCESS"); 47 } catch (TestFailedException e) { 48 System.out.println("FAIL"); 49 } 50 } 51 52 void test() throws TestFailedException { 53 q.put("one"); 54 q.put("two"); 55 q.put("three"); 56 if (!((String) q.get()).equals("one")) { 57 throw new TestFailedException("1"); 58 } 59 if (!((String) q.get()).equals("two")) { 60 throw new TestFailedException("2"); 61 } 62 q.put("four"); 63 q.put("five"); 64 q.put("six"); 65 if (!((String) q.get()).equals("three")) { 66 throw new TestFailedException("3"); 67 } 68 if (!((String) q.get()).equals("four")) { 69 throw new TestFailedException("4"); 70 } 71 if (!((String) q.get()).equals("five")) { 72 throw new TestFailedException("5"); 73 } 74 if (!((String) q.get()).equals("six")) { 75 throw new TestFailedException("6"); 76 } 77 try { 78 q.get(); 79 throw new TestFailedException("5"); 80 } catch (NoSuchElementException e) { 81 // ok 82 } 83 q.put("one"); 84 q.put("two"); 85 q.put("three"); 86 q.put("four"); 87 q.put("five"); 88 q.put("six"); 89 if (!((String) q.get()).equals("one")) { 90 throw new TestFailedException("1.1"); 91 } 92 if (!((String) q.get()).equals("two")) { 93 throw new TestFailedException("1.2"); 94 } 95 if (!((String) q.get()).equals("three")) { 96 throw new TestFailedException("1.3"); 97 } 98 if (!((String) q.get()).equals("four")) { 99 throw new TestFailedException("1.4"); 100 } 101 if (!((String) q.get()).equals("five")) { 102 throw new TestFailedException("1.5"); 103 } 104 if (!((String) q.get()).equals("six")) { 105 throw new TestFailedException("1.6"); 106 } 107 try { 108 q.get(); 109 throw new TestFailedException("1.7"); 110 } catch (NoSuchElementException e) { 111 // ok 112 } 113 } 114 115 class TestFailedException extends Exception { 116 TestFailedException(String desc) { 117 super(desc); 118 } 119 } 120 }