From fc483504821f60b0e2ba8a08e4be953961570070 Mon Sep 17 00:00:00 2001 From: Tilmann Date: Wed, 31 Jul 2024 15:01:09 +0200 Subject: [PATCH] Unit test output (#45) --- CHANGELOG.md | 6 +- .../org/tinspin/index/critbit/Examples.java | 6 +- .../tinspin/index/critbit/TestCritBit.java | 7 +- .../org/tinspin/index/phtree/PhTreeTest.java | 35 +- .../index/rtree/RTreeMixedQueryTest.java | 336 +++++++++--------- .../org/tinspin/index/test/Issue0037Test.java | 31 +- .../tinspin/index/test/TestBoxWrappers.java | 7 +- .../tinspin/index/test/TestBoxWrappersMM.java | 11 +- .../tinspin/index/test/TestPointWrappers.java | 7 +- .../index/test/TestPointWrappersMM.java | 11 +- .../org/tinspin/index/test/util/JmxTools.java | 8 +- .../index/test/util/TestBoxCluster.java | 4 +- .../tinspin/index/test/util/TestBoxCube.java | 4 +- .../index/test/util/TestPointCluster.java | 4 +- .../index/test/util/TestPointCube.java | 4 +- .../tinspin/index/test/util/TestRunner.java | 17 +- 16 files changed, 263 insertions(+), 235 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9372f10..46682a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,13 +10,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [2.1.4 - Unreleased] +### Fixed - Fixed tree corruption after remove() in QT2. [#40](https://github.com/tzaeschke/tinspin-indexes/issues/40) - Fixed tree consistency (single-entry leaf after remove) - Fixed tree consistency (nValues) -> verify - Fixed bug in qt2.contains() - Fixed QT2 inconsistency after root resizing after insert(). [#42](https://github.com/tzaeschke/tinspin-indexes/issues/42) - Essentially, we enforce all radii and the center of the root to be a power of two. - This should immensely reduce and problems with precision errors. + Essentially, we force all radii and the center of the root to be powers of two. + This should immensely reduce precision problems. +- Removed unnecessary JUnit test console output. [#45](https://github.com/tzaeschke/tinspin-indexes/pull/45) ## [2.1.3] - 2023-11-19 diff --git a/src/main/java/org/tinspin/index/critbit/Examples.java b/src/main/java/org/tinspin/index/critbit/Examples.java index ee13c5a..478d9c8 100644 --- a/src/main/java/org/tinspin/index/critbit/Examples.java +++ b/src/main/java/org/tinspin/index/critbit/Examples.java @@ -28,6 +28,8 @@ */ public class Examples { + public static boolean PRINT = true; + public static void main(String[] args) { ex1D_32(); ex1D_float(); @@ -123,6 +125,8 @@ private static void ex4D() { } private static void log(String msg) { - System.out.println(msg); + if (PRINT) { + System.out.println(msg); + } } } diff --git a/src/test/java/org/tinspin/index/critbit/TestCritBit.java b/src/test/java/org/tinspin/index/critbit/TestCritBit.java index cb95f44..ab6927c 100644 --- a/src/test/java/org/tinspin/index/critbit/TestCritBit.java +++ b/src/test/java/org/tinspin/index/critbit/TestCritBit.java @@ -28,6 +28,7 @@ import java.util.Arrays; import java.util.Random; +import org.junit.BeforeClass; import org.junit.Test; import org.tinspin.index.critbit.CritBit; import org.tinspin.index.critbit.CritBit1D; @@ -48,7 +49,11 @@ public class TestCritBit { private CritBit1D newCritBit(int depth) { return CritBit.create1D(depth); } - + + @BeforeClass public static void beforeClass() { + Examples.PRINT = false; + } + @Test public void testInsertIntRBug1() { randomInsertCheck(1000, 7374, 32); diff --git a/src/test/java/org/tinspin/index/phtree/PhTreeTest.java b/src/test/java/org/tinspin/index/phtree/PhTreeTest.java index 1ab8a99..89b8ac5 100644 --- a/src/test/java/org/tinspin/index/phtree/PhTreeTest.java +++ b/src/test/java/org/tinspin/index/phtree/PhTreeTest.java @@ -25,6 +25,7 @@ import java.util.Random; import ch.ethz.globis.tinspin.TestStats; +import org.junit.BeforeClass; import org.junit.Test; import org.tinspin.index.BoxMap; import org.tinspin.index.array.RectArray; @@ -32,6 +33,7 @@ import org.tinspin.index.test.util.TestBox; import org.tinspin.index.test.util.TestBoxCube; import org.tinspin.index.test.util.TestInstances.TST; +import org.tinspin.index.test.util.TestRunner; import static org.tinspin.index.Index.*; @@ -42,6 +44,11 @@ public class PhTreeTest { private static final double param1 = 0.01; private static final RectComp COMP = new RectComp(); + @BeforeClass + public static void beforeClass() { + TestRunner.PRINT = false; + } + @Test public void testR() { Random R = new Random(0); @@ -76,7 +83,7 @@ private void load(BoxMap tree, double[] data) { private void repeatQuery(TestBox test, BoxMap tree1, BoxMap tree2, int repeat) { int dims = DIM; //log("N=" + N); - log("querying index ... repeat = " + repeat); + println("querying index ... repeat = " + repeat); double[][] lower = new double[repeat][dims]; double[][] upper = new double[repeat][dims]; test.generateWindowQueries(lower, upper); @@ -85,7 +92,7 @@ private void repeatQuery(TestBox test, BoxMap tree1, BoxMap tr int n = 0; n = repeatQueries(tree1, tree2, lower, upper); long t2 = System.currentTimeMillis(); - log("Query time: " + (t2-t1) + " ms -> " + (t2-t1)/(double)repeat + " ms/q -> " + + println("Query time: " + (t2-t1) + " ms -> " + (t2-t1)/(double)repeat + " ms/q -> " + (t2-t1)*1000*1000/(double)n + " ns/q/r (n=" + n + ")"); } @@ -107,8 +114,8 @@ private int repeatQueries(BoxMap tree1, BoxMap tree2, double[] n2++; } if (n1 != n2) { - log("n1/n2=" + n1 + "/" + n2); - log("q=" + Arrays.toString(lower[i]) + "/" + Arrays.toString(upper[i])); + println("n1/n2=" + n1 + "/" + n2); + println("q=" + Arrays.toString(lower[i]) + "/" + Arrays.toString(upper[i])); set1.sort(COMP); set2.sort(COMP); for (int j = 0; j < set1.size(); j++) { @@ -116,15 +123,15 @@ private int repeatQueries(BoxMap tree1, BoxMap tree2, double[] BoxEntry e2 = set2.get(j); if (!Arrays.equals(e1.min(), e2.min()) || !Arrays.equals(e1.max(), e2.max())) { - log("j=" + j + " mismatch: " + e1 + " -/- " + e2); + println("j=" + j + " mismatch: " + e1 + " -/- " + e2); } } } assertEquals(n1, n2); n += n1; - if (i%10 == 0) System.out.print('.'); + if (i%10 == 0) print("."); } - System.out.println(); + println(""); //log("n=" + n/(double)lower.length); return n; } @@ -146,9 +153,17 @@ public int compare(BoxEntry o1, BoxEntry o2) { return 0; } } - - private static void log(String string) { - System.out.println(string); + + private static void println(String string) { + if (TestRunner.PRINT) { + System.out.println(string); + } + } + + private static void print(String string) { + if (TestRunner.PRINT) { + System.out.print(string); + } } } diff --git a/src/test/java/org/tinspin/index/rtree/RTreeMixedQueryTest.java b/src/test/java/org/tinspin/index/rtree/RTreeMixedQueryTest.java index 8861bc3..9b2b5be 100644 --- a/src/test/java/org/tinspin/index/rtree/RTreeMixedQueryTest.java +++ b/src/test/java/org/tinspin/index/rtree/RTreeMixedQueryTest.java @@ -1,10 +1,10 @@ /* * Copyright 2017 Christophe Schmaltz - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software @@ -15,185 +15,167 @@ */ package org.tinspin.index.rtree; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Random; -import java.util.Set; - import org.junit.Test; import org.tinspin.index.BoxDistance; -import static org.tinspin.index.Index.*; +import java.util.*; + +import static org.junit.Assert.*; +import static org.tinspin.index.Index.BoxEntryKnn; public class RTreeMixedQueryTest { - - private static final int DIMS = 8; - private static final int REPEAT = 10; - - // seed chosen randomly using a well equilibrated dice :-) - // [makes test reproducible] - Random rnd = new Random(4); - { - // fail here if Random implementation changes - assertEquals(-4969378402838085704l, rnd.nextLong()); - } - - @SuppressWarnings("rawtypes") - @Test - public void test() { - RTree tree = RTree.createRStar(DIMS); - - int N_ELEMENTS = 100000; - for (int i = 0; i < N_ELEMENTS; i++) { - double[] position = randDouble(DIMS); - assert tree.queryExact(position, position) == null; - tree.insert(position, "#" + i); - } - - Iterable> q = tree.queryRangedNearestNeighbor( - createAndFill( 1 ), - BoxDistance.CENTER, BoxDistance.EDGE, - createAndFill( 0.5 ), createAndFill( 1 )); - - - double lastDistance = 0; - int maxQueueSize = 0; - int nElements = 0; - Set duplicateCheck = new HashSet<>(); - for (Iterator> iterator = q.iterator(); iterator.hasNext();) { - BoxEntryKnn e = iterator.next(); - //System.out.println(nElements + " " + iterator + " " + e); - - assertTrue(e.value() + " @" + nElements, duplicateCheck.add(e.value())); - assertTrue("Order should be ascending", lastDistance <= e.dist()); - lastDistance = e.dist(); - nElements++; - maxQueueSize = Math.max(maxQueueSize, ((RTreeMixedQuery) iterator).queueSize()); - - if (true) { - iterator.remove(); - assertEquals(tree.size(), N_ELEMENTS - nElements); - } - } - - perfTestNN(tree); - System.out.println("maxQueueSize=" + maxQueueSize + " / "); - System.out.println("nElements=" + nElements); - if (DIMS == 3) { - assertEquals("Test should be reproducible thanks to fixed seed", 12582, nElements); - } - } - - private void perfTestNN(RTree tree) { - int k = tree.size() / 8; - double[] center = createAndFill( 1 ); - - { - Iterable> q = tree.queryRangedNearestNeighbor( - center, BoxDistance.EDGE, - BoxDistance.EDGE, Filter.ALL); - RTreeQueryKnn res = tree.queryKnn(center, k, BoxDistance.EDGE); - // test that we get the same results - Iterator> iterator = q.iterator(); - int i=0; - for (; iterator.hasNext();) { - assertTrue("I="+i, res.hasNext()); - assertEquals(res.next().value(), iterator.next().value()); - i++; - if (i >= k) - break; - } - assertFalse(res.hasNext()); - } - - fillProcessorCache(); - - long timeRef = timeOf(() -> { - RTreeQueryKnn res = tree.queryKnn(center, k, BoxDistance.EDGE); - int cnt = 0; - for(;res.hasNext();) { - cnt++; - BoxEntryKnn e = res.next(); - assertNotNull(e); - } - assertEquals(k, cnt); - }); - - fillProcessorCache(); - - long timeMixed = timeOf(() -> { - Iterable> q = tree.queryRangedNearestNeighbor( - center, BoxDistance.EDGE, - BoxDistance.EDGE, Filter.ALL); - int cnt = 0; - if (false) { - /* - * A lot of the speedup is simply due to the copy. Adding this - * makes the code 6,28 times slower for 12500 neighbors out of 100000. - * - * Probably cache locality as my code is only faster for large results. - * - * It seems as if executing the query multiple times is better than caching the results... - */ - List> arr = new ArrayList<>(); - q.forEach(arr::add); - q = arr; - } - for (Iterator> iterator = q.iterator(); iterator.hasNext();) { - BoxEntryKnn e = iterator.next(); - assertNotNull(e); - cnt++; - if (cnt >= k) - break; - } - }); - - System.out.println("timeMixed=" + timeMixed + ", timeRef=" + timeRef + " # speedup:" + (timeRef / (double)timeMixed)); - } - - private void fillProcessorCache() { - // 20MB - int[] mem = new int[1024 * 1024 * 20]; - for (int i = 0; i < mem.length; i++) { - mem[i] = i; - } - } - - public long timeOf(Runnable run) { - final int nRuns = REPEAT; - long time = 0; - for (int i = 0; i <= nRuns; i++) { - long timeBefore = System.nanoTime(); - run.run(); - long delta = System.nanoTime() - timeBefore; - if (i > 0) { - // ignore the first one for warm up - time += delta; - } - } - return time / nRuns; - } - - private static double[] createAndFill(double d) { - double[] ret = new double[DIMS]; - Arrays.fill(ret, d); - return ret; - } - - private double[] randDouble(int n) { - double[] r = new double[n]; - for (int i = 0; i < n; i++) { - r[i] = rnd.nextDouble(); - } - return r; - } + + private static final int DIMS = 8; + private static final int REPEAT = 10; + + // seed chosen randomly using a well equilibrated dice :-) + // [makes test reproducible] + Random rnd = new Random(4); + + { + // fail here if Random implementation changes + assertEquals(-4969378402838085704L, rnd.nextLong()); + } + + @SuppressWarnings("rawtypes") + @Test + public void test() { + RTree tree = RTree.createRStar(DIMS); + + int N_ELEMENTS = 100000; + for (int i = 0; i < N_ELEMENTS; i++) { + double[] position = randDouble(DIMS); + assert tree.queryExact(position, position) == null; + tree.insert(position, "#" + i); + } + + Iterable> q = tree.queryRangedNearestNeighbor(createAndFill(1), BoxDistance.CENTER, BoxDistance.EDGE, createAndFill(0.5), createAndFill(1)); + + + double lastDistance = 0; + int maxQueueSize = 0; + int nElements = 0; + Set duplicateCheck = new HashSet<>(); + for (Iterator> iterator = q.iterator(); iterator.hasNext(); ) { + BoxEntryKnn e = iterator.next(); + // System.out.println(nElements + " " + iterator + " " + e); + + assertTrue(e.value() + " @" + nElements, duplicateCheck.add(e.value())); + assertTrue("Order should be ascending", lastDistance <= e.dist()); + lastDistance = e.dist(); + nElements++; + maxQueueSize = Math.max(maxQueueSize, ((RTreeMixedQuery) iterator).queueSize()); + + if (true) { + iterator.remove(); + assertEquals(tree.size(), N_ELEMENTS - nElements); + } + } + + perfTestNN(tree); + // System.out.println("maxQueueSize=" + maxQueueSize + " / "); + // System.out.println("nElements=" + nElements); + if (DIMS == 3) { + assertEquals("Test should be reproducible thanks to fixed seed", 12582, nElements); + } + } + + private void perfTestNN(RTree tree) { + int k = tree.size() / 8; + double[] center = createAndFill(1); + + { + Iterable> q = tree.queryRangedNearestNeighbor(center, BoxDistance.EDGE, BoxDistance.EDGE, Filter.ALL); + RTreeQueryKnn res = tree.queryKnn(center, k, BoxDistance.EDGE); + // test that we get the same results + Iterator> iterator = q.iterator(); + int i = 0; + while (iterator.hasNext()) { + assertTrue("I=" + i, res.hasNext()); + assertEquals(res.next().value(), iterator.next().value()); + i++; + if (i >= k) break; + } + assertFalse(res.hasNext()); + } + + fillProcessorCache(); + + long timeRef = timeOf(() -> { + RTreeQueryKnn res = tree.queryKnn(center, k, BoxDistance.EDGE); + int cnt = 0; + while (res.hasNext()) { + cnt++; + BoxEntryKnn e = res.next(); + assertNotNull(e); + } + assertEquals(k, cnt); + }); + + fillProcessorCache(); + + long timeMixed = timeOf(() -> { + Iterable> q = tree.queryRangedNearestNeighbor(center, BoxDistance.EDGE, BoxDistance.EDGE, Filter.ALL); + int cnt = 0; + if (false) { + /* + * A lot of the speedup is simply due to the copy. Adding this + * makes the code 6,28 times slower for 12500 neighbors out of 100000. + * + * Probably cache locality as my code is only faster for large results. + * + * It seems as if executing the query multiple times is better than caching the results... + */ + List> arr = new ArrayList<>(); + q.forEach(arr::add); + q = arr; + } + for (Iterator> iterator = q.iterator(); iterator.hasNext(); ) { + BoxEntryKnn e = iterator.next(); + assertNotNull(e); + cnt++; + if (cnt >= k) break; + } + }); + + // System.out.println("timeMixed=" + timeMixed + ", timeRef=" + timeRef + " # speedup:" + (timeRef / (double)timeMixed)); + } + + private void fillProcessorCache() { + // 20MB + int[] mem = new int[1024 * 1024 * 20]; + for (int i = 0; i < mem.length; i++) { + mem[i] = i; + } + } + + public long timeOf(Runnable run) { + final int nRuns = REPEAT; + long time = 0; + for (int i = 0; i <= nRuns; i++) { + long timeBefore = System.nanoTime(); + run.run(); + long delta = System.nanoTime() - timeBefore; + if (i > 0) { + // ignore the first one for warm up + time += delta; + } + } + return time / nRuns; + } + + private static double[] createAndFill(double d) { + double[] ret = new double[DIMS]; + Arrays.fill(ret, d); + return ret; + } + + private double[] randDouble(int n) { + double[] r = new double[n]; + for (int i = 0; i < n; i++) { + r[i] = rnd.nextDouble(); + } + return r; + } } diff --git a/src/test/java/org/tinspin/index/test/Issue0037Test.java b/src/test/java/org/tinspin/index/test/Issue0037Test.java index d288eb2..13d4d55 100644 --- a/src/test/java/org/tinspin/index/test/Issue0037Test.java +++ b/src/test/java/org/tinspin/index/test/Issue0037Test.java @@ -30,7 +30,6 @@ import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Random; import static org.junit.Assert.assertTrue; @@ -64,8 +63,8 @@ public void testQT2() throws IOException { * knn=[24.7677965164185, -335.507710456848] * 1476 * false - * - * + *

+ *

* p=20.7747859954834, -335.053844928741 * knn=[13.7747859954834, -335.053844928741] * 1476 @@ -86,23 +85,23 @@ private void testTree(PointMap tree) throws IOException { for (int i = 0; i < k; i++) { String[] sp = reader.readLine().split(" "); double d1 = Double.parseDouble(sp[0]), d2 = Double.parseDouble(sp[1]); - System.out.println("Remove: " + d1 + ", " + d2); + // System.out.println("Remove: " + d1 + ", " + d2); tree.remove(new double[]{d1, d2}); } Stats stats = tree.getStats(); - System.out.println("Stats: n=" + stats.nEntries); + // System.out.println("Stats: n=" + stats.nEntries); { String[] sp = reader.readLine().split(" "); double d1 = Double.parseDouble(sp[0]), d2 = Double.parseDouble(sp[1]); - System.out.println("p=" + d1 + ", " + d2); + // System.out.println("p=" + d1 + ", " + d2); boolean has13_335 = tree.contains(new double[]{13.7747859954834, -335.053844928741}); - System.out.println("contains: 13.7747859954834, -335.053844928741 ? " + has13_335); + // System.out.println("contains: 13.7747859954834, -335.053844928741 ? " + has13_335); var node = tree.query1nn(new double[]{d1, d2}); - System.out.println("knn=" + Arrays.toString(node.point())); + // System.out.println("knn=" + Arrays.toString(node.point())); boolean has = tree.contains(node.point()); - System.out.println(n); + // System.out.println(n); - System.out.println(has); // Should print true, but prints false with QuadTreeKD2 + // System.out.println(has); // Should print true, but prints false with QuadTreeKD2 assertTrue(has); } } @@ -110,7 +109,7 @@ private void testTree(PointMap tree) throws IOException { private void testTree2(PointMap tree) throws IOException { Random R = new Random(0); int n = 100; - int k = n/2; + int k = n / 2; ArrayList array = new ArrayList<>(); for (int i = 0; i < n; i++) { @@ -134,12 +133,12 @@ private void testTree2(PointMap tree) throws IOException { // assertTrue(has); // } for (int i = 0; i < n; i++) { - var node = tree.query1nn(array.get(i)); - boolean has = tree.contains(node.point()); - System.out.println(n); + var node = tree.query1nn(array.get(i)); + boolean has = tree.contains(node.point()); + // System.out.println(n); - System.out.println(has); // Should print true, but prints false with QuadTreeKD2 - assertTrue(has); + // System.out.println(has); // Should print true, but prints false with QuadTreeKD2 + assertTrue(has); } } } diff --git a/src/test/java/org/tinspin/index/test/TestBoxWrappers.java b/src/test/java/org/tinspin/index/test/TestBoxWrappers.java index 6ba7180..93fa0c8 100644 --- a/src/test/java/org/tinspin/index/test/TestBoxWrappers.java +++ b/src/test/java/org/tinspin/index/test/TestBoxWrappers.java @@ -31,9 +31,10 @@ public TestBoxWrappers(IDX candCls) { @BeforeClass public static void beforeClass() { - //init results - //use this as reference for all others - //if the naive implementation should be wrong, the others should fail as well + TestRunner.PRINT = false; + // init results + // use this as reference for all others + // if the naive implementation should be wrong, the others should fail as well expectedCube = createUnitTestStats(IDX.ARRAY, TST.CUBE_R, N, dims, 1.0); new TestRunner(expectedCube).run(); diff --git a/src/test/java/org/tinspin/index/test/TestBoxWrappersMM.java b/src/test/java/org/tinspin/index/test/TestBoxWrappersMM.java index d75539f..ea6bf2e 100644 --- a/src/test/java/org/tinspin/index/test/TestBoxWrappersMM.java +++ b/src/test/java/org/tinspin/index/test/TestBoxWrappersMM.java @@ -33,9 +33,10 @@ public TestBoxWrappersMM(IDX candCls) { @BeforeClass public static void beforeClass() { - //init results - //use this as reference for all others - //if the naive implementation should be wrong, the others should fail as well + TestRunner.PRINT = false; + // init results + // use this as reference for all others + // if the naive implementation should be wrong, the others should fail as well expectedCube = createUnitTestStatsDupl(IDX.ARRAY, TST.CUBE_R, N, dims, 1.0, N_DUPL); new TestRunner(expectedCube).run(); @@ -58,7 +59,7 @@ public static Iterable candidates() { @Test @Parameters public void testCube() { - System.out.println("Testing: " + candidate.name()); + TestRunner.log("Testing: " + candidate.name()); TestStats ts = createUnitTestStatsDupl(candidate, TST.CUBE_R, N, dims, 1.0, N_DUPL); TestRunner tr = new TestRunner(ts); tr.run(); @@ -69,7 +70,7 @@ public void testCube() { @Test @Parameters public void testCluster() { - System.out.println("Testing: " + candidate.name()); + TestRunner.log("Testing: " + candidate.name()); TestStats ts = createUnitTestStatsDupl(candidate, TST.CLUSTER_R, N, dims, 5.0, N_DUPL); TestRunner tr = new TestRunner(ts); tr.run(); diff --git a/src/test/java/org/tinspin/index/test/TestPointWrappers.java b/src/test/java/org/tinspin/index/test/TestPointWrappers.java index 51a9c52..f8c76fc 100644 --- a/src/test/java/org/tinspin/index/test/TestPointWrappers.java +++ b/src/test/java/org/tinspin/index/test/TestPointWrappers.java @@ -32,9 +32,10 @@ public TestPointWrappers(IDX candCls) { @BeforeClass public static void beforeClass() { - //init results - //use this as reference for all others - //if the naive implementation should be wrong, the others should fail as well + TestRunner.PRINT = false; + // init results + // use this as reference for all others + // if the naive implementation should be wrong, the others should fail as well expectedCube = createUnitTestStats(IDX.ARRAY, TST.CUBE_P, N, dims, 1.0); new TestRunner(expectedCube).run(); diff --git a/src/test/java/org/tinspin/index/test/TestPointWrappersMM.java b/src/test/java/org/tinspin/index/test/TestPointWrappersMM.java index dcbbc4b..6a19471 100644 --- a/src/test/java/org/tinspin/index/test/TestPointWrappersMM.java +++ b/src/test/java/org/tinspin/index/test/TestPointWrappersMM.java @@ -32,9 +32,10 @@ public TestPointWrappersMM(IDX candCls) { @BeforeClass public static void beforeClass() { - //init results - //use this as reference for all others - //if the naive implementation should be wrong, the others should fail as well + TestRunner.PRINT = false; + // init results + // use this as reference for all others + // if the naive implementation should be wrong, the others should fail as well expectedCube = createUnitTestStatsDupl(IDX.ARRAY, TST.CUBE_P, N, dims, 1.0, N_DUPL); new TestRunner(expectedCube).run(); @@ -61,7 +62,7 @@ public static Iterable candidates() { @Test @Parameters public void testCube() { - System.out.println("Testing: " + candidate.name()); + TestRunner.log("Testing: " + candidate.name()); TestStats ts = createUnitTestStatsDupl(candidate, TST.CUBE_P, N, dims, 1.0, N_DUPL); TestRunner tr = new TestRunner(ts); tr.run(); @@ -72,7 +73,7 @@ public void testCube() { @Test @Parameters public void testCluster() { - System.out.println("Testing: " + candidate.name()); + TestRunner.log("Testing: " + candidate.name()); TestStats ts = createUnitTestStatsDupl(candidate, TST.CLUSTER_P, N, dims, 5.0, N_DUPL); TestRunner tr = new TestRunner(ts); tr.run(); diff --git a/src/test/java/org/tinspin/index/test/util/JmxTools.java b/src/test/java/org/tinspin/index/test/util/JmxTools.java index 1282142..6a29fdc 100644 --- a/src/test/java/org/tinspin/index/test/util/JmxTools.java +++ b/src/test/java/org/tinspin/index/test/util/JmxTools.java @@ -36,6 +36,7 @@ public class JmxTools { + public static boolean PRINT = false; private static final MBeanServer SERVER = ManagementFactory.getPlatformMBeanServer(); private static final String[] POOL_NAMES; static { @@ -78,7 +79,7 @@ public static void gc() { sleep(); td2 = totalDiff; tt2 = totalTime; - System.out.println("GC: " + (td1/1024/1024) + "MB -> " + (td2/1024/1024) + "MB " + + println("GC: " + (td1/1024/1024) + "MB -> " + (td2/1024/1024) + "MB " + "tGC=" + (tt2-tt1) + " tSys=" + (ts2-ts1)); n++; //Ignore Eden collection of <3MB @@ -374,4 +375,9 @@ private static void processNotification(ObjectName name) { // System.out.println("Not supported: " + o.getClass()); // } + private static void println(String s) { + if (PRINT) { + System.out.println(s); + } + } } diff --git a/src/test/java/org/tinspin/index/test/util/TestBoxCluster.java b/src/test/java/org/tinspin/index/test/util/TestBoxCluster.java index 809247c..e68cbd3 100644 --- a/src/test/java/org/tinspin/index/test/util/TestBoxCluster.java +++ b/src/test/java/org/tinspin/index/test/util/TestBoxCluster.java @@ -66,7 +66,9 @@ public TestBoxCluster(Random R, TestStats S) { //diagonal version @Override public double[] generate() { - log("Running: TestCluster(" + S.cfgDataLen + "," + S.cfgDuplicates + ")"); + if (TestRunner.PRINT) { + log("Running: TestCluster(" + S.cfgDataLen + "," + S.cfgDuplicates + ")"); + } double len = 1.0; switch (TYPE.toType(param1)) { diff --git a/src/test/java/org/tinspin/index/test/util/TestBoxCube.java b/src/test/java/org/tinspin/index/test/util/TestBoxCube.java index 707b21b..8f5bb31 100644 --- a/src/test/java/org/tinspin/index/test/util/TestBoxCube.java +++ b/src/test/java/org/tinspin/index/test/util/TestBoxCube.java @@ -25,7 +25,9 @@ public TestBoxCube(Random R, TestStats S) { @Override public double[] generate() { double rectLen = S.cfgRectLen; - log("Running: TestCube (" + rectLen + "," + S.cfgDuplicates + ")"); + if (TestRunner.PRINT) { + log("Running: TestCube (" + rectLen + "," + S.cfgDuplicates + ")"); + } int dims = S.cfgNDims; int nEntries = S.cfgNEntries; diff --git a/src/test/java/org/tinspin/index/test/util/TestPointCluster.java b/src/test/java/org/tinspin/index/test/util/TestPointCluster.java index f1de380..b3a5e30 100644 --- a/src/test/java/org/tinspin/index/test/util/TestPointCluster.java +++ b/src/test/java/org/tinspin/index/test/util/TestPointCluster.java @@ -67,7 +67,9 @@ static TYPE toType(double d) { //diagonal version @Override public double[] generate() { - log("Running: TestCluster(" + S.cfgDataLen + "," + S.cfgDuplicates + ")"); + if (TestRunner.PRINT) { + log("Running: TestCluster(" + S.cfgDataLen + "," + S.cfgDuplicates + ")"); + } double len = 1.0; switch (TYPE.toType(param1)) { case ORIGINAL: return generateOriginal(len); diff --git a/src/test/java/org/tinspin/index/test/util/TestPointCube.java b/src/test/java/org/tinspin/index/test/util/TestPointCube.java index 762b902..05230cb 100644 --- a/src/test/java/org/tinspin/index/test/util/TestPointCube.java +++ b/src/test/java/org/tinspin/index/test/util/TestPointCube.java @@ -27,7 +27,9 @@ public TestPointCube(Random R, TestStats S) { */ @Override public double[] generate() { - log("Running: TestCube(" + S.cfgDataLen + "," + S.cfgDuplicates + ")"); + if (TestRunner.PRINT) { + log("Running: TestCube(" + S.cfgDataLen + "," + S.cfgDuplicates + ")"); + } double[] data = new double[getN() * DIM]; int dup = S.cfgDuplicates; for (int i = 0; i < getN(); i += dup) { diff --git a/src/test/java/org/tinspin/index/test/util/TestRunner.java b/src/test/java/org/tinspin/index/test/util/TestRunner.java index dc0a0ff..57150a3 100644 --- a/src/test/java/org/tinspin/index/test/util/TestRunner.java +++ b/src/test/java/org/tinspin/index/test/util/TestRunner.java @@ -28,10 +28,9 @@ * @author Tilmann Zaeschke */ public class TestRunner { - - private static final SimpleDateFormat FT = new SimpleDateFormat ("yyyy-MM-dd' 'HH:mm:ss"); - public static boolean USE_NEW_QUERIES = true; + public static boolean PRINT = false; + private static final SimpleDateFormat FT = new SimpleDateFormat ("yyyy-MM-dd' 'HH:mm:ss"); private final TestStats S; private Random R; @@ -471,12 +470,16 @@ private int repeatQueries(double[][] lower, double[][] upper) { return n; } - static void log(String string) { - System.out.println(string); + public static void log(String string) { + if (PRINT) { + System.out.println(string); + } } - static void logNLF(String string) { - System.out.print(string); + public static void logNLF(String string) { + if (PRINT) { + System.out.print(string); + } }