001: // $Id: BoundedListTest.java,v 1.2 2005/06/08 11:24:17 belaban Exp $
002:
003: package org.jgroups.tests;
004:
005: import junit.framework.TestCase;
006: import org.jgroups.util.BoundedList;
007:
008: public class BoundedListTest extends TestCase {
009: private BoundedList l = null;
010:
011: public BoundedListTest(String name) {
012: super (name);
013: }
014:
015: public void setUp() throws Exception {
016: super .setUp();
017: l = new BoundedList(3);
018: }
019:
020: public void tearDown() throws Exception {
021: super .tearDown();
022: l.removeAll();
023: l = null;
024: }
025:
026: public void testAdd() throws Exception {
027: assertEquals(l.size(), 0);
028: l.add(new Integer(1));
029: System.out.println(l);
030: assertEquals(l.size(), 1);
031:
032: l.add(new Integer(2));
033: System.out.println(l);
034:
035: l.add(new Integer(3));
036: System.out.println(l);
037: assertEquals(l.size(), 3);
038:
039: l.add(new Integer(4));
040: System.out.println(l);
041: assertEquals(l.size(), 3);
042:
043: int tmp;
044:
045: tmp = ((Integer) l.removeFromHead()).intValue();
046: assertEquals(tmp, 2);
047:
048: tmp = ((Integer) l.removeFromHead()).intValue();
049: assertEquals(tmp, 3);
050:
051: tmp = ((Integer) l.removeFromHead()).intValue();
052: assertEquals(tmp, 4);
053: }
054:
055: public void testAddAtHead() throws Exception {
056: assertEquals(l.size(), 0);
057: l.addAtHead(new Integer(1));
058: System.out.println(l);
059: assertEquals(l.size(), 1);
060:
061: l.addAtHead(new Integer(2));
062: System.out.println(l);
063:
064: l.addAtHead(new Integer(3));
065: System.out.println(l);
066: assertEquals(l.size(), 3);
067:
068: l.addAtHead(new Integer(4));
069: System.out.println(l);
070: assertEquals(l.size(), 3);
071:
072: int tmp;
073:
074: tmp = ((Integer) l.removeFromHead()).intValue();
075: assertEquals(tmp, 4);
076:
077: tmp = ((Integer) l.removeFromHead()).intValue();
078: assertEquals(tmp, 3);
079:
080: tmp = ((Integer) l.removeFromHead()).intValue();
081: assertEquals(tmp, 2);
082: }
083:
084: public void testContains() throws Exception {
085: l.add("Bela");
086: System.out.println(l);
087:
088: l.add("Michelle");
089: System.out.println(l);
090:
091: l.add("Jeannette");
092: System.out.println(l);
093:
094: l.add("Nicole");
095: System.out.println(l);
096:
097: assertTrue(l.contains("Bela") == false);
098: assertTrue(l.contains("Nicole"));
099: assertTrue(l.contains("Michelle"));
100: }
101:
102: public static void main(String[] args) {
103: String[] testCaseName = { BoundedListTest.class.getName() };
104: junit.textui.TestRunner.main(testCaseName);
105: }
106:
107: }
|