Skip to content

Commit

Permalink
BUG: Lucene.Net.Analysis.Miscellaneous.TestStemmerOverrideFilter::Tes…
Browse files Browse the repository at this point in the history
…tRandomRealisticWhiteSpace(): Ported patch from apache/lucene@bce10ef to fix rare random test failures. Fixes #896.
  • Loading branch information
NightOwl888 committed Jan 20, 2024
1 parent c1a6cac commit 6868c38
Showing 1 changed file with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using J2N.Text;
using Lucene.Net.Analysis.Core;
using Lucene.Net.Analysis.En;
using Lucene.Net.Analysis.Util;
using Lucene.Net.Attributes;
using Lucene.Net.Util;
using NUnit.Framework;
Expand Down Expand Up @@ -99,7 +100,14 @@ public virtual void TestNoOverrides()
public virtual void TestRandomRealisticWhiteSpace()
{
IDictionary<string, string> map = new Dictionary<string, string>();
// LUCENENET: Ported the patch from https://github.com/apache/lucene/commit/bce10efeb40c11271cb398c37b859408818b8a00
// so we don't have random failures.
ISet<string> seen = new HashSet<string>();
int numTerms = AtLeast(50);
bool ignoreCase = Random.nextBoolean();

CharacterUtils charUtils = CharacterUtils.GetInstance(TEST_VERSION_CURRENT);

for (int i = 0; i < numTerms; i++)
{
string randomRealisticUnicodeString = TestUtil.RandomRealisticUnicodeString(Random);
Expand All @@ -116,16 +124,36 @@ public virtual void TestRandomRealisticWhiteSpace()
}
if (sb.Length > 0)
{
string value = TestUtil.RandomSimpleString(Random);
map[sb.ToString()] = value.Length == 0 ? "a" : value;
string inputValue = sb.ToString();

// Make sure we don't try to add two inputs that vary only by case:
string seenInputValue;
if (ignoreCase)
{
// TODO: can we simply use inputValue.toLowerCase(Locale.ROOT)???
char[] buffer = inputValue.ToCharArray();
charUtils.ToLower(buffer, 0, buffer.Length);
seenInputValue = buffer.ToString();
}
else
{
seenInputValue = inputValue;
}

if (seen.Contains(seenInputValue) == false)
{
seen.Add(seenInputValue);
string value = TestUtil.RandomSimpleString(Random);
map[inputValue] =
value == string.Empty ? "a" : value;
}
}
}
if (map.Count == 0)
{
map["booked"] = "books";
}
StemmerOverrideFilter.Builder builder = new StemmerOverrideFilter.Builder(Random.nextBoolean());
StemmerOverrideFilter.Builder builder = new StemmerOverrideFilter.Builder(ignoreCase);
IDictionary<string, string> entrySet = map;
StringBuilder input = new StringBuilder();
IList<string> output = new JCG.List<string>();
Expand Down

0 comments on commit 6868c38

Please sign in to comment.