From 11bed874c2f4f0349a8de868201d718dd0e6fa21 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 2 May 2011 15:23:22 +0000 Subject: [PATCH] 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 --- .../apache/lucene/util/TestBytesRefHash.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lucene/src/test/org/apache/lucene/util/TestBytesRefHash.java b/lucene/src/test/org/apache/lucene/util/TestBytesRefHash.java index 2c82aea6ff3..a0739372c52 100644 --- a/lucene/src/test/org/apache/lucene/util/TestBytesRefHash.java +++ b/lucene/src/test/org/apache/lucene/util/TestBytesRefHash.java @@ -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());