mirror of https://github.com/apache/lucene.git
- 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. git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@149768 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a7bd647dd6
commit
a6d7df46a4
|
@ -56,50 +56,62 @@ 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) {
|
||||
public class TestPriorityQueue
|
||||
extends TestCase
|
||||
{
|
||||
public TestPriorityQueue(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
private static class IntegerQueue extends PriorityQueue {
|
||||
public IntegerQueue(int count) {
|
||||
private static class IntegerQueue
|
||||
extends PriorityQueue
|
||||
{
|
||||
public IntegerQueue(int count)
|
||||
{
|
||||
super();
|
||||
initialize(count);
|
||||
}
|
||||
|
||||
protected boolean lessThan(Object a, Object b) {
|
||||
protected boolean lessThan(Object a, Object b)
|
||||
{
|
||||
return ((Integer) a).intValue() < ((Integer) b).intValue();
|
||||
}
|
||||
}
|
||||
|
||||
public void testPQ() throws Exception {
|
||||
public void testPQ()
|
||||
throws Exception
|
||||
{
|
||||
testPQ(10000);
|
||||
}
|
||||
|
||||
public static void testPQ(int count) {
|
||||
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++) {
|
||||
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 (int i = 0; i < count; i++) {
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
Integer next = (Integer)pq.pop();
|
||||
assertTrue(next.intValue() >= last);
|
||||
last = next.intValue();
|
||||
|
@ -107,10 +119,20 @@ public class TestPriorityQueue extends TestCase {
|
|||
}
|
||||
|
||||
assertEquals(sum, sum2);
|
||||
// end = new Date();
|
||||
// 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");
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue