Apache Lucene open-source search software
- Added testClear() test. It doesn't really test much, but since I already typed it in I'm leaving it. - Reformatted/reindented the code and nuked trailing spaces.
Otis Gospodnetica6d7df46a435
diff --git a/src/test/org/apache/lucene/util/TestPriorityQueue.java b/src/test/org/apache/lucene/util/TestPriorityQueue.javaindex e4bea6a6961..40836712bdb 100644--- a/src/test/org/apache/lucene/util/TestPriorityQueue.java+++ b/src/test/org/apache/lucene/util/TestPriorityQueue.java@@ -56,61 +56,83 @@ package org.apache.lucene.util;import java.util.Date;import java.util.Random;-import junit.framework.*;+import junit.framework.TestCase;-public class TestPriorityQueue extends TestCase {- public TestPriorityQueue(String name) {- super(name);- }-- private static class IntegerQueue extends PriorityQueue {- public IntegerQueue(int count) {- super();- initialize(count);+public class TestPriorityQueue+ extends TestCase+{+ public TestPriorityQueue(String name)+ {+ super(name);}- protected boolean lessThan(Object a, Object b) {- return ((Integer) a).intValue() < ((Integer) b).intValue();+ private static class IntegerQueue+ extends PriorityQueue+ {+ public IntegerQueue(int count)+ {+ super();+ initialize(count);+ }++ protected boolean lessThan(Object a, Object b)+ {+ return ((Integer) a).intValue() < ((Integer) b).intValue();+ }}- }-- public void testPQ() throws Exception {- testPQ(10000);- }-- public static void testPQ(int count) {- PriorityQueue pq = new IntegerQueue(count);- Random gen = new Random();- int sum = 0, sum2 = 0;-- Date start = new Date();-- for (int i = 0; i < count; i++) {- int next = gen.nextInt();- sum += next;- pq.put(new Integer(next));++ public void testPQ()+ throws Exception+ {+ testPQ(10000);}-// Date end = new Date();+ public static void testPQ(int count)+ {+ PriorityQueue pq = new IntegerQueue(count);+ Random gen = new Random();+ int sum = 0, sum2 = 0;-// System.out.print(((float)(end.getTime()-start.getTime()) / count) * 1000);-// System.out.println(" microseconds/put");+ Date start = new Date();-// start = new Date();+ for (int i = 0; i < count; i++)+ {+ int next = gen.nextInt();+ sum += next;+ pq.put(new Integer(next));+ }- int last = Integer.MIN_VALUE;- for (int i = 0; i < count; i++) {- Integer next = (Integer)pq.pop();- assertTrue(next.intValue() >= last);- last = next.intValue();- sum2 += last;- }+ // Date end = new Date();++ // System.out.print(((float)(end.getTime()-start.getTime()) / count) * 1000);+ // System.out.println(" microseconds/put");- assertEquals(sum, sum2);-// end = new Date();+ // start = new Date();-// System.out.print(((float)(end.getTime()-start.getTime()) / count) * 1000);-// System.out.println(" microseconds/pop");+ int last = Integer.MIN_VALUE;+ for (int i = 0; i < count; i++)+ {+ Integer next = (Integer)pq.pop();+ assertTrue(next.intValue() >= last);+ last = next.intValue();+ sum2 += last;+ }- }+ assertEquals(sum, sum2);+ // end = new Date();++ // System.out.print(((float)(end.getTime()-start.getTime()) / count) * 1000);+ // System.out.println(" microseconds/pop");+ }++ public void testClear()+ {+ PriorityQueue pq = new IntegerQueue(3);+ pq.put(new Integer(2));+ pq.put(new Integer(3));+ pq.put(new Integer(1));+ assertEquals(3, pq.size());+ pq.clear();+ assertEquals(0, pq.size());+ }}