01: /*
02: * <copyright>
03: *
04: * Copyright 1997-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.util;
28:
29: import java.util.ArrayList;
30: import java.util.List;
31:
32: import junit.framework.TestCase;
33:
34: public class TestCircularQueue extends TestCase {
35: public void test_toString0() {
36: assertEquals(new CircularQueue<Object>(2).toString(),
37: "{CircularQueue 0/2}");
38: }
39:
40: public void test_toString1() {
41: CircularQueue<Integer> q = new CircularQueue<Integer>(2);
42: q.add(1);
43: q.add(2);
44: q.add(3);
45: q.add(4);
46: // 8 because the queue algorithm needs an extra slot
47: assertEquals("{CircularQueue 4/8}", q.toString());
48: }
49:
50: public void test_add_next0() {
51: CircularQueue<Integer> q = new CircularQueue<Integer>(2);
52: q.add(1);
53: q.add(2);
54: q.add(3);
55: q.add(4);
56: assertEquals(q.next().intValue(), 1);
57: assertEquals(q.next().intValue(), 2);
58: assertEquals(q.next().intValue(), 3);
59: assertEquals(q.next().intValue(), 4);
60: assertEquals(q.next(), null);
61: }
62:
63: public void test_fillList() {
64: CircularQueue<Integer> q = new CircularQueue<Integer>(2);
65: q.add(1);
66: q.add(2);
67: List<Integer> l = new ArrayList<Integer>();
68: l.addAll(q);
69: assertTrue(l.size() == 2);
70: assertEquals(1, l.get(0).intValue());
71: assertEquals(2, l.get(1).intValue());
72: }
73:
74: public void test_toArray1() {
75: CircularQueue<Integer> q = new CircularQueue<Integer>(2);
76: q.add(1);
77: q.add(2);
78: Object[] l = q.toArray();
79: assertTrue(l.length == 2);
80: assertEquals(1, l[0]);
81: assertEquals(2, l[1]);
82: }
83:
84: public void test_toArray2() {
85: CircularQueue<Integer> q = new CircularQueue<Integer>(2);
86: q.add(1);
87: q.add(2);
88: Integer[] l = q.toArray(new Integer[2]);
89: assertTrue(l.length == 2);
90: assertEquals(1, l[0].intValue());
91: assertEquals(2, l[1].intValue());
92: }
93: }
|