lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject lucene-solr:branch_6x: add test case
Date Wed, 03 Aug 2016 18:31:06 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x 728b4fbcd -> 03138e764


add test case


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/03138e76
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/03138e76
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/03138e76

Branch: refs/heads/branch_6x
Commit: 03138e764dd0c88f6dbeb666eb5d76ef6b91844c
Parents: 728b4fb
Author: Mike McCandless <mikemccand@apache.org>
Authored: Wed Aug 3 14:30:44 2016 -0400
Committer: Mike McCandless <mikemccand@apache.org>
Committed: Wed Aug 3 14:30:44 2016 -0400

----------------------------------------------------------------------
 .../apache/lucene/util/TestMSBRadixSorter.java  | 65 ++++++++++++++++++++
 1 file changed, 65 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/03138e76/lucene/core/src/test/org/apache/lucene/util/TestMSBRadixSorter.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestMSBRadixSorter.java b/lucene/core/src/test/org/apache/lucene/util/TestMSBRadixSorter.java
index c496ff8..52eb494 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestMSBRadixSorter.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestMSBRadixSorter.java
@@ -17,6 +17,8 @@
 package org.apache.lucene.util;
 
 import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
 
 public class TestMSBRadixSorter extends LuceneTestCase {
 
@@ -117,4 +119,67 @@ public class TestMSBRadixSorter extends LuceneTestCase {
       testRandom(TestUtil.nextInt(random(), 1, 30), 2);
     }
   }
+
+  public void testRandom2() {
+    // how large our alphabet is
+    int letterCount = TestUtil.nextInt(random(), 2, 10);
+
+    // how many substring fragments to use
+    int substringCount = TestUtil.nextInt(random(), 2, 10);
+    Set<BytesRef> substringsSet = new HashSet<>();
+
+    // how many strings to make
+    int stringCount = atLeast(10000);
+
+    //System.out.println("letterCount=" + letterCount + " substringCount=" + substringCount
+ " stringCount=" + stringCount);
+    while(substringsSet.size() < substringCount) {
+      int length = TestUtil.nextInt(random(), 2, 10);
+      byte[] bytes = new byte[length];
+      for(int i=0;i<length;i++) {
+        bytes[i] = (byte) random().nextInt(letterCount);
+      }
+      BytesRef br = new BytesRef(bytes);
+      substringsSet.add(br);
+      //System.out.println("add substring count=" + substringsSet.size() + ": " + br);
+    }
+
+    BytesRef[] substrings = substringsSet.toArray(new BytesRef[substringsSet.size()]);
+    double[] chance = new double[substrings.length];
+    double sum = 0.0;
+    for(int i=0;i<substrings.length;i++) {
+      chance[i] = random().nextDouble();
+      sum += chance[i];
+    }
+
+    // give each substring a random chance of occurring:
+    double accum = 0.0;
+    for(int i=0;i<substrings.length;i++) {
+      accum += chance[i]/sum;
+      chance[i] = accum;
+    }
+
+    Set<BytesRef> stringsSet = new HashSet<>();
+    int iters = 0;
+    while (stringsSet.size() < stringCount && iters < stringCount*5) {
+      int count = TestUtil.nextInt(random(), 1, 5);
+      BytesRefBuilder b = new BytesRefBuilder();
+      for(int i=0;i<count;i++) {
+        double v = random().nextDouble();
+        accum = 0.0;
+        for(int j=0;j<substrings.length;j++) {
+          accum += chance[j];
+          if (accum >= v) {
+            b.append(substrings[j]);
+            break;
+          }
+        }
+      }
+      BytesRef br = b.toBytesRef();
+      stringsSet.add(br);
+      //System.out.println("add string count=" + stringsSet.size() + ": " + br);
+      iters++;
+    }
+
+    test(stringsSet.toArray(new BytesRef[stringsSet.size()]), stringsSet.size());
+  }
 }


Mime
View raw message