Repository: jena Updated Branches: refs/heads/master 960a2ebce -> eaf580dac
Improve permuting arrays in support of randomized testing Project: http://git-wip-us.apache.org/repos/asf/jena/repo Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/ba50b1f0 Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/ba50b1f0 Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/ba50b1f0 Branch: refs/heads/master Commit: ba50b1f05f8f9043965829e2dde7e6829ba2d5f0 Parents: a0aa6e9 Author: Andy Seaborne <[email protected]> Authored: Mon Feb 23 10:51:42 2015 +0000 Committer: Andy Seaborne <[email protected]> Committed: Mon Feb 23 10:51:42 2015 +0000 ---------------------------------------------------------------------- .../java/org/apache/jena/atlas/test/Gen.java | 20 +++++++++++++++++-- .../com/hp/hpl/jena/tdb/index/IndexTestLib.java | 2 +- .../hpl/jena/tdb/index/ext/ExtHashTestBase.java | 21 +++++++++----------- 3 files changed, 28 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jena/blob/ba50b1f0/jena-arq/src/main/java/org/apache/jena/atlas/test/Gen.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/atlas/test/Gen.java b/jena-arq/src/main/java/org/apache/jena/atlas/test/Gen.java index a87275c..4a573a6 100644 --- a/jena-arq/src/main/java/org/apache/jena/atlas/test/Gen.java +++ b/jena-arq/src/main/java/org/apache/jena/atlas/test/Gen.java @@ -20,7 +20,9 @@ package org.apache.jena.atlas.test; import static org.apache.jena.atlas.lib.RandomLib.random ; +import java.util.ArrayList ; import java.util.Arrays ; +import java.util.List ; /** Support for testing. May be generally useful */ public class Gen @@ -56,8 +58,22 @@ public class Gen return k ; } - /** Sort-of jumble a sequence */ - public static int[] permute(int[] x, int num) { + /** Pull items out of the list in a random order */ + public static int[] permute(int[] x) { + int[] x2 = new int[x.length] ; + List<Integer> list = new ArrayList<>() ; + + for ( int i : x ) + list.add(i) ; + for ( int i = 0 ; i<x.length ; i++ ) { + int idx = random.nextInt(list.size()) ; + x2[i] = list.remove(idx) ; + } + return x2 ; + } + + /** Do a number of random pair-wise swaps */ + public static int[] shuffle(int[] x, int num) { // Collections.shuffle. int[] x2 = new int[x.length] ; System.arraycopy(x, 0, x2, 0, x.length) ; http://git-wip-us.apache.org/repos/asf/jena/blob/ba50b1f0/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/index/IndexTestLib.java ---------------------------------------------------------------------- diff --git a/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/index/IndexTestLib.java b/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/index/IndexTestLib.java index fb2a71e..1329fe7 100644 --- a/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/index/IndexTestLib.java +++ b/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/index/IndexTestLib.java @@ -102,7 +102,7 @@ public class IndexTestLib System.err.printf("Warning: too many keys\n") ; int[] keys1 = rand(numKeys, 0, maxValue) ; - int[] keys2 = permute(keys1, 4*numKeys) ; + int[] keys2 = permute(keys1) ; try { testInsert(index, keys1); if ( true ) http://git-wip-us.apache.org/repos/asf/jena/blob/ba50b1f0/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/index/ext/ExtHashTestBase.java ---------------------------------------------------------------------- diff --git a/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/index/ext/ExtHashTestBase.java b/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/index/ext/ExtHashTestBase.java index f84e675..be28e78 100644 --- a/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/index/ext/ExtHashTestBase.java +++ b/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/index/ext/ExtHashTestBase.java @@ -23,23 +23,20 @@ import static org.apache.jena.atlas.lib.RandomLib.random ; import static org.apache.jena.atlas.test.Gen.permute ; import static org.apache.jena.atlas.test.Gen.rand ; import static org.apache.jena.atlas.test.Gen.strings ; -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 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.Iterator; -import java.util.List; +import java.util.Iterator ; +import java.util.List ; import org.apache.jena.atlas.lib.Bytes ; import org.apache.jena.atlas.test.ExecGenerator ; import org.apache.jena.atlas.test.RepeatExecution ; - - -import com.hp.hpl.jena.tdb.base.record.Record; -import com.hp.hpl.jena.tdb.base.record.RecordFactory; -import com.hp.hpl.jena.tdb.index.ext.ExtHash; +import com.hp.hpl.jena.tdb.base.record.Record ; +import com.hp.hpl.jena.tdb.base.record.RecordFactory ; public class ExtHashTestBase { @@ -77,7 +74,7 @@ public class ExtHashTestBase // System.err.printf("Warning: too many keys\n") ; int[] r1 = rand(numKeys, 0, maxValue) ; - int[] r2 = permute(r1, 4*numKeys) ; + int[] r2 = permute(r1) ; runTest(r1, r2) ; }
