LUCENE-3062: Fix test to be more tolerant and accept duplicates generated by randomRealisticUnicodeString

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1098625 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Simon Willnauer 2011-05-02 15:23:22 +00:00
parent 744840f141
commit 11bed874c2
1 changed files with 13 additions and 4 deletions

View File

@ -135,6 +135,7 @@ public class TestBytesRefHash extends LuceneTestCase {
public void testCompact() {
BytesRef ref = new BytesRef();
for (int j = 0; j < 2 * RANDOM_MULTIPLIER; j++) {
int numEntries = 0;
final int size = 797;
BitSet bits = new BitSet(size);
for (int i = 0; i < size; i++) {
@ -143,13 +144,21 @@ public class TestBytesRefHash extends LuceneTestCase {
str = _TestUtil.randomRealisticUnicodeString(random, 1000);
} while (str.length() == 0);
ref.copy(str);
bits.set(hash.add(ref));
final int key = hash.add(ref);
if (key < 0) {
assertTrue(bits.get((-key)-1));
} else {
assertFalse(bits.get(key));
bits.set(key);
numEntries++;
}
}
assertEquals(hash.size(), bits.cardinality());
assertEquals(numEntries, bits.cardinality());
assertEquals(numEntries, hash.size());
int[] compact = hash.compact();
assertTrue(size < compact.length);
for (int i = 0; i < size; i++) {
assertTrue(numEntries < compact.length);
for (int i = 0; i < numEntries; i++) {
bits.set(compact[i], false);
}
assertEquals(0, bits.cardinality());