Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
35   109   9   5
4   71   0.26   3.5
7     1.29  
2    
 
  TestPriorityQueue       Line # 22 32 7 100% 1.0
  TestPriorityQueue.IntegerQueue       Line # 30 3 2 100% 1.0
 
  (3)
 
1    package org.apache.lucene.util;
2   
3    /**
4    * Copyright 2004 The Apache Software Foundation
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10    * http://www.apache.org/licenses/LICENSE-2.0
11    *
12    * Unless required by applicable law or agreed to in writing, software
13    * distributed under the License is distributed on an "AS IS" BASIS,
14    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    * See the License for the specific language governing permissions and
16    * limitations under the License.
17    */
18   
19    import java.util.Random;
20    import junit.framework.TestCase;
21   
 
22    public class TestPriorityQueue
23    extends TestCase
24    {
 
25  3 toggle public TestPriorityQueue(String name)
26    {
27  3 super(name);
28    }
29   
 
30    private static class IntegerQueue
31    extends PriorityQueue
32    {
 
33  3 toggle public IntegerQueue(int count)
34    {
35  3 super();
36  3 initialize(count);
37    }
38   
 
39  239230 toggle protected boolean lessThan(Object a, Object b)
40    {
41  239230 return ((Integer) a).intValue() < ((Integer) b).intValue();
42    }
43    }
44   
 
45  1 toggle public void testPQ()
46    throws Exception
47    {
48  1 testPQ(10000);
49    }
50   
 
51  1 toggle public static void testPQ(int count)
52    {
53  1 PriorityQueue pq = new IntegerQueue(count);
54  1 Random gen = new Random();
55  1 int sum = 0, sum2 = 0;
56   
57  10001 for (int i = 0; i < count; i++)
58    {
59  10000 int next = gen.nextInt();
60  10000 sum += next;
61  10000 pq.put(new Integer(next));
62    }
63   
64    // Date end = new Date();
65   
66    // System.out.print(((float)(end.getTime()-start.getTime()) / count) * 1000);
67    // System.out.println(" microseconds/put");
68   
69    // start = new Date();
70   
71  1 int last = Integer.MIN_VALUE;
72  10001 for (int i = 0; i < count; i++)
73    {
74  10000 Integer next = (Integer)pq.pop();
75  10000 assertTrue(next.intValue() >= last);
76  10000 last = next.intValue();
77  10000 sum2 += last;
78    }
79   
80  1 assertEquals(sum, sum2);
81    // end = new Date();
82   
83    // System.out.print(((float)(end.getTime()-start.getTime()) / count) * 1000);
84    // System.out.println(" microseconds/pop");
85    }
86   
 
87  1 toggle public void testClear()
88    {
89  1 PriorityQueue pq = new IntegerQueue(3);
90  1 pq.put(new Integer(2));
91  1 pq.put(new Integer(3));
92  1 pq.put(new Integer(1));
93  1 assertEquals(3, pq.size());
94  1 pq.clear();
95  1 assertEquals(0, pq.size());
96    }
97   
 
98  1 toggle public void testFixedSize(){
99  1 PriorityQueue pq = new IntegerQueue(3);
100  1 pq.insert(new Integer(2));
101  1 pq.insert(new Integer(3));
102  1 pq.insert(new Integer(1));
103  1 pq.insert(new Integer(5));
104  1 pq.insert(new Integer(7));
105  1 pq.insert(new Integer(1));
106  1 assertEquals(3, pq.size());
107  1 assertEquals(3, ((Integer) pq.top()).intValue());
108    }
109    }