01: package com.ecyrd.jspwiki.util;
02:
03: import junit.framework.*;
04:
05: public class PriorityListTest extends TestCase {
06: public PriorityListTest(String s) {
07: super (s);
08: }
09:
10: public void testInsert() {
11: PriorityList p = new PriorityList();
12:
13: p.add("One", 1);
14: p.add("Two", 2);
15:
16: assertEquals("size", 2, p.size());
17:
18: assertEquals("Two", "Two", p.get(0));
19: assertEquals("One", "One", p.get(1));
20: }
21:
22: /**
23: * Check that the priority in case two items are the same priority
24: * is "first goes first".
25: */
26: public void testInsertSame() {
27: PriorityList p = new PriorityList();
28:
29: p.add("One", 1);
30: p.add("Two", 1);
31:
32: assertEquals("size", 2, p.size());
33:
34: assertEquals("One", "One", p.get(0));
35: assertEquals("Two", "Two", p.get(1));
36: }
37:
38: public void testInsertSame2() {
39: PriorityList p = new PriorityList();
40:
41: p.add("One", 1);
42: p.add("Two", 2);
43: p.add("Three", 3);
44:
45: assertEquals("size", 3, p.size());
46:
47: assertEquals("Three", "Three", p.get(0));
48: assertEquals("Two", "Two", p.get(1));
49: assertEquals("One", "One", p.get(2));
50:
51: p.add("TwoTwo", 2);
52:
53: assertEquals("2: size", 4, p.size());
54:
55: assertEquals("2: Three", "Three", p.get(0));
56: assertEquals("2: Two", "Two", p.get(1));
57: assertEquals("2: TwoTwo", "TwoTwo", p.get(2));
58: assertEquals("2: One", "One", p.get(3));
59: }
60:
61: public void testInsertSame3() {
62: PriorityList p = new PriorityList();
63:
64: p.add("One", 1);
65: p.add("Two", 2);
66: p.add("Two2", 2);
67: p.add("Two3", 2);
68: p.add("Three", 3);
69:
70: assertEquals("size", 5, p.size());
71:
72: assertEquals("Three", "Three", p.get(0));
73: assertEquals("Two", "Two", p.get(1));
74: assertEquals("Two2", "Two2", p.get(2));
75: assertEquals("Two3", "Two3", p.get(3));
76: assertEquals("One", "One", p.get(4));
77:
78: p.add("TwoTwo", 2);
79:
80: assertEquals("2: size", 6, p.size());
81:
82: assertEquals("2: Three", "Three", p.get(0));
83: assertEquals("2: Two", "Two", p.get(1));
84: assertEquals("2: Two2", "Two2", p.get(2));
85: assertEquals("2: Two3", "Two3", p.get(3));
86: assertEquals("2: TwoTwo", "TwoTwo", p.get(4));
87: assertEquals("2: One", "One", p.get(5));
88: }
89:
90: public static Test suite() {
91: return new TestSuite(PriorityListTest.class);
92: }
93: }
|