| 1 |
|
package org.apache.lucene.search; |
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
import java.util.Random; |
| 20 |
|
|
| 21 |
|
import junit.framework.TestCase; |
| 22 |
|
|
| 23 |
|
import org.apache.lucene.analysis.SimpleAnalyzer; |
| 24 |
|
import org.apache.lucene.document.Document; |
| 25 |
|
import org.apache.lucene.document.Field; |
| 26 |
|
import org.apache.lucene.index.IndexWriter; |
| 27 |
|
import org.apache.lucene.store.RAMDirectory; |
| 28 |
|
|
|
|
|
| 94.6% |
Uncovered Elements: 3 (56) |
Complexity: 12 |
Complexity Density: 0.31 |
|
| 29 |
|
public class BaseTestRangeFilter extends TestCase { |
| 30 |
|
|
| 31 |
|
public static final boolean F = false; |
| 32 |
|
public static final boolean T = true; |
| 33 |
|
|
| 34 |
|
RAMDirectory index = new RAMDirectory(); |
| 35 |
|
Random rand = new Random(101); |
| 36 |
|
|
| 37 |
|
int maxR = Integer.MIN_VALUE; |
| 38 |
|
int minR = Integer.MAX_VALUE; |
| 39 |
|
|
| 40 |
|
int minId = 0; |
| 41 |
|
int maxId = 10000; |
| 42 |
|
|
| 43 |
|
static final int intLength = Integer.toString(Integer.MAX_VALUE).length(); |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
| 48 |
200070
|
public static String pad(int n) {... |
| 49 |
200070
|
StringBuffer b = new StringBuffer(40); |
| 50 |
200070
|
String p = "0"; |
| 51 |
200070
|
if (n < 0) { |
| 52 |
50510
|
p = "-"; |
| 53 |
50510
|
n = Integer.MAX_VALUE + n + 1; |
| 54 |
|
} |
| 55 |
200070
|
b.append(p); |
| 56 |
200070
|
String s = Integer.toString(n); |
| 57 |
1062974
|
for (int i = s.length(); i <= intLength; i++) { |
| 58 |
862904
|
b.append("0"); |
| 59 |
|
} |
| 60 |
200070
|
b.append(s); |
| 61 |
|
|
| 62 |
200070
|
return b.toString(); |
| 63 |
|
} |
| 64 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 65 |
10
|
public BaseTestRangeFilter(String name) {... |
| 66 |
10
|
super(name); |
| 67 |
10
|
build(); |
| 68 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 69 |
0
|
public BaseTestRangeFilter() {... |
| 70 |
0
|
build(); |
| 71 |
|
} |
| 72 |
|
|
|
|
|
| 95.5% |
Uncovered Elements: 1 (22) |
Complexity: 5 |
Complexity Density: 0.31 |
|
| 73 |
10
|
private void build() {... |
| 74 |
10
|
try { |
| 75 |
|
|
| 76 |
|
|
| 77 |
10
|
IndexWriter writer = new IndexWriter(index, |
| 78 |
|
new SimpleAnalyzer(), T); |
| 79 |
|
|
| 80 |
100020
|
for (int d = minId; d <= maxId; d++) { |
| 81 |
100010
|
Document doc = new Document(); |
| 82 |
100010
|
doc.add(new Field("id",pad(d), Field.Store.YES, Field.Index.UN_TOKENIZED)); |
| 83 |
100010
|
int r= rand.nextInt(); |
| 84 |
100010
|
if (maxR < r) { |
| 85 |
110
|
maxR = r; |
| 86 |
|
} |
| 87 |
100010
|
if (r < minR) { |
| 88 |
120
|
minR = r; |
| 89 |
|
} |
| 90 |
100010
|
doc.add(new Field("rand",pad(r), Field.Store.YES, Field.Index.UN_TOKENIZED)); |
| 91 |
100010
|
doc.add(new Field("body","body", Field.Store.YES, Field.Index.UN_TOKENIZED)); |
| 92 |
100010
|
writer.addDocument(doc); |
| 93 |
|
} |
| 94 |
|
|
| 95 |
10
|
writer.optimize(); |
| 96 |
10
|
writer.close(); |
| 97 |
|
|
| 98 |
|
} catch (Exception e) { |
| 99 |
0
|
throw new RuntimeException("can't build index", e); |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
} |
| 103 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
4
-
|
|
| 104 |
2
|
public void testPad() {... |
| 105 |
|
|
| 106 |
2
|
int[] tests = new int[] { |
| 107 |
|
-9999999, -99560, -100, -3, -1, 0, 3, 9, 10, 1000, 999999999 |
| 108 |
|
}; |
| 109 |
22
|
for (int i = 0; i < tests.length - 1; i++) { |
| 110 |
20
|
int a = tests[i]; |
| 111 |
20
|
int b = tests[i+1]; |
| 112 |
20
|
String aa = pad(a); |
| 113 |
20
|
String bb = pad(b); |
| 114 |
20
|
String label = a + ":" + aa + " vs " + b + ":" + bb; |
| 115 |
20
|
assertEquals("length of " + label, aa.length(), bb.length()); |
| 116 |
20
|
assertTrue("compare less than " + label, aa.compareTo(bb) < 0); |
| 117 |
|
} |
| 118 |
|
|
| 119 |
|
} |
| 120 |
|
|
| 121 |
|
} |