Apache Lucene open-source search software
Turn PriorityQueueTest into a JUnit test
Brian Goetzf6f1683dd504
diff --git a/src/test/org/apache/lucene/util/PriorityQueueTest.java b/src/test/org/apache/lucene/util/TestPriorityQueue.javasimilarity index 79%rename from src/test/org/apache/lucene/util/PriorityQueueTest.javarename to src/test/org/apache/lucene/util/TestPriorityQueue.javaindex d972ccd4e0e..fa857525e91 100644--- a/src/test/org/apache/lucene/util/PriorityQueueTest.java+++ b/src/test/org/apache/lucene/util/TestPriorityQueue.java@@ -56,11 +56,12 @@ package org.apache.lucene.util;import java.util.Date;import java.util.Random;+import junit.framework.*;-class PriorityQueueTest {- public static void main(String[] args) {- test(10000);- }+public class TestPriorityQueue extends TestCase {+ public TestPriorityQueue(String name) {+ super(name);+ }private static class IntegerQueue extends PriorityQueue {public IntegerQueue(int count) {@@ -73,36 +74,43 @@ class PriorityQueueTest {}}- public static void test(int count) {+ public void testPQ() throws Exception {+ testPQ(10000);+ }++ public static void testPQ(int count) {PriorityQueue pq = new IntegerQueue(count);Random gen = new Random();- int i;+ int sum = 0, sum2 = 0;Date start = new Date();- for (i = 0; i < count; i++) {- pq.put(new Integer(gen.nextInt()));+ for (int i = 0; i < count; i++) {+ int next = gen.nextInt();+ sum += next;+ pq.put(new Integer(next));}- Date end = new Date();+// Date end = new Date();- System.out.print(((float)(end.getTime()-start.getTime()) / count) * 1000);- System.out.println(" microseconds/put");+// System.out.print(((float)(end.getTime()-start.getTime()) / count) * 1000);+// System.out.println(" microseconds/put");- start = new Date();+// start = new Date();int last = Integer.MIN_VALUE;- for (i = 0; i < count; i++) {+ for (int i = 0; i < count; i++) {Integer next = (Integer)pq.pop();- if (next.intValue() <= last)- throw new Error("out of order");+ assert(next.intValue() >= last);last = next.intValue();+ sum2 += last;}- end = new Date();+ assert(sum == sum2);+// end = new Date();- System.out.print(((float)(end.getTime()-start.getTime()) / count) * 1000);- System.out.println(" microseconds/pop");+// System.out.print(((float)(end.getTime()-start.getTime()) / count) * 1000);+// System.out.println(" microseconds/pop");}}