diff --git a/.editorconfig b/.editorconfig index 46bd2ece87..090a230876 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,6 +4,8 @@ [*] charset = utf-8-bom trim_trailing_whitespace = true +insert_final_newline = true +resharper_enforce_empty_line_at_end_of_file = true [*.md] indent_style = space @@ -189,4 +191,4 @@ dotnet_diagnostic.IDE0070.severity = none ### SonarCloud Issues ### # S907: Remove this use of 'goto' -dotnet_diagnostic.S907.severity = none \ No newline at end of file +dotnet_diagnostic.S907.severity = none diff --git a/.idea/.idea.Lucene.Net/.idea/.gitignore b/.idea/.idea.Lucene.Net/.idea/.gitignore new file mode 100644 index 0000000000..e4c6e33706 --- /dev/null +++ b/.idea/.idea.Lucene.Net/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/contentModel.xml +/.idea.Lucene.Net.iml +/projectSettingsUpdater.xml +/modules.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.idea.Lucene.Net/.idea/.name b/.idea/.idea.Lucene.Net/.idea/.name new file mode 100644 index 0000000000..79a5e09981 --- /dev/null +++ b/.idea/.idea.Lucene.Net/.idea/.name @@ -0,0 +1 @@ +Lucene.Net \ No newline at end of file diff --git a/.idea/.idea.Lucene.Net/.idea/encodings.xml b/.idea/.idea.Lucene.Net/.idea/encodings.xml new file mode 100644 index 0000000000..df87cf951f --- /dev/null +++ b/.idea/.idea.Lucene.Net/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.Lucene.Net/.idea/indexLayout.xml b/.idea/.idea.Lucene.Net/.idea/indexLayout.xml new file mode 100644 index 0000000000..7b08163ceb --- /dev/null +++ b/.idea/.idea.Lucene.Net/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Lucene.Net/.idea/vcs.xml b/.idea/.idea.Lucene.Net/.idea/vcs.xml new file mode 100644 index 0000000000..35eb1ddfbb --- /dev/null +++ b/.idea/.idea.Lucene.Net/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Directory.Build.targets b/Directory.Build.targets index 92406f90f8..c39e315ef9 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -26,6 +26,7 @@ $(DefineConstants);FEATURE_SPANFORMATTABLE + $(DefineConstants);FEATURE_RANDOM_NEXTINT64_NEXTSINGLE diff --git a/build b/build old mode 100644 new mode 100755 diff --git a/src/Lucene.Net.Tests.Expressions/JS/TestJavascriptOperations.cs b/src/Lucene.Net.Tests.Expressions/JS/TestJavascriptOperations.cs index 2422201cdd..2bcea6cc3f 100644 --- a/src/Lucene.Net.Tests.Expressions/JS/TestJavascriptOperations.cs +++ b/src/Lucene.Net.Tests.Expressions/JS/TestJavascriptOperations.cs @@ -1,5 +1,7 @@ using Lucene.Net.Util; using NUnit.Framework; +using System; +using System.Runtime.InteropServices; using Assert = Lucene.Net.TestFramework.Assert; namespace Lucene.Net.Expressions.JS @@ -23,7 +25,7 @@ namespace Lucene.Net.Expressions.JS public class TestJavascriptOperations : LuceneTestCase { - + private void AssertEvaluatesTo(string expression, long expected) { Expression evaluator = JavascriptCompiler.Compile(expression); @@ -91,8 +93,17 @@ public virtual void TestDivisionOperation() AssertEvaluatesTo("10/5/2", 1); AssertEvaluatesTo("(27/9)/3", 1); AssertEvaluatesTo("27/(9/3)", 9); - //.NET Port division overflow cast to double evals to long.MinValue - AssertEvaluatesTo("1/0", -9223372036854775808); + // LUCENENET: division overflow cast to double then to long evaluates to long.MinValue, except on arm64 + // where it matches Java's behavior and Lucene's assertion. This only happens with the conv.i8 opcode with + // positive infinity on the stack. 1.0 / 0.0 == double.PositiveInfinity. In C#, if you cast + // double.PositiveInfinity to long in an unchecked context it returns 0. The C# spec for conversion in an + // unchecked context from double to long states "If the value of the operand is NaN or infinite, the result + // of the conversion is an unspecified value of the destination type." Likewise, the docs for conv.i8 state + // "If overflow occurs converting a floating-point type to an integer the value returned is unspecified." + // Essentially this is undefined behavior, so we are going to assert an architecture-specific value + // primarily to ensure it produces something rather than throws. CPU architectures other than arm64, x86, + // and x64 may produce different results. + AssertEvaluatesTo("1/0", RuntimeInformation.ProcessArchitecture == Architecture.Arm64 ? 9223372036854775807 : -9223372036854775808); } [Test] @@ -373,7 +384,7 @@ public virtual void TestHexConst2() AssertEvaluatesTo("0X0", 0); AssertEvaluatesTo("0X1", 1); AssertEvaluatesTo("0XF", 15); - AssertEvaluatesTo("0X1234ABCDEF", 78193085935L); + AssertEvaluatesTo("0X1234ABCDEF", 78193085935L); } [Test] diff --git a/src/Lucene.Net.Tests/Util/Automaton/TestBasicOperations.cs b/src/Lucene.Net.Tests/Util/Automaton/TestBasicOperations.cs index 456de6e36b..9879c64749 100644 --- a/src/Lucene.Net.Tests/Util/Automaton/TestBasicOperations.cs +++ b/src/Lucene.Net.Tests/Util/Automaton/TestBasicOperations.cs @@ -180,4 +180,4 @@ public virtual void TestGetRandomAcceptedString() } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/Automaton/TestCompiledAutomaton.cs b/src/Lucene.Net.Tests/Util/Automaton/TestCompiledAutomaton.cs index 1e970ad26b..f882b146af 100644 --- a/src/Lucene.Net.Tests/Util/Automaton/TestCompiledAutomaton.cs +++ b/src/Lucene.Net.Tests/Util/Automaton/TestCompiledAutomaton.cs @@ -2,7 +2,6 @@ using NUnit.Framework; using System; using System.Collections.Generic; -using System.Linq; using Assert = Lucene.Net.TestFramework.Assert; using Console = Lucene.Net.Util.SystemConsole; using JCG = J2N.Collections.Generic; @@ -148,4 +147,4 @@ public virtual void TestBasic() TestFloor(c, "zzz", "goo"); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/Automaton/TestDeterminism.cs b/src/Lucene.Net.Tests/Util/Automaton/TestDeterminism.cs index aab64f6162..13f3686af5 100644 --- a/src/Lucene.Net.Tests/Util/Automaton/TestDeterminism.cs +++ b/src/Lucene.Net.Tests/Util/Automaton/TestDeterminism.cs @@ -35,7 +35,7 @@ public virtual void TestRegexps() int num = AtLeast(500); for (int i = 0; i < num; i++) { - AssertAutomaton((new RegExp(AutomatonTestUtil.RandomRegexp(Random), RegExpSyntax.NONE)).ToAutomaton()); + AssertAutomaton(new RegExp(AutomatonTestUtil.RandomRegexp(Random), RegExpSyntax.NONE).ToAutomaton()); } } @@ -89,4 +89,4 @@ private static void AssertAutomaton(Automaton a) } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/Automaton/TestDeterminizeLexicon.cs b/src/Lucene.Net.Tests/Util/Automaton/TestDeterminizeLexicon.cs index a468d1ea3e..46794317c6 100644 --- a/src/Lucene.Net.Tests/Util/Automaton/TestDeterminizeLexicon.cs +++ b/src/Lucene.Net.Tests/Util/Automaton/TestDeterminizeLexicon.cs @@ -71,4 +71,4 @@ public void AssertLexicon() } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/Automaton/TestLevenshteinAutomata.cs b/src/Lucene.Net.Tests/Util/Automaton/TestLevenshteinAutomata.cs index 15074fd30c..bc481d0fd4 100644 --- a/src/Lucene.Net.Tests/Util/Automaton/TestLevenshteinAutomata.cs +++ b/src/Lucene.Net.Tests/Util/Automaton/TestLevenshteinAutomata.cs @@ -53,7 +53,7 @@ public virtual void TestLev2() [Test] public virtual void TestNoWastedStates() { - AutomatonTestUtil.AssertNoDetachedStates((new LevenshteinAutomata("abc", false)).ToAutomaton(1)); + AutomatonTestUtil.AssertNoDetachedStates(new LevenshteinAutomata("abc", false).ToAutomaton(1)); } /// @@ -435,4 +435,4 @@ private int GetTDistance(string target, string other) return Math.Abs(d[n][m]); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/Automaton/TestMinimize.cs b/src/Lucene.Net.Tests/Util/Automaton/TestMinimize.cs index b86b7ae40b..bfb9f91812 100644 --- a/src/Lucene.Net.Tests/Util/Automaton/TestMinimize.cs +++ b/src/Lucene.Net.Tests/Util/Automaton/TestMinimize.cs @@ -1,6 +1,5 @@ using NUnit.Framework; using Assert = Lucene.Net.TestFramework.Assert; -using Console = Lucene.Net.Util.SystemConsole; namespace Lucene.Net.Util.Automaton { @@ -250,7 +249,7 @@ public virtual void TestAgainstBrzozowski() [Test] public virtual void TestMinimizeHuge() { - (new RegExp("+-*(A|.....|BC)*]", RegExpSyntax.NONE)).ToAutomaton(); + new RegExp("+-*(A|.....|BC)*]", RegExpSyntax.NONE).ToAutomaton(); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/Automaton/TestSpecialOperations.cs b/src/Lucene.Net.Tests/Util/Automaton/TestSpecialOperations.cs index a0af00d968..ae4a83664d 100644 --- a/src/Lucene.Net.Tests/Util/Automaton/TestSpecialOperations.cs +++ b/src/Lucene.Net.Tests/Util/Automaton/TestSpecialOperations.cs @@ -59,4 +59,4 @@ public virtual void TestFiniteStrings() Assert.IsTrue(strings.Contains(duck)); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/Automaton/TestUTF32ToUTF8.cs b/src/Lucene.Net.Tests/Util/Automaton/TestUTF32ToUTF8.cs index 21656909ba..42e7125b24 100644 --- a/src/Lucene.Net.Tests/Util/Automaton/TestUTF32ToUTF8.cs +++ b/src/Lucene.Net.Tests/Util/Automaton/TestUTF32ToUTF8.cs @@ -244,7 +244,7 @@ public void TestRandomRegexes() int num = AtLeast(250); for (int i = 0; i < num; i++) { - AssertAutomaton((new RegExp(AutomatonTestUtil.RandomRegexp(Random), RegExpSyntax.NONE)).ToAutomaton()); + AssertAutomaton(new RegExp(AutomatonTestUtil.RandomRegexp(Random), RegExpSyntax.NONE).ToAutomaton()); } } @@ -286,4 +286,4 @@ private static void AssertAutomaton(Automaton automaton) } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/BaseSortTestCase.cs b/src/Lucene.Net.Tests/Util/BaseSortTestCase.cs index 364504b9cb..6ed41f97bb 100644 --- a/src/Lucene.Net.Tests/Util/BaseSortTestCase.cs +++ b/src/Lucene.Net.Tests/Util/BaseSortTestCase.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using Lucene.Net.Support; using NUnit.Framework; using System; @@ -44,18 +43,19 @@ public virtual int CompareTo(Entry other) } private readonly bool stable; - private readonly Random random; protected BaseSortTestCase(bool stable) { this.stable = stable; - this.random = Random; } public abstract Sorter NewSorter(Entry[] arr); + // LUCENENET specific public class StableEntryComparer : IComparer { + public static readonly StableEntryComparer Default = new StableEntryComparer(); + public int Compare(Entry a, Entry b) { if (a.Value < b.Value) return -1; @@ -69,7 +69,8 @@ public int Compare(Entry a, Entry b) public virtual void AssertSorted(Entry[] original, Entry[] sorted) { Assert.AreEqual(original.Length, sorted.Length); - Entry[] stableSorted = original.OrderBy(e => e, new StableEntryComparer()).ToArray(); + Entry[] stableSorted = Arrays.CopyOf(original, original.Length); + Array.Sort(stableSorted, StableEntryComparer.Default); // LUCENENET: use StableEntryComparer for (int i = 0; i < original.Length; ++i) { Assert.AreEqual(stableSorted[i].Value, sorted[i].Value); @@ -82,8 +83,8 @@ public virtual void AssertSorted(Entry[] original, Entry[] sorted) public virtual void SortTest(Entry[] arr) { - int o = random.Next(1000); - var toSort = new Entry[o + arr.Length + random.Next(3)]; + int o = Random.Next(1000); + var toSort = new Entry[o + arr.Length + Random.Next(3)]; Arrays.Copy(arr, 0, toSort, o, arr.Length); Sorter sorter = NewSorter(toSort); sorter.Sort(o, o + arr.Length); @@ -94,50 +95,47 @@ public virtual void SortTest(Entry[] arr) private void RandomStrategy(Entry[] arr, int i) { - arr[i] = new Entry(random.Next(), i); + arr[i] = new Entry(Random.Next(), i); } private void RandomLowCardinalityStrategy(Entry[] arr, int i) { - arr[i] = new Entry(random.nextInt(6), i); + arr[i] = new Entry(Random.nextInt(6), i); } private void AscendingStrategy(Entry[] arr, int i) { arr[i] = i == 0 - ? new Entry(random.nextInt(6), 0) - : new Entry(arr[i - 1].Value + random.nextInt(6), i); + ? new Entry(Random.nextInt(6), 0) + : new Entry(arr[i - 1].Value + Random.nextInt(6), i); } private void DescendingStrategy(Entry[] arr, int i) { arr[i] = i == 0 - ? new Entry(random.nextInt(6), 0) - : new Entry(arr[i - 1].Value - random.nextInt(6), i); + ? new Entry(Random.nextInt(6), 0) + : new Entry(arr[i - 1].Value - Random.nextInt(6), i); } - + private void StrictlyDescendingStrategy(Entry[] arr, int i) { arr[i] = i == 0 - ? new Entry(random.nextInt(6), 0) - : new Entry(arr[i - 1].Value - TestUtil.NextInt32(random, 1, 5), i); - + ? new Entry(Random.nextInt(6), 0) + : new Entry(arr[i - 1].Value - TestUtil.NextInt32(Random, 1, 5), i); } private void AscendingSequencesStrategy(Entry[] arr, int i) { arr[i] = i == 0 - ? new Entry(random.nextInt(6), 0) - : new Entry(Rarely(random) ? random.nextInt(1000) : arr[i - 1].Value + random.nextInt(6), i); - + ? new Entry(Random.nextInt(6), 0) + : new Entry(Rarely(Random) ? Random.nextInt(1000) : arr[i - 1].Value + Random.nextInt(6), i); } - + private void MostlyAscendingStrategy(Entry[] arr, int i) { arr[i] = i == 0 - ? new Entry(random.nextInt(6), 0) - : new Entry(arr[i - 1].Value + TestUtil.NextInt32(random, -8, 10), i); - + ? new Entry(Random.nextInt(6), 0) + : new Entry(arr[i - 1].Value + TestUtil.NextInt32(Random, -8, 10), i); } private void DoTest(Strategy strategy, int length) @@ -169,7 +167,7 @@ public virtual void TestOne() [Test] public virtual void TestTwo() { - DoTest(RandomStrategy, 2); + DoTest(RandomLowCardinalityStrategy, 2); } [Test] @@ -181,31 +179,31 @@ public virtual void TestRandom() [Test] public virtual void TestRandomLowCardinality() { - DoTest(RandomLowCardinalityStrategy, 2); + DoTest(RandomLowCardinalityStrategy); } [Test] public virtual void TestAscending() { - DoTest(AscendingStrategy, 2); + DoTest(AscendingStrategy); } [Test] public virtual void TestAscendingSequences() { - DoTest(AscendingSequencesStrategy, 2); + DoTest(AscendingSequencesStrategy); } [Test] public virtual void TestDescending() { - DoTest(DescendingStrategy, 2); + DoTest(DescendingStrategy); } [Test] public virtual void TestStrictlyDescendingStrategy() { - DoTest(StrictlyDescendingStrategy, 2); + DoTest(StrictlyDescendingStrategy); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/Fst/Test2BFST.cs b/src/Lucene.Net.Tests/Util/Fst/Test2BFST.cs index 3867046094..ff321b8367 100644 --- a/src/Lucene.Net.Tests/Util/Fst/Test2BFST.cs +++ b/src/Lucene.Net.Tests/Util/Fst/Test2BFST.cs @@ -1,11 +1,14 @@ using Lucene.Net.Support; using NUnit.Framework; -using RandomizedTesting.Generators; using System; using Assert = Lucene.Net.TestFramework.Assert; using Console = Lucene.Net.Util.SystemConsole; using Int64 = J2N.Numerics.Int64; +#if !FEATURE_RANDOM_NEXTINT64_NEXTSINGLE +using RandomizedTesting.Generators; // for Random.NextInt64 extension method +#endif + namespace Lucene.Net.Util.Fst { /* @@ -338,4 +341,4 @@ private void NextInput(Random r, int[] ints) } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/Fst/TestBytesStore.cs b/src/Lucene.Net.Tests/Util/Fst/TestBytesStore.cs index f652109d94..3f0bc46638 100644 --- a/src/Lucene.Net.Tests/Util/Fst/TestBytesStore.cs +++ b/src/Lucene.Net.Tests/Util/Fst/TestBytesStore.cs @@ -428,4 +428,4 @@ private void Verify(BytesStore bytes, byte[] expected, int totalLength) } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/Fst/TestFSTs.cs b/src/Lucene.Net.Tests/Util/Fst/TestFSTs.cs index 9eaa6e14af..f21e68457d 100644 --- a/src/Lucene.Net.Tests/Util/Fst/TestFSTs.cs +++ b/src/Lucene.Net.Tests/Util/Fst/TestFSTs.cs @@ -2,7 +2,6 @@ using J2N.Threading.Atomic; using Lucene.Net.Diagnostics; using Lucene.Net.Index.Extensions; -using Lucene.Net.Support; using Lucene.Net.Util.Automaton; using NUnit.Framework; using RandomizedTesting.Generators; @@ -10,7 +9,6 @@ using System.Collections.Generic; using System.Globalization; using System.IO; -using System.Linq; using System.Text; using Assert = Lucene.Net.TestFramework.Assert; using Console = Lucene.Net.Util.SystemConsole; @@ -128,7 +126,7 @@ public virtual void TestBasicFSA() { pairs.Add(new InputOutput(term, NO_OUTPUT)); } - FST fst = (new FSTTester(Random, dir, inputMode, pairs, outputs, false)).DoTest(0, 0, false); + FST fst = new FSTTester(Random, dir, inputMode, pairs, outputs, false).DoTest(0, 0, false); Assert.IsNotNull(fst); Assert.AreEqual(22, fst.NodeCount); Assert.AreEqual(27, fst.ArcCount); @@ -142,7 +140,7 @@ public virtual void TestBasicFSA() { pairs.Add(new InputOutput(terms2[idx], idx)); } - FST fst = (new FSTTester(Random, dir, inputMode, pairs, outputs, true)).DoTest(0, 0, false); + FST fst = new FSTTester(Random, dir, inputMode, pairs, outputs, true).DoTest(0, 0, false); Assert.IsNotNull(fst); Assert.AreEqual(22, fst.NodeCount); Assert.AreEqual(27, fst.ArcCount); @@ -158,7 +156,7 @@ public virtual void TestBasicFSA() BytesRef output = Random.Next(30) == 17 ? NO_OUTPUT : new BytesRef(Convert.ToString(idx)); pairs.Add(new InputOutput(terms2[idx], output)); } - FST fst = (new FSTTester(Random, dir, inputMode, pairs, outputs, false)).DoTest(0, 0, false); + FST fst = new FSTTester(Random, dir, inputMode, pairs, outputs, false).DoTest(0, 0, false); Assert.IsNotNull(fst); Assert.AreEqual(24, fst.NodeCount); Assert.AreEqual(30, fst.ArcCount); @@ -180,7 +178,7 @@ private void DoTest(int inputMode, Int32sRef[] terms) { pairs.Add(new InputOutput(term, NO_OUTPUT)); } - (new FSTTester(Random, dir, inputMode, pairs, outputs, false)).DoTest(true); + new FSTTester(Random, dir, inputMode, pairs, outputs, false).DoTest(true); } // PositiveIntOutput (ord) @@ -191,7 +189,7 @@ private void DoTest(int inputMode, Int32sRef[] terms) { pairs.Add(new InputOutput(terms[idx], idx)); } - (new FSTTester(Random, dir, inputMode, pairs, outputs, true)).DoTest(true); + new FSTTester(Random, dir, inputMode, pairs, outputs, true).DoTest(true); } // PositiveIntOutput (random monotonically increasing positive number) @@ -205,7 +203,7 @@ private void DoTest(int inputMode, Int32sRef[] terms) lastOutput = value; pairs.Add(new InputOutput(terms[idx], value)); } - (new FSTTester(Random, dir, inputMode, pairs, outputs, true)).DoTest(true); + new FSTTester(Random, dir, inputMode, pairs, outputs, true).DoTest(true); } // PositiveIntOutput (random positive number) @@ -216,7 +214,7 @@ private void DoTest(int inputMode, Int32sRef[] terms) { pairs.Add(new InputOutput(terms[idx], TestUtil.NextInt64(Random, 0, long.MaxValue))); } - (new FSTTester(Random, dir, inputMode, pairs, outputs, false)).DoTest(true); + new FSTTester(Random, dir, inputMode, pairs, outputs, false).DoTest(true); } // Pair @@ -232,7 +230,7 @@ private void DoTest(int inputMode, Int32sRef[] terms) lastOutput = value; pairs.Add(new InputOutput(terms[idx], outputs.NewPair(idx, value))); } - (new FSTTester(Random, dir, inputMode, pairs, outputs, false)).DoTest(true); + new FSTTester(Random, dir, inputMode, pairs, outputs, false).DoTest(true); } // Sequence-of-bytes @@ -245,7 +243,7 @@ private void DoTest(int inputMode, Int32sRef[] terms) BytesRef output = Random.Next(30) == 17 ? NO_OUTPUT : new BytesRef(Convert.ToString(idx)); pairs.Add(new InputOutput(terms[idx], output)); } - (new FSTTester(Random, dir, inputMode, pairs, outputs, false)).DoTest(true); + new FSTTester(Random, dir, inputMode, pairs, outputs, false).DoTest(true); } // Sequence-of-ints @@ -265,7 +263,7 @@ private void DoTest(int inputMode, Int32sRef[] terms) } pairs.Add(new InputOutput(terms[idx], output)); } - (new FSTTester(Random, dir, inputMode, pairs, outputs, false)).DoTest(true); + new FSTTester(Random, dir, inputMode, pairs, outputs, false).DoTest(true); } } @@ -376,7 +374,7 @@ public virtual void TestRealTerms() BytesRef term; int ord = 0; - Automaton automaton = (new RegExp(".*", RegExpSyntax.NONE)).ToAutomaton(); + Automaton automaton = new RegExp(".*", RegExpSyntax.NONE).ToAutomaton(); TermsEnum termsEnum2 = terms.Intersect(new CompiledAutomaton(automaton, false, false), null); while (termsEnum.MoveNext()) @@ -392,7 +390,7 @@ public virtual void TestRealTerms() { try { - var _ = termsEnum.Ord; + _ = termsEnum.Ord; // LUCENENET: using discard assignment to avoid "Only ... can be used as a statement" error } catch (Exception uoe) when (uoe.IsUnsupportedOperationException()) { @@ -813,7 +811,7 @@ public virtual void Run(int limit, bool verify, bool verifyByOutput) object NO_OUTPUT = outputs.NoOutput; new VisitTermsAnonymousClass4(dirOut, wordsFileIn, inputMode, prune, outputs, doPack, noArcArrays, NO_OUTPUT).Run(limit, verify, false); } - }*/ + } private sealed class VisitTermsAnonymousClass : VisitTerms { @@ -881,7 +879,7 @@ protected internal override object GetOutput(Int32sRef input, int ord) { return NO_OUTPUT; } - } + }*/ [Test] public virtual void TestSingleString() @@ -923,16 +921,16 @@ public virtual void TestDuplicateFSAString() /* public void testTrivial() throws Exception { - + // Get outputs -- passing true means FST will share // (delta code) the outputs. this should result in // smaller FST if the outputs grow monotonically. But // if numbers are "random", false should give smaller // final size: final NoOutputs outputs = NoOutputs.getSingleton(); - + String[] strings = new String[] {"station", "commotion", "elation", "elastic", "plastic", "stop", "ftop", "ftation", "stat"}; - + final Builder builder = new Builder(FST.INPUT_TYPE.BYTE1, 0, 0, true, @@ -951,9 +949,9 @@ public void testTrivial() throws Exception { Writer w = new OutputStreamWriter(new FileOutputStream("/mnt/scratch/before.dot")); Util.toDot(fst, w, false, false); w.Dispose(); - + final FST rewrite = new FST(fst, 1, 100); - + System.out.println("DOT after rewrite"); w = new OutputStreamWriter(new FileOutputStream("/mnt/scratch/after.dot")); Util.toDot(rewrite, w, false, false); @@ -1251,6 +1249,8 @@ public virtual void TestRandomTermLookup() [Test] public virtual void TestExpandedCloseToRoot() { + // LUCENENET: Local class moved to SyntheticData class below + // Sanity check. Assert.IsTrue(FST.FIXED_ARRAY_NUM_ARCS_SHALLOW < FST.FIXED_ARRAY_NUM_ARCS_DEEP); Assert.IsTrue(FST.FIXED_ARRAY_SHALLOW_DISTANCE >= 0); @@ -1451,7 +1451,7 @@ private void CheckStopNodes(FST fst, PositiveInt32Outputs outputs) } internal static readonly IComparer minLongComparer = Comparer.Create((left, right)=> left.CompareTo(right)); - + [Test] public virtual void TestShortestPaths() { @@ -1505,7 +1505,7 @@ public virtual void TestRejectNoLimits() Assert.AreEqual(1, res.TopN.Count); Assert.AreEqual(Util.ToInt32sRef(new BytesRef("aac"), scratch), res.TopN[0].Input); Assert.AreEqual(7L, res.TopN[0].Output); - rejectCount.Value = (0); + rejectCount.Value = 0; searcher = new TopNSearcherAnonymousClass2(fst, minLongComparer, rejectCount); searcher.AddStartPaths(fst.GetFirstArc(new FST.Arc()), outputs.NoOutput, true, new Int32sRef()); @@ -1558,7 +1558,7 @@ protected override bool AcceptResult(Int32sRef input, Int64 output) // compares just the weight side of the pair internal static readonly IComparer minPairWeightComparer = Comparer.Create((left, right)=> left.Output1.CompareTo(right.Output1)); - + /// /// like testShortestPaths, but uses pairoutputs so we have both a weight and an output [Test] @@ -1868,4 +1868,4 @@ public virtual void TestLargeOutputsOnArrayArcs() } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/Packed/TestEliasFanoDocIdSet.cs b/src/Lucene.Net.Tests/Util/Packed/TestEliasFanoDocIdSet.cs index 6d1241dcd3..bff040174a 100644 --- a/src/Lucene.Net.Tests/Util/Packed/TestEliasFanoDocIdSet.cs +++ b/src/Lucene.Net.Tests/Util/Packed/TestEliasFanoDocIdSet.cs @@ -26,7 +26,7 @@ public class TestEliasFanoDocIdSet : BaseDocIdSetTestCase { public override EliasFanoDocIdSet CopyOf(BitSet bs, int numBits) { - EliasFanoDocIdSet set = new EliasFanoDocIdSet((int)bs.Cardinality, numBits - 1); + EliasFanoDocIdSet set = new EliasFanoDocIdSet(bs.Cardinality, numBits - 1); set.EncodeFromDisi(new DocIdSetIteratorAnonymousClass(bs, numBits)); return set; } @@ -40,10 +40,9 @@ public DocIdSetIteratorAnonymousClass(BitSet bs, int numBits) { this.bs = bs; this.numBits = numBits; - doc = -1; } - internal int doc; + int doc = -1; public override int NextDoc() { @@ -69,4 +68,4 @@ public override int Advance(int target) } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/Packed/TestEliasFanoSequence.cs b/src/Lucene.Net.Tests/Util/Packed/TestEliasFanoSequence.cs index ee29105fa8..688e2de2f7 100644 --- a/src/Lucene.Net.Tests/Util/Packed/TestEliasFanoSequence.cs +++ b/src/Lucene.Net.Tests/Util/Packed/TestEliasFanoSequence.cs @@ -294,6 +294,7 @@ public virtual void TestHashCodeEquals() [Test] public virtual void TestMonotoneSequences() { + // LUCENENET: See TestMonotoneSequencesLonger below for 4422 case from original Lucene test for (int s = 2; s < 1222; s++) { long[] values = new long[s]; @@ -322,6 +323,7 @@ public virtual void TestMonotoneSequencesLonger() [Test] public virtual void TestStrictMonotoneSequences() { + // LUCENENET: See TestStrictMonotoneSequencesLonger below for 4422 case from original Lucene test for (int s = 2; s < 1222; s++) { var values = new long[s]; @@ -494,4 +496,4 @@ public virtual void TestExample2NoIndex2() // Figure 2 from Vigna 2012 paper, no Assert.AreEqual(32, efDecVI.AdvanceToValue(22), "advance 22"); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/Packed/TestPackedInts.cs b/src/Lucene.Net.Tests/Util/Packed/TestPackedInts.cs index bd60e05544..a43f3195e8 100644 --- a/src/Lucene.Net.Tests/Util/Packed/TestPackedInts.cs +++ b/src/Lucene.Net.Tests/Util/Packed/TestPackedInts.cs @@ -7,7 +7,6 @@ using System.Collections.Generic; using System.Globalization; using JCG = J2N.Collections.Generic; -using Assert = Lucene.Net.TestFramework.Assert; using Console = Lucene.Net.Util.SystemConsole; using RandomInts = RandomizedTesting.Generators.RandomNumbers; @@ -505,7 +504,7 @@ public virtual void TestSecondaryBlockChange() /* Check if the structures properly handle the case where index * bitsPerValue > Integer.MAX_VALUE - + NOTE: this test allocates 256 MB */ [Ignore("See LUCENE-4488 - LUCENENET NOTE: In .NET it is not possible to catch OOME")] @@ -1343,7 +1342,7 @@ public virtual void TestBlockPackedReaderWriter() in1.ReadBytes(buf, 0, (int)fp); in1.Seek(0L); ByteArrayDataInput in2 = new ByteArrayDataInput(buf); - DataInput @in = Random.NextBoolean() ? (DataInput)in1 : in2; + DataInput @in = Random.NextBoolean() ? in1 : in2; BlockPackedReaderIterator it = new BlockPackedReaderIterator(@in, PackedInt32s.VERSION_CURRENT, blockSize, valueCount); for (int i = 0; i < valueCount; ) { @@ -1529,4 +1528,4 @@ public virtual void TestBlockReaderOverflow() } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/StressRamUsageEstimator.cs b/src/Lucene.Net.Tests/Util/StressRamUsageEstimator.cs index 769a1f92ab..523ff68936 100644 --- a/src/Lucene.Net.Tests/Util/StressRamUsageEstimator.cs +++ b/src/Lucene.Net.Tests/Util/StressRamUsageEstimator.cs @@ -2,7 +2,6 @@ using NUnit.Framework; using System; using System.Globalization; -using Assert = Lucene.Net.TestFramework.Assert; using Console = Lucene.Net.Util.SystemConsole; namespace Lucene.Net.Util @@ -26,7 +25,7 @@ namespace Lucene.Net.Util /// /// Estimates how estimates physical memory consumption - /// of Java objects. + /// of Java objects. /// [TestFixture] public class StressRamUsageEstimator : LuceneTestCase @@ -50,6 +49,8 @@ public virtual Entry CreateNext(object o) [Test] public virtual void TestChainedEstimation() { + // LUCENENET: not needed: MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); + Random rnd = Random; Entry first = new Entry(); try @@ -57,7 +58,7 @@ public virtual void TestChainedEstimation() while (true) { // Check the current memory consumption and provide the estimate. - long jvmUsed = GC.GetTotalMemory(false); + long jvmUsed = GC.GetTotalMemory(false); // LUCENENET: instead of memoryMXBean.getHeapMemoryUsage().getUsed() long estimated = RamUsageEstimator.SizeOf(first); Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0:0000000000}, {1:0000000000}", jvmUsed, estimated)); @@ -80,15 +81,17 @@ public virtual void TestChainedEstimation() [Test] public virtual void TestLargeSetOfByteArrays() { + // LUCENENET: not needed: MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); + CauseGc(); - long before = GC.GetTotalMemory(false); + long before = GC.GetTotalMemory(false); // LUCENENET: instead of memoryMXBean.getHeapMemoryUsage().getUsed() object[] all = new object[1000000]; for (int i = 0; i < all.Length; i++) { all[i] = new sbyte[Random.Next(3)]; } CauseGc(); - long after = GC.GetTotalMemory(false); + long after = GC.GetTotalMemory(false); // LUCENENET: instead of memoryMXBean.getHeapMemoryUsage().getUsed() Console.WriteLine("mx: " + RamUsageEstimator.HumanReadableUnits(after - before)); Console.WriteLine("rue: " + RamUsageEstimator.HumanReadableUnits(ShallowSizeOf(all))); @@ -123,6 +126,8 @@ private long ShallowSizeOf(object[][] all) [Slow] public virtual void TestSimpleByteArrays() { + // LUCENENET: not needed: MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); + object[][] all = new object[0][]; try { @@ -130,14 +135,20 @@ public virtual void TestSimpleByteArrays() { // Check the current memory consumption and provide the estimate. CauseGc(); - + + // LUCENENET: not needed: MemoryUsage mu = memoryMXBean.getHeapMemoryUsage(); + long estimated = ShallowSizeOf(all); if (estimated > 50 * RamUsageEstimator.ONE_MB) { break; } - Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0}\t{1}\t{2}", RamUsageEstimator.HumanReadableUnits(GC.GetTotalMemory(false)).PadLeft(10, ' '), RamUsageEstimator.HumanReadableUnits(GC.MaxGeneration).PadLeft(10, ' '), RamUsageEstimator.HumanReadableUnits(estimated).PadLeft(10, ' '))); + // LUCENENET: padding done for each value instead of in format string + Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0}\t{1}\t{2}", + RamUsageEstimator.HumanReadableUnits(GC.GetTotalMemory(false)).PadLeft(10, ' '), // LUCENENET: GC.GetTotalMemory(false) instead of mu.getUsed() + RamUsageEstimator.HumanReadableUnits(GC.MaxGeneration).PadLeft(10, ' '), // LUCENENET: GC.MaxGeneration instead of mu.getMax() + RamUsageEstimator.HumanReadableUnits(estimated).PadLeft(10, ' '))); // Make another batch of objects. object[] seg = new object[10000]; @@ -156,12 +167,13 @@ public virtual void TestSimpleByteArrays() } /// - /// Very hacky, very crude, but (sometimes) works. - /// Don't look, it will burn your eyes out. + /// Very hacky, very crude, but (sometimes) works. + /// Don't look, it will burn your eyes out. /// private void CauseGc() { + // LUCENENET: this is way simpler than the Java equivalent here! GC.Collect(); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/Test2BPagedBytes.cs b/src/Lucene.Net.Tests/Util/Test2BPagedBytes.cs index 9e0723cebc..50106c50f4 100644 --- a/src/Lucene.Net.Tests/Util/Test2BPagedBytes.cs +++ b/src/Lucene.Net.Tests/Util/Test2BPagedBytes.cs @@ -1,10 +1,13 @@ using Lucene.Net.Diagnostics; using Lucene.Net.Store; using NUnit.Framework; -using RandomizedTesting.Generators; using System; using Assert = Lucene.Net.TestFramework.Assert; +#if !FEATURE_RANDOM_NEXTINT64_NEXTSINGLE +using RandomizedTesting.Generators; // for Random.NextInt64 extension method +#endif + namespace Lucene.Net.Util { /* @@ -30,9 +33,6 @@ namespace Lucene.Net.Util using IOContext = Lucene.Net.Store.IOContext; using MockDirectoryWrapper = Lucene.Net.Store.MockDirectoryWrapper; - //using Ignore = org.junit.Ignore; - - //ORIGINAL LINE: @Ignore("You must increase heap to > 2 G to run this") public class Test2BPagedBytes extends LuceneTestCase [Ignore("You must increase heap to > 2 G to run this")] [TestFixture] public class Test2BPagedBytes : LuceneTestCase @@ -86,4 +86,4 @@ public virtual void Test() dir.Dispose(); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestArrayUtil.cs b/src/Lucene.Net.Tests/Util/TestArrayUtil.cs index 4a56a15e3c..2fb9987efd 100644 --- a/src/Lucene.Net.Tests/Util/TestArrayUtil.cs +++ b/src/Lucene.Net.Tests/Util/TestArrayUtil.cs @@ -350,4 +350,4 @@ public virtual void TestEmptyArraySort() ArrayUtil.TimSort(a, Collections.ReverseOrder()); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestAttributeSource.cs b/src/Lucene.Net.Tests/Util/TestAttributeSource.cs index 4f4f7ba18e..36dd232533 100644 --- a/src/Lucene.Net.Tests/Util/TestAttributeSource.cs +++ b/src/Lucene.Net.Tests/Util/TestAttributeSource.cs @@ -187,4 +187,4 @@ public virtual void TestLUCENE_3042() Assert.AreEqual(src2.GetHashCode(), src1.GetHashCode()); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestBroadWord.cs b/src/Lucene.Net.Tests/Util/TestBroadWord.cs index fd90200480..a813ebffc8 100644 --- a/src/Lucene.Net.Tests/Util/TestBroadWord.cs +++ b/src/Lucene.Net.Tests/Util/TestBroadWord.cs @@ -26,6 +26,7 @@ public class TestBroadWord : LuceneTestCase { private void TstRank(long x) { + // LUCENENET: using J2N PopCount extension instead of Long.bitCount() Assert.AreEqual(x.PopCount(), BroadWord.BitCount(x), "rank(" + x + ")"); } @@ -139,7 +140,9 @@ public virtual void TestSmalleru_87_01() { long ii = i * BroadWord.L8_L; long jj = j * BroadWord.L8_L; - Assert.AreEqual(ToStringUtils.Int64Hex((i < j) ? unchecked(0x80L * BroadWord.L8_L) : 0x0L), ToStringUtils.Int64Hex(BroadWord.SmallerUpTo7_8(ii, jj)), ToStringUtils.Int64Hex(ii) + " < " + ToStringUtils.Int64Hex(jj)); + Assert.AreEqual(ToStringUtils.Int64Hex((i < j) ? unchecked(0x80L * BroadWord.L8_L) : 0x0L), + ToStringUtils.Int64Hex(BroadWord.SmallerUpTo7_8(ii, jj)), + ToStringUtils.Int64Hex(ii) + " < " + ToStringUtils.Int64Hex(jj)); } } } @@ -154,7 +157,9 @@ public virtual void TestSmalleru_8_01() { long ii = i * BroadWord.L8_L; long jj = j * BroadWord.L8_L; - Assert.AreEqual(ToStringUtils.Int64Hex((i < j) ? unchecked(0x80L * BroadWord.L8_L) : 0x0L), ToStringUtils.Int64Hex(BroadWord.Smalleru_8(ii, jj)), ToStringUtils.Int64Hex(ii) + " < " + ToStringUtils.Int64Hex(jj)); + Assert.AreEqual(ToStringUtils.Int64Hex((i < j) ? unchecked(0x80L * BroadWord.L8_L) : 0x0L), + ToStringUtils.Int64Hex(BroadWord.Smalleru_8(ii, jj)), + ToStringUtils.Int64Hex(ii) + " < " + ToStringUtils.Int64Hex(jj)); } } } @@ -166,8 +171,10 @@ public virtual void TestNotEquals0_8() for (long i = 0x0L; i <= 0xFFL; i++) { long ii = i * BroadWord.L8_L; - Assert.AreEqual(ToStringUtils.Int64Hex((i != 0L) ? unchecked(0x80L * BroadWord.L8_L) : 0x0L), ToStringUtils.Int64Hex(BroadWord.NotEquals0_8(ii)), ToStringUtils.Int64Hex(ii) + " <> 0"); + Assert.AreEqual(ToStringUtils.Int64Hex((i != 0L) ? unchecked(0x80L * BroadWord.L8_L) : 0x0L), + ToStringUtils.Int64Hex(BroadWord.NotEquals0_8(ii)), + ToStringUtils.Int64Hex(ii) + " <> 0"); } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestByteBlockPool.cs b/src/Lucene.Net.Tests/Util/TestByteBlockPool.cs index c563710f38..522f894c87 100644 --- a/src/Lucene.Net.Tests/Util/TestByteBlockPool.cs +++ b/src/Lucene.Net.Tests/Util/TestByteBlockPool.cs @@ -29,7 +29,7 @@ public class TestByteBlockPool : LuceneTestCase [Test] public virtual void TestReadAndWrite() { - Counter bytesUsed = Util.Counter.NewCounter(); + Counter bytesUsed = Counter.NewCounter(); ByteBlockPool pool = new ByteBlockPool(new ByteBlockPool.DirectTrackingAllocator(bytesUsed)); pool.NextBuffer(); bool reuseFirst = Random.NextBoolean(); @@ -69,4 +69,4 @@ public virtual void TestReadAndWrite() } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestBytesRef.cs b/src/Lucene.Net.Tests/Util/TestBytesRef.cs index 309ee15bde..c9acb68ee0 100644 --- a/src/Lucene.Net.Tests/Util/TestBytesRef.cs +++ b/src/Lucene.Net.Tests/Util/TestBytesRef.cs @@ -55,12 +55,12 @@ public virtual void TestFromChars() for (int i = 0; i < 100; i++) { string s = TestUtil.RandomUnicodeString(Random); - string s2 = (new BytesRef(s)).Utf8ToString(); + string s2 = new BytesRef(s).Utf8ToString(); Assert.AreEqual(s, s2); } // only for 4.x - Assert.AreEqual("\uFFFF", (new BytesRef("\uFFFF")).Utf8ToString()); + Assert.AreEqual("\uFFFF", new BytesRef("\uFFFF").Utf8ToString()); } [Test, LuceneNetSpecific] @@ -69,12 +69,12 @@ public virtual void TestFromCharSequence() for (int i = 0; i < 100; i++) { ICharSequence s = new StringCharSequence(TestUtil.RandomUnicodeString(Random)); - ICharSequence s2 = (new BytesRef(s)).Utf8ToString().AsCharSequence(); + ICharSequence s2 = new BytesRef(s).Utf8ToString().AsCharSequence(); Assert.AreEqual(s, s2); } // only for 4.x - Assert.AreEqual("\uFFFF", (new BytesRef("\uFFFF")).Utf8ToString()); + Assert.AreEqual("\uFFFF", new BytesRef("\uFFFF").Utf8ToString()); } // LUCENE-3590, AIOOBE if you append to a bytesref with offset != 0 @@ -120,4 +120,4 @@ public void TestSerialization() } #endif } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestBytesRefArray.cs b/src/Lucene.Net.Tests/Util/TestBytesRefArray.cs index 1c0ffc4497..1fef8e5cfa 100644 --- a/src/Lucene.Net.Tests/Util/TestBytesRefArray.cs +++ b/src/Lucene.Net.Tests/Util/TestBytesRefArray.cs @@ -31,7 +31,7 @@ public class TestBytesRefArray : LuceneTestCase public virtual void TestAppend() { Random random = Random; - BytesRefArray list = new BytesRefArray(Util.Counter.NewCounter()); + BytesRefArray list = new BytesRefArray(Counter.NewCounter()); IList stringList = new JCG.List(); for (int j = 0; j < 2; j++) { @@ -80,7 +80,7 @@ public virtual void TestAppend() public virtual void TestAppendIterator() { Random random = Random; - BytesRefArray list = new BytesRefArray(Util.Counter.NewCounter()); + BytesRefArray list = new BytesRefArray(Counter.NewCounter()); IList stringList = new JCG.List(); for (int j = 0; j < 2; j++) { @@ -114,11 +114,10 @@ public virtual void TestAppendIterator() } for (int i = 0; i < 2; i++) { - IBytesRefEnumerator iterator = list.GetEnumerator(); + IBytesRefIterator iterator = list.GetIterator(); foreach (string @string in stringList) { - Assert.IsTrue(iterator.MoveNext()); - Assert.AreEqual(@string, iterator.Current.Utf8ToString()); + Assert.AreEqual(@string, iterator.Next().Utf8ToString()); } } } @@ -128,7 +127,7 @@ public virtual void TestAppendIterator() public virtual void TestSort() { Random random = Random; - BytesRefArray list = new BytesRefArray(Util.Counter.NewCounter()); + BytesRefArray list = new BytesRefArray(Counter.NewCounter()); IList stringList = new JCG.List(); for (int j = 0; j < 2; j++) @@ -172,7 +171,7 @@ public virtual void TestSort() public virtual void TestSortIterator() { Random random = Random; - BytesRefArray list = new BytesRefArray(Util.Counter.NewCounter()); + BytesRefArray list = new BytesRefArray(Counter.NewCounter()); IList stringList = new JCG.List(); for (int j = 0; j < 2; j++) @@ -211,4 +210,4 @@ public virtual void TestSortIterator() } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestBytesRefHash.cs b/src/Lucene.Net.Tests/Util/TestBytesRefHash.cs index 8233b52364..370691fba8 100644 --- a/src/Lucene.Net.Tests/Util/TestBytesRefHash.cs +++ b/src/Lucene.Net.Tests/Util/TestBytesRefHash.cs @@ -25,7 +25,7 @@ namespace Lucene.Net.Util * limitations under the License. */ - using MaxBytesLengthExceededException = Lucene.Net.Util.BytesRefHash.MaxBytesLengthExceededException; + using MaxBytesLengthExceededException = BytesRefHash.MaxBytesLengthExceededException; [TestFixture] public class TestBytesRefHash : LuceneTestCase @@ -43,17 +43,19 @@ public override void SetUp() private ByteBlockPool NewPool() { - return Random.NextBoolean() && pool != null ? pool : new ByteBlockPool(new RecyclingByteBlockAllocator(ByteBlockPool.BYTE_BLOCK_SIZE, Random.Next(25))); + return Random.NextBoolean() && pool != null ? pool + : new ByteBlockPool(new RecyclingByteBlockAllocator(ByteBlockPool.BYTE_BLOCK_SIZE, Random.Next(25))); } private BytesRefHash NewHash(ByteBlockPool blockPool) { int initSize = 2 << 1 + Random.Next(5); - return Random.NextBoolean() ? new BytesRefHash(blockPool) : new BytesRefHash(blockPool, initSize, new BytesRefHash.DirectBytesStartArray(initSize)); + return Random.NextBoolean() ? new BytesRefHash(blockPool) : new BytesRefHash( + blockPool, initSize, new BytesRefHash.DirectBytesStartArray(initSize)); } /// - /// Test method for . + /// Test method for . /// [Test] public virtual void TestSize() @@ -93,7 +95,7 @@ public virtual void TestSize() /// /// Test method for - /// + /// /// . /// [Test] @@ -133,7 +135,7 @@ public virtual void TestGet() foreach (KeyValuePair entry in strings) { @ref.CopyChars(entry.Key); - Assert.AreEqual(@ref, hash.Get((int)entry.Value, scratch)); + Assert.AreEqual(@ref, hash.Get(entry.Value, scratch)); } hash.Clear(); Assert.AreEqual(0, hash.Count); @@ -142,7 +144,7 @@ public virtual void TestGet() } /// - /// Test method for . + /// Test method for . /// [Test] public virtual void TestCompact() @@ -192,7 +194,7 @@ public virtual void TestCompact() /// /// Test method for - /// . + /// . /// [Test] public virtual void TestSort() @@ -237,7 +239,7 @@ public virtual void TestSort() /// /// Test method for - /// + /// /// . /// [Test] @@ -331,7 +333,9 @@ public virtual void TestFind() [Test] public virtual void TestLargeValue() { - int[] sizes = { Random.Next(5), ByteBlockPool.BYTE_BLOCK_SIZE - 33 + Random.Next(31), ByteBlockPool.BYTE_BLOCK_SIZE - 1 + Random.Next(37) }; + int[] sizes = { Random.Next(5), + ByteBlockPool.BYTE_BLOCK_SIZE - 33 + Random.Next(31), + ByteBlockPool.BYTE_BLOCK_SIZE - 1 + Random.Next(37) }; BytesRef @ref = new BytesRef(); var exceptionThrown = false; @@ -362,7 +366,7 @@ public virtual void TestLargeValue() /// /// Test method for - /// + /// /// . /// [Test] @@ -443,4 +447,4 @@ private void AssertAllIn(ISet strings, BytesRefHash hash) } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestCharsRef.cs b/src/Lucene.Net.Tests/Util/TestCharsRef.cs index 18653138c7..f1bd30445b 100644 --- a/src/Lucene.Net.Tests/Util/TestCharsRef.cs +++ b/src/Lucene.Net.Tests/Util/TestCharsRef.cs @@ -118,7 +118,7 @@ public virtual void TestCopyCharsRef() Assert.AreEqual("bcde", c.ToString()); } - // LUCENENET NOTE: Removed the CharAt(int) method from the + // LUCENENET NOTE: Removed the CharAt(int) method from the // ICharSequence interface and replaced with this[int] //// LUCENE-3590: fix charsequence to fully obey interface //[Test] @@ -271,4 +271,4 @@ public void TestSerialization() } #endif } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestCloseableThreadLocal.cs b/src/Lucene.Net.Tests/Util/TestCloseableThreadLocal.cs index 730dad5254..0a8f716645 100644 --- a/src/Lucene.Net.Tests/Util/TestCloseableThreadLocal.cs +++ b/src/Lucene.Net.Tests/Util/TestCloseableThreadLocal.cs @@ -28,6 +28,7 @@ public class TestIDisposableThreadLocal : LuceneTestCase [Test] public virtual void TestInitValue() { + // LUCENENET: using DisposableThreadLocal instead of InitValueThreadLocal DisposableThreadLocal tl = new DisposableThreadLocal(() => TEST_VALUE); string str = (string)tl.Value; Assert.AreEqual(TEST_VALUE, str); @@ -38,8 +39,9 @@ public virtual void TestNullValue() { // Tests that null can be set as a valid value (LUCENE-1805). this // previously failed in get(). + // LUCENENET: using DisposableThreadLocal instead of InitValueThreadLocal DisposableThreadLocal ctl = new DisposableThreadLocal(); - ctl.Value = (null); + ctl.Value = null; Assert.IsNull(ctl.Value); } @@ -48,8 +50,9 @@ public virtual void TestDefaultValueWithoutSetting() { // LUCENE-1805: make sure default get returns null, // twice in a row + // LUCENENET: using DisposableThreadLocal instead of InitValueThreadLocal DisposableThreadLocal ctl = new DisposableThreadLocal(); Assert.IsNull(ctl.Value); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestCollectionUtil.cs b/src/Lucene.Net.Tests/Util/TestCollectionUtil.cs index c5960d0d05..018ecfb5cc 100644 --- a/src/Lucene.Net.Tests/Util/TestCollectionUtil.cs +++ b/src/Lucene.Net.Tests/Util/TestCollectionUtil.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; using JCG = J2N.Collections.Generic; -using Assert = Lucene.Net.TestFramework.Assert; namespace Lucene.Net.Util { @@ -124,4 +123,4 @@ public virtual void TestOneElementListSort() CollectionUtil.TimSort(list, Collections.ReverseOrder()); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestConstants.cs b/src/Lucene.Net.Tests/Util/TestConstants.cs index 885fc4323b..7eafb70f2e 100644 --- a/src/Lucene.Net.Tests/Util/TestConstants.cs +++ b/src/Lucene.Net.Tests/Util/TestConstants.cs @@ -26,13 +26,17 @@ namespace Lucene.Net.Util [TestFixture] public class TestConstants : LuceneTestCase { - private string VersionDetails => " (LUCENE_MAIN_VERSION=" + Constants.LUCENE_MAIN_VERSION + ", LUCENE_MAIN_VERSION(without alpha/beta)=" + Constants.MainVersionWithoutAlphaBeta + ", LUCENE_VERSION=" + Constants.LUCENE_VERSION + ")"; + private string VersionDetails => " (LUCENE_MAIN_VERSION=" + Constants.LUCENE_MAIN_VERSION + + ", LUCENE_MAIN_VERSION(without alpha/beta)=" + Constants.MainVersionWithoutAlphaBeta + + ", LUCENE_VERSION=" + Constants.LUCENE_VERSION + ")"; [Test] public virtual void TestLuceneMainVersionConstant() { - Assert.IsTrue(Regex.IsMatch(Constants.LUCENE_MAIN_VERSION, "\\d+\\.\\d+(|\\.0\\.\\d+)", RegexOptions.IgnoreCase), "LUCENE_MAIN_VERSION does not follow pattern: 'x.y' (stable release) or 'x.y.0.z' (alpha/beta version)" + VersionDetails); - Assert.IsTrue(Constants.LUCENE_VERSION.StartsWith(Constants.MainVersionWithoutAlphaBeta, StringComparison.Ordinal), "LUCENE_VERSION does not start with LUCENE_MAIN_VERSION (without alpha/beta marker)" + VersionDetails); + Assert.IsTrue(Regex.IsMatch(Constants.LUCENE_MAIN_VERSION, "\\d+\\.\\d+(|\\.0\\.\\d+)", RegexOptions.IgnoreCase), + "LUCENE_MAIN_VERSION does not follow pattern: 'x.y' (stable release) or 'x.y.0.z' (alpha/beta version)" + VersionDetails); + Assert.IsTrue(Constants.LUCENE_VERSION.StartsWith(Constants.MainVersionWithoutAlphaBeta, StringComparison.Ordinal), + "LUCENE_VERSION does not start with LUCENE_MAIN_VERSION (without alpha/beta marker)" + VersionDetails); } [Test] @@ -50,7 +54,8 @@ public virtual void TestBuildSetup() // remove anything after a "-" from the version string: version = Regex.Replace(version, "-.*$", ""); string versionConstant = Regex.Replace(Constants.LUCENE_VERSION, "-.*$", ""); - Assert.IsTrue(versionConstant.StartsWith(version, StringComparison.Ordinal) || version.StartsWith(versionConstant, StringComparison.Ordinal), "LUCENE_VERSION should share the same prefix with lucene.version test property ('" + version + "')." + VersionDetails); + Assert.IsTrue(versionConstant.StartsWith(version, StringComparison.Ordinal) || version.StartsWith(versionConstant, StringComparison.Ordinal), + "LUCENE_VERSION should share the same prefix with lucene.version test property ('" + version + "')." + VersionDetails); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestDocIdBitSet.cs b/src/Lucene.Net.Tests/Util/TestDocIdBitSet.cs index 7eb44c1f46..0b6c37959f 100644 --- a/src/Lucene.Net.Tests/Util/TestDocIdBitSet.cs +++ b/src/Lucene.Net.Tests/Util/TestDocIdBitSet.cs @@ -1,4 +1,3 @@ -using Assert = Lucene.Net.TestFramework.Assert; using BitSet = J2N.Collections.BitSet; namespace Lucene.Net.Util @@ -20,6 +19,7 @@ namespace Lucene.Net.Util * limitations under the License. */ + [TestFixture] public class TestDocIdBitSet : BaseDocIdSetTestCase { public override DocIdBitSet CopyOf(BitSet bs, int length) @@ -27,4 +27,4 @@ public override DocIdBitSet CopyOf(BitSet bs, int length) return new DocIdBitSet((BitSet)bs.Clone()); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestDoubleBarrelLRUCache.cs b/src/Lucene.Net.Tests/Util/TestDoubleBarrelLRUCache.cs index 8e9f0472ff..b5a67b4707 100644 --- a/src/Lucene.Net.Tests/Util/TestDoubleBarrelLRUCache.cs +++ b/src/Lucene.Net.Tests/Util/TestDoubleBarrelLRUCache.cs @@ -146,7 +146,7 @@ public virtual void TestThreadCorrectness() { const int NUM_THREADS = 4; const int CACHE_SIZE = 512; - int OBJ_COUNT = 3 * CACHE_SIZE; + const int OBJ_COUNT = 3 * CACHE_SIZE; DoubleBarrelLRUCache c = new DoubleBarrelLRUCache(1024); @@ -182,7 +182,8 @@ public CloneableObject(object value) public override bool Equals(object other) { - if (other.GetType().Equals(typeof (CloneableObject))) + // LUCENENET: Additional type check not present in Java code + if (other is CloneableObject) return this.value.Equals(((CloneableObject) other).value); else return false; @@ -224,4 +225,4 @@ public override object Clone() } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestFieldCacheSanityChecker.cs b/src/Lucene.Net.Tests/Util/TestFieldCacheSanityChecker.cs index 723bfca349..05c4b323b4 100644 --- a/src/Lucene.Net.Tests/Util/TestFieldCacheSanityChecker.cs +++ b/src/Lucene.Net.Tests/Util/TestFieldCacheSanityChecker.cs @@ -1,7 +1,6 @@ using Lucene.Net.Documents; using Lucene.Net.Search; using NUnit.Framework; -using System; using System.Globalization; using System.IO; using Assert = Lucene.Net.TestFramework.Assert; @@ -194,4 +193,4 @@ public virtual void TestInsanity2() cache.PurgeAllCaches(); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestFilterIterator.cs b/src/Lucene.Net.Tests/Util/TestFilterIterator.cs index 3598c1f1d8..5b1b8587b6 100644 --- a/src/Lucene.Net.Tests/Util/TestFilterIterator.cs +++ b/src/Lucene.Net.Tests/Util/TestFilterIterator.cs @@ -26,6 +26,8 @@ namespace Lucene.Net.Util [TestFixture] public class TestFilterIterator : LuceneTestCase { + // LUCENENET: in these tests, using lambdas with FilterEnumerator instead of anonymous classes + private static readonly ISet set = new JCG.SortedSet(StringComparer.Ordinal) { "a", "b", "c" }; private static void AssertNoMore(IEnumerator it) @@ -37,14 +39,14 @@ private static void AssertNoMore(IEnumerator it) [Test] public virtual void TestEmpty() { - IEnumerator it = new FilterEnumerator(set.GetEnumerator(), (s) => false); + IEnumerator it = new FilterEnumerator(set.GetEnumerator(), (_) => false); AssertNoMore(it); } [Test] public virtual void TestA1() { - IEnumerator it = new FilterEnumerator(set.GetEnumerator(), (s) => "a".Equals(s, StringComparison.Ordinal)); + IEnumerator it = new FilterEnumerator(set.GetEnumerator(), s => "a".Equals(s, StringComparison.Ordinal)); Assert.IsTrue(it.MoveNext()); Assert.AreEqual("a", it.Current); AssertNoMore(it); @@ -115,7 +117,7 @@ public virtual void TestAll2() // try // { - // it.Remove(); + // it.Remove(); // Assert.Fail("Should throw UnsupportedOperationException"); // } // catch (Exception oue) when (oue.IsUnsupportedOperationException()) @@ -124,9 +126,6 @@ public virtual void TestAll2() // } //} - - - [Test] [Obsolete("This method will be removed in 4.8.0 release candidate."), System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] public virtual void TestEmptyIterator() @@ -303,4 +302,4 @@ protected override bool PredicateFunction(string s) } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestFixedBitSet.cs b/src/Lucene.Net.Tests/Util/TestFixedBitSet.cs index e622c477a8..1bf8467bfa 100644 --- a/src/Lucene.Net.Tests/Util/TestFixedBitSet.cs +++ b/src/Lucene.Net.Tests/Util/TestFixedBitSet.cs @@ -24,7 +24,7 @@ namespace Lucene.Net.Util * limitations under the License. */ - using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator; + using DocIdSetIterator = Search.DocIdSetIterator; [TestFixture] public class TestFixedBitSet : BaseDocIdSetTestCase @@ -218,7 +218,7 @@ internal virtual void DoRandomSets(int maxSize, int iter, int mode) if (b0 != null && b0.Length <= b.Length) { Assert.AreEqual(a.Cardinality, b.Cardinality); - + BitSet a_and = (BitSet)a.Clone(); a_and.And(a0); BitSet a_or = (BitSet)a.Clone(); @@ -502,4 +502,4 @@ public virtual void TestEnsureCapacity() Assert.IsFalse(newBits.Get(1)); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestIOUtils.cs b/src/Lucene.Net.Tests/Util/TestIOUtils.cs index bc8ae8621e..dba2fb450a 100644 --- a/src/Lucene.Net.Tests/Util/TestIOUtils.cs +++ b/src/Lucene.Net.Tests/Util/TestIOUtils.cs @@ -74,9 +74,7 @@ public virtual void TestSuppressedExceptions() { IOUtils.DisposeWhileHandlingException((TestException)null, new BrokenIDisposable(1), new BrokenIDisposable(2)); } -#pragma warning disable 168 - catch (TestException e1) -#pragma warning restore 168 + catch (TestException) { fail("TestException should not be thrown here"); } @@ -86,12 +84,10 @@ public virtual void TestSuppressedExceptions() assertEquals(1, e2.GetSuppressed().Length); assertEquals("TEST-IO-EXCEPTION-2", e2.GetSuppressed()[0].Message); } -#pragma warning disable 168 - catch (Exception e2) -#pragma warning restore 168 + catch (Exception) { fail("Exception should not be thrown here"); } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestIdentityHashSet.cs b/src/Lucene.Net.Tests/Util/TestIdentityHashSet.cs index 67317e8e68..9419dbf86e 100644 --- a/src/Lucene.Net.Tests/Util/TestIdentityHashSet.cs +++ b/src/Lucene.Net.Tests/Util/TestIdentityHashSet.cs @@ -62,4 +62,4 @@ public virtual void TestCheck() assertEquals(collected, jdk, aggressive: false); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestInPlaceMergeSorter.cs b/src/Lucene.Net.Tests/Util/TestInPlaceMergeSorter.cs index b5e57b7c58..07ed574c84 100644 --- a/src/Lucene.Net.Tests/Util/TestInPlaceMergeSorter.cs +++ b/src/Lucene.Net.Tests/Util/TestInPlaceMergeSorter.cs @@ -1,5 +1,3 @@ -using Assert = Lucene.Net.TestFramework.Assert; - namespace Lucene.Net.Util { /* @@ -19,6 +17,7 @@ namespace Lucene.Net.Util * limitations under the License. */ + [TestFixture] public class TestInPlaceMergeSorter : BaseSortTestCase { public TestInPlaceMergeSorter() @@ -31,4 +30,4 @@ public override Sorter NewSorter(Entry[] arr) return new ArrayInPlaceMergeSorter(arr, ArrayUtil.GetNaturalComparer()); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestIndexableBinaryStringTools.cs b/src/Lucene.Net.Tests/Util/TestIndexableBinaryStringTools.cs index 2831585d2f..2c578f72a2 100644 --- a/src/Lucene.Net.Tests/Util/TestIndexableBinaryStringTools.cs +++ b/src/Lucene.Net.Tests/Util/TestIndexableBinaryStringTools.cs @@ -43,7 +43,9 @@ public override void BeforeClass() [Test] public virtual void TestSingleBinaryRoundTrip() { - sbyte[] binary = new sbyte[] { (sbyte)0x23, unchecked((sbyte)0x98), (sbyte)0x13, unchecked((sbyte)0xE4), (sbyte)0x76, (sbyte)0x41, unchecked((sbyte)0xB2), unchecked((sbyte)0xC9), (sbyte)0x7F, (sbyte)0x0A, unchecked((sbyte)0xA6), unchecked((sbyte)0xD8) }; + sbyte[] binary = new sbyte[] { (sbyte)0x23, unchecked((sbyte)0x98), (sbyte)0x13, + unchecked((sbyte)0xE4), (sbyte)0x76, (sbyte)0x41, unchecked((sbyte)0xB2), unchecked((sbyte)0xC9), + (sbyte)0x7F, (sbyte)0x0A, unchecked((sbyte)0xA6), unchecked((sbyte)0xD8) }; int encodedLen = IndexableBinaryStringTools.GetEncodedLength(binary, 0, binary.Length); char[] encoded = new char[encodedLen]; @@ -53,7 +55,11 @@ public virtual void TestSingleBinaryRoundTrip() sbyte[] decoded = new sbyte[decodedLen]; IndexableBinaryStringTools.Decode(encoded, 0, encoded.Length, decoded, 0, decoded.Length); - Assert.AreEqual(BinaryDump(binary, binary.Length), BinaryDump(decoded, decoded.Length), "Round trip decode/decode returned different results:\noriginal: " + BinaryDump(binary, binary.Length) + "\n encoded: " + CharArrayDump(encoded, encoded.Length) + "\n decoded: " + BinaryDump(decoded, decoded.Length)); + Assert.AreEqual(BinaryDump(binary, binary.Length), BinaryDump(decoded, decoded.Length), + "Round trip decode/decode returned different results:\noriginal: " + + BinaryDump(binary, binary.Length) + "\n encoded: " + + CharArrayDump(encoded, encoded.Length) + "\n decoded: " + + BinaryDump(decoded, decoded.Length)); } [Test] @@ -88,7 +94,8 @@ public virtual void TestEncodedSortability() int originalComparison = String.CompareOrdinal(new string(originalString1, 0, numBytes1), new string(originalString2, 0, numBytes2)); - originalComparison = originalComparison < 0 ? -1 : originalComparison > 0 ? 1 : 0; + originalComparison = originalComparison < 0 ? -1 + : originalComparison > 0 ? 1 : 0; int encodedLen1 = IndexableBinaryStringTools.GetEncodedLength(originalArray1, 0, numBytes1); if (encodedLen1 > encoded1.Length) @@ -109,7 +116,13 @@ public virtual void TestEncodedSortability() encodedComparison = encodedComparison < 0 ? -1 : encodedComparison > 0 ? 1 : 0; - Assert.AreEqual(originalComparison, encodedComparison, "Test #" + (testNum + 1) + ": Original bytes and encoded chars compare differently:" + " \nbinary 1: " + BinaryDump(originalArray1, numBytes1) + " \nbinary 2: " + BinaryDump(original2, numBytes2) + "\nencoded 1: " + CharArrayDump(encoded1, encodedLen1) + "\nencoded 2: " + CharArrayDump(encoded2, encodedLen2)); + Assert.AreEqual(originalComparison, encodedComparison, + "Test #" + (testNum + 1) + + ": Original bytes and encoded chars compare differently:" + + " \nbinary 1: " + BinaryDump(originalArray1, numBytes1) + + " \nbinary 2: " + BinaryDump(original2, numBytes2) + + "\nencoded 1: " + CharArrayDump(encoded1, encodedLen1) + + "\nencoded 2: " + CharArrayDump(encoded2, encodedLen2)); } } @@ -142,7 +155,10 @@ public virtual void TestAllNullInput() sbyte[] decoded = new sbyte[decodedLen]; IndexableBinaryStringTools.Decode(encoded, 0, encoded.Length, decoded, 0, decoded.Length); - Assert.AreEqual(BinaryDump(binary, binary.Length), BinaryDump(decoded, decoded.Length), "Round trip decode/decode returned different results:" + "\n original: " + BinaryDump(binary, binary.Length) + "\ndecodedBuf: " + BinaryDump(decoded, decoded.Length)); + Assert.AreEqual(BinaryDump(binary, binary.Length), BinaryDump(decoded, decoded.Length), + "Round trip decode/decode returned different results:" + + "\n original: " + BinaryDump(binary, binary.Length) + + "\ndecodedBuf: " + BinaryDump(decoded, decoded.Length)); } [Test] @@ -170,7 +186,12 @@ public virtual void TestRandomBinaryRoundTrip() int decodedLen = IndexableBinaryStringTools.GetDecodedLength(encoded, 0, encodedLen); IndexableBinaryStringTools.Decode(encoded, 0, encodedLen, decoded, 0, decodedLen); - Assert.AreEqual(BinaryDump(binary, numBytes), BinaryDump(decoded, decodedLen), "Test #" + (testNum + 1) + ": Round trip decode/decode returned different results:" + "\n original: " + BinaryDump(binary, numBytes) + "\nencodedBuf: " + CharArrayDump(encoded, encodedLen) + "\ndecodedBuf: " + BinaryDump(decoded, decodedLen)); + Assert.AreEqual(BinaryDump(binary, numBytes), BinaryDump(decoded, decodedLen), + "Test #" + (testNum + 1) + + ": Round trip decode/decode returned different results:" + + "\n original: " + BinaryDump(binary, numBytes) + + "\nencodedBuf: " + CharArrayDump(encoded, encodedLen) + + "\ndecodedBuf: " + BinaryDump(decoded, decodedLen)); } } @@ -212,4 +233,4 @@ public virtual string CharArrayDump(char[] charArray, int numBytes) return buf.ToString(); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestIntroSorter.cs b/src/Lucene.Net.Tests/Util/TestIntroSorter.cs index 81be1d5a26..feef59d2b8 100644 --- a/src/Lucene.Net.Tests/Util/TestIntroSorter.cs +++ b/src/Lucene.Net.Tests/Util/TestIntroSorter.cs @@ -1,5 +1,3 @@ -using Assert = Lucene.Net.TestFramework.Assert; - namespace Lucene.Net.Util { /* @@ -19,6 +17,7 @@ namespace Lucene.Net.Util * limitations under the License. */ + [TestFixture] public class TestIntroSorter : BaseSortTestCase { public TestIntroSorter() @@ -31,4 +30,4 @@ public override Sorter NewSorter(Entry[] arr) return new ArrayIntroSorter(arr, ArrayUtil.GetNaturalComparer()); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestIntsRef.cs b/src/Lucene.Net.Tests/Util/TestIntsRef.cs index 35c5c004b8..954a78f7fa 100644 --- a/src/Lucene.Net.Tests/Util/TestIntsRef.cs +++ b/src/Lucene.Net.Tests/Util/TestIntsRef.cs @@ -71,4 +71,4 @@ public void TestSerialization() } #endif } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestLongBitSet.cs b/src/Lucene.Net.Tests/Util/TestLongBitSet.cs index 109f7cc49d..482ddaa40d 100644 --- a/src/Lucene.Net.Tests/Util/TestLongBitSet.cs +++ b/src/Lucene.Net.Tests/Util/TestLongBitSet.cs @@ -117,12 +117,12 @@ internal virtual void DoRandomSets(int maxSize, int iter, int mode) idx = Random.Next(sz); a.Flip(idx); b.Flip(idx, idx + 1); - + bool val2 = b.Get(idx); bool val = b.GetAndSet(idx); Assert.IsTrue(val2 == val); Assert.IsTrue(b.Get(idx)); - + if (!val) { b.Clear(idx); @@ -133,7 +133,7 @@ internal virtual void DoRandomSets(int maxSize, int iter, int mode) // test that the various ways of accessing the bits are equivalent DoGet(a, b); - + // test ranges, including possible extension int fromIndex, toIndex; fromIndex = Random.Next(sz / 2); @@ -474,4 +474,4 @@ public void TestSerialization() } #endif } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestMathUtil.cs b/src/Lucene.Net.Tests/Util/TestMathUtil.cs index e2392c9713..74beb8982c 100644 --- a/src/Lucene.Net.Tests/Util/TestMathUtil.cs +++ b/src/Lucene.Net.Tests/Util/TestMathUtil.cs @@ -1,6 +1,5 @@ using NUnit.Framework; using RandomizedTesting.Generators; -using System; using Assert = Lucene.Net.TestFramework.Assert; namespace Lucene.Net.Util @@ -58,6 +57,8 @@ internal static long RandomLong() } // slow version used for testing + // LUCENENET: semantics changed to a Try pattern as BigInteger could overflow long + // LUCENENET: l1/l2 parameters renamed to a/b to potentially avoid reader confusion with 11/12 private static bool TryGetGcd(long a, long b, out long result) { result = 0; @@ -79,6 +80,7 @@ public virtual void TestGCD() long l1 = RandomLong(); long l2 = RandomLong(); long gcd = MathUtil.Gcd(l1, l2); + // LUCENENET: test changed to use Try pattern, was: final long actualGcd = gcd(l1, l2); if (TryGetGcd(l1, l2, out long actualGcd)) { Assert.AreEqual(actualGcd, gcd); @@ -210,4 +212,4 @@ public virtual void TestAtanhMethod() } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestMergedIterator.cs b/src/Lucene.Net.Tests/Util/TestMergedIterator.cs index 3242f3944e..05c63144fb 100644 --- a/src/Lucene.Net.Tests/Util/TestMergedIterator.cs +++ b/src/Lucene.Net.Tests/Util/TestMergedIterator.cs @@ -3,7 +3,10 @@ using System.Collections.Generic; using JCG = J2N.Collections.Generic; using Assert = Lucene.Net.TestFramework.Assert; -using RandomizedTesting.Generators; + +#if !FEATURE_RANDOM_NEXTINT64_NEXTSINGLE +using RandomizedTesting.Generators; // for Random.NextInt64 extension method +#endif namespace Lucene.Net.Util { @@ -36,13 +39,13 @@ public virtual void TestMergeEmpty() IEnumerator merged = new MergedEnumerator(); Assert.IsFalse(merged.MoveNext()); - merged = new MergedEnumerator((new JCG.List()).GetEnumerator()); + merged = new MergedEnumerator(new JCG.List().GetEnumerator()); Assert.IsFalse(merged.MoveNext()); IEnumerator[] itrs = new IEnumerator[Random.Next(100)]; for (int i = 0; i < itrs.Length; i++) { - itrs[i] = (new JCG.List()).GetEnumerator(); + itrs[i] = new JCG.List().GetEnumerator(); } merged = new MergedEnumerator(itrs); Assert.IsFalse(merged.MoveNext()); @@ -192,13 +195,13 @@ public virtual void TestMergeEmptyIterator() IEnumerator merged = new MergedIterator(); Assert.IsFalse(merged.MoveNext()); - merged = new MergedIterator((new JCG.List()).GetEnumerator()); + merged = new MergedIterator(new JCG.List().GetEnumerator()); Assert.IsFalse(merged.MoveNext()); IEnumerator[] itrs = new IEnumerator[Random.Next(100)]; for (int i = 0; i < itrs.Length; i++) { - itrs[i] = (new JCG.List()).GetEnumerator(); + itrs[i] = new JCG.List().GetEnumerator(); } merged = new MergedIterator(itrs); Assert.IsFalse(merged.MoveNext()); @@ -343,4 +346,4 @@ private void TestCaseIterator(int itrsWithVal, int specifiedValsOnItr, bool remo Assert.IsFalse(mergedItr.MoveNext()); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestNamedSPILoader.cs b/src/Lucene.Net.Tests/Util/TestNamedSPILoader.cs index 57a7446ce4..bd4f61a5a2 100644 --- a/src/Lucene.Net.Tests/Util/TestNamedSPILoader.cs +++ b/src/Lucene.Net.Tests/Util/TestNamedSPILoader.cs @@ -56,4 +56,4 @@ public virtual void TestAvailableServices() Assert.IsTrue(codecs.Contains("Lucene46")); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestNumericUtils.cs b/src/Lucene.Net.Tests/Util/TestNumericUtils.cs index 2d13918fa8..3c2b3d4b4e 100644 --- a/src/Lucene.Net.Tests/Util/TestNumericUtils.cs +++ b/src/Lucene.Net.Tests/Util/TestNumericUtils.cs @@ -553,4 +553,4 @@ public virtual void TestSplitIntRange() } #endif } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestOfflineSorter.cs b/src/Lucene.Net.Tests/Util/TestOfflineSorter.cs index 50fc13f830..dc5efe6ea3 100644 --- a/src/Lucene.Net.Tests/Util/TestOfflineSorter.cs +++ b/src/Lucene.Net.Tests/Util/TestOfflineSorter.cs @@ -307,4 +307,4 @@ public virtual void TestRamBuffer() Assert.Throws(() => OfflineSorter.BufferSize.Megabytes(-1), "min mb is 0.5"); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestOpenBitSet.cs b/src/Lucene.Net.Tests/Util/TestOpenBitSet.cs index cb48bfa3f8..a50009ac1f 100644 --- a/src/Lucene.Net.Tests/Util/TestOpenBitSet.cs +++ b/src/Lucene.Net.Tests/Util/TestOpenBitSet.cs @@ -513,4 +513,4 @@ public virtual void TestXorWithDifferentCapacity() Assert.IsTrue(smaller.Get(66)); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs b/src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs index 6732d1286c..aadbb7f88a 100644 --- a/src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs +++ b/src/Lucene.Net.Tests/Util/TestPForDeltaDocIdSet.cs @@ -38,4 +38,4 @@ public override void AssertEquals(int numBits, BitSet ds1, PForDeltaDocIdSet ds2 Assert.AreEqual(ds1.Cardinality, ds2.Cardinality); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestPagedBytes.cs b/src/Lucene.Net.Tests/Util/TestPagedBytes.cs index 40098f164f..20982180c5 100644 --- a/src/Lucene.Net.Tests/Util/TestPagedBytes.cs +++ b/src/Lucene.Net.Tests/Util/TestPagedBytes.cs @@ -53,20 +53,20 @@ public virtual void TestDataInputOutput() int blockSize = 1 << blockBits; PagedBytes p = new PagedBytes(blockBits); IndexOutput @out = dir.CreateOutput("foo", IOContext.DEFAULT); - int numBytes = TestUtil.NextInt32(LuceneTestCase.Random, 2, 10000000); + int numBytes = TestUtil.NextInt32(Random, 2, 10000000); byte[] answer = new byte[numBytes]; - LuceneTestCase.Random.NextBytes(answer); + Random.NextBytes(answer); int written = 0; while (written < numBytes) { - if (LuceneTestCase.Random.Next(10) == 7) + if (Random.Next(10) == 7) { @out.WriteByte(answer[written++]); } else { - int chunk = Math.Min(LuceneTestCase.Random.Next(1000), numBytes - written); + int chunk = Math.Min(Random.Next(1000), numBytes - written); @out.WriteBytes(answer, written, chunk); written += chunk; } @@ -83,13 +83,13 @@ public virtual void TestDataInputOutput() int read = 0; while (read < numBytes) { - if (LuceneTestCase.Random.Next(10) == 7) + if (Random.Next(10) == 7) { verify[read++] = @in.ReadByte(); } else { - int chunk = Math.Min(LuceneTestCase.Random.Next(1000), numBytes - read); + int chunk = Math.Min(Random.Next(1000), numBytes - read); @in.ReadBytes(verify, read, chunk); read += chunk; } @@ -104,7 +104,7 @@ public virtual void TestDataInputOutput() reader.FillSlice(slice, pos, len); for (int byteUpto = 0; byteUpto < len; byteUpto++) { - Assert.AreEqual(answer[pos + byteUpto], (byte)slice.Bytes[slice.Offset + byteUpto]); + Assert.AreEqual(answer[pos + byteUpto], slice.Bytes[slice.Offset + byteUpto]); } } input.Dispose(); @@ -126,20 +126,20 @@ public virtual void TestDataInputOutput2() int blockSize = 1 << blockBits; PagedBytes p = new PagedBytes(blockBits); DataOutput @out = p.GetDataOutput(); - int numBytes = LuceneTestCase.Random.Next(10000000); + int numBytes = Random.Next(10000000); byte[] answer = new byte[numBytes]; - LuceneTestCase.Random.NextBytes(answer); + Random.NextBytes(answer); int written = 0; while (written < numBytes) { - if (LuceneTestCase.Random.Next(10) == 7) + if (Random.Next(10) == 7) { @out.WriteByte(answer[written++]); } else { - int chunk = Math.Min(LuceneTestCase.Random.Next(1000), numBytes - written); + int chunk = Math.Min(Random.Next(1000), numBytes - written); @out.WriteBytes(answer, written, chunk); written += chunk; } @@ -153,13 +153,13 @@ public virtual void TestDataInputOutput2() int read = 0; while (read < numBytes) { - if (LuceneTestCase.Random.Next(10) == 7) + if (Random.Next(10) == 7) { verify[read++] = @in.ReadByte(); } else { - int chunk = Math.Min(LuceneTestCase.Random.Next(1000), numBytes - read); + int chunk = Math.Min(Random.Next(1000), numBytes - read); @in.ReadBytes(verify, read, chunk); read += chunk; } @@ -174,7 +174,7 @@ public virtual void TestDataInputOutput2() reader.FillSlice(slice, pos, len); for (int byteUpto = 0; byteUpto < len; byteUpto++) { - Assert.AreEqual(answer[pos + byteUpto], (byte)slice.Bytes[slice.Offset + byteUpto]); + Assert.AreEqual(answer[pos + byteUpto], slice.Bytes[slice.Offset + byteUpto]); } } } @@ -223,4 +223,4 @@ public virtual void TestOverflow() dir.Dispose(); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestPriorityQueue.cs b/src/Lucene.Net.Tests/Util/TestPriorityQueue.cs index b41d658af7..13999d8260 100644 --- a/src/Lucene.Net.Tests/Util/TestPriorityQueue.cs +++ b/src/Lucene.Net.Tests/Util/TestPriorityQueue.cs @@ -348,7 +348,7 @@ public int Compare(int? a, int? b) return 0; } - } + } [Ignore("Increase heap size to run this test")] [Test, LuceneNetSpecific] @@ -365,7 +365,7 @@ public static void TestMaxSizeBounds() // A valid maximum size maxSize = 12345; pq = new IntegerQueue(maxSize); - + // Cannot construct a negative size heap maxSize = -3; try @@ -552,7 +552,7 @@ public static void TestPop() pq.Add(7); pq.Pop(); Assert.AreEqual(pq.Count, 0); - + // Add a bunch of elements, pop them all pq.Add(1); pq.Add(20); @@ -724,7 +724,7 @@ public static void TestOverflow() { // Tests adding elements to full queues // Add's documentation claims throwing an IndexOutOfRangeException in this situation - + // Add an element to a prepopulated queue int maxSize = 10; PriorityQueue pq = new IntegerQueue(maxSize, true); @@ -1198,4 +1198,4 @@ private static int GetArrayHeapSize(int maxSize) #endregion } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestQueryBuilder.cs b/src/Lucene.Net.Tests/Util/TestQueryBuilder.cs index 02105267f0..794d460d27 100644 --- a/src/Lucene.Net.Tests/Util/TestQueryBuilder.cs +++ b/src/Lucene.Net.Tests/Util/TestQueryBuilder.cs @@ -57,8 +57,7 @@ public virtual void TestBoolean() expected.Add(new TermQuery(new Term("field", "foo")), Occur.SHOULD); expected.Add(new TermQuery(new Term("field", "bar")), Occur.SHOULD); QueryBuilder builder = new QueryBuilder(new MockAnalyzer(Random)); - Assert.IsTrue(expected.Equals(builder.CreateBooleanQuery("field", "foo bar"))); - //Assert.AreEqual(expected, builder.CreateBooleanQuery("field", "foo bar")); + Assert.AreEqual(expected, builder.CreateBooleanQuery("field", "foo bar")); } [Test] @@ -429,4 +428,4 @@ public virtual void TestCJKSynonymsPhrase() Assert.AreEqual(expected, builder.CreatePhraseQuery("field", "中国", 3)); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestRamUsageEstimator.cs b/src/Lucene.Net.Tests/Util/TestRamUsageEstimator.cs index f51fdfc58b..f92912f87b 100644 --- a/src/Lucene.Net.Tests/Util/TestRamUsageEstimator.cs +++ b/src/Lucene.Net.Tests/Util/TestRamUsageEstimator.cs @@ -86,7 +86,7 @@ public virtual void TestStaticOverloads() } } - + [Test] public virtual void TestReferenceSize() { @@ -151,4 +151,4 @@ private class HolderSubclass2 : Holder } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestRamUsageEstimatorOnWildAnimals.cs b/src/Lucene.Net.Tests/Util/TestRamUsageEstimatorOnWildAnimals.cs index 6d4f309b30..f8e57ccbf5 100644 --- a/src/Lucene.Net.Tests/Util/TestRamUsageEstimatorOnWildAnimals.cs +++ b/src/Lucene.Net.Tests/Util/TestRamUsageEstimatorOnWildAnimals.cs @@ -67,4 +67,4 @@ public virtual void TestOverflowMaxChainLength() } #endif } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestRecyclingByteBlockAllocator.cs b/src/Lucene.Net.Tests/Util/TestRecyclingByteBlockAllocator.cs index 0e04bd8360..5013862325 100644 --- a/src/Lucene.Net.Tests/Util/TestRecyclingByteBlockAllocator.cs +++ b/src/Lucene.Net.Tests/Util/TestRecyclingByteBlockAllocator.cs @@ -1,8 +1,6 @@ using J2N.Collections.Generic.Extensions; using NUnit.Framework; using System; -using System.Collections.Generic; -using System.Linq; using Assert = Lucene.Net.TestFramework.Assert; using JCG = J2N.Collections.Generic; @@ -39,7 +37,7 @@ public override void SetUp() private RecyclingByteBlockAllocator NewAllocator() { - return new RecyclingByteBlockAllocator(1 << (2 + Random.Next(15)), Random.Next(97), Util.Counter.NewCounter()); + return new RecyclingByteBlockAllocator(1 << (2 + Random.Next(15)), Random.Next(97), Counter.NewCounter()); } [Test] @@ -151,4 +149,4 @@ public virtual void TestAllocateAndFree() } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestRecyclingIntBlockAllocator.cs b/src/Lucene.Net.Tests/Util/TestRecyclingIntBlockAllocator.cs index a3d6811366..d13a81552f 100644 --- a/src/Lucene.Net.Tests/Util/TestRecyclingIntBlockAllocator.cs +++ b/src/Lucene.Net.Tests/Util/TestRecyclingIntBlockAllocator.cs @@ -2,7 +2,6 @@ using NUnit.Framework; using System; using System.Collections.Generic; -using System.Linq; using Assert = Lucene.Net.TestFramework.Assert; using JCG = J2N.Collections.Generic; @@ -151,4 +150,4 @@ public virtual void TestAllocateAndFree() } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestRollingBuffer.cs b/src/Lucene.Net.Tests/Util/TestRollingBuffer.cs index 2a4be4b2a5..de30241f28 100644 --- a/src/Lucene.Net.Tests/Util/TestRollingBuffer.cs +++ b/src/Lucene.Net.Tests/Util/TestRollingBuffer.cs @@ -109,4 +109,4 @@ public Position Create(object rollingBuffer) } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestSentinelIntSet.cs b/src/Lucene.Net.Tests/Util/TestSentinelIntSet.cs index e9231d233d..3e769afccc 100644 --- a/src/Lucene.Net.Tests/Util/TestSentinelIntSet.cs +++ b/src/Lucene.Net.Tests/Util/TestSentinelIntSet.cs @@ -75,4 +75,4 @@ public virtual void TestRandom() } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestSetOnce.cs b/src/Lucene.Net.Tests/Util/TestSetOnce.cs index 2f572eb540..4af4b812c2 100644 --- a/src/Lucene.Net.Tests/Util/TestSetOnce.cs +++ b/src/Lucene.Net.Tests/Util/TestSetOnce.cs @@ -1,10 +1,13 @@ using J2N.Threading; using NUnit.Framework; -using RandomizedTesting.Generators; using System; using System.Globalization; using Assert = Lucene.Net.TestFramework.Assert; +#if !FEATURE_RANDOM_NEXTINT64_NEXTSINGLE +using RandomizedTesting.Generators; // for Random.NextInt64 extension method +#endif + namespace Lucene.Net.Util { /* @@ -126,4 +129,4 @@ public virtual void TestSetMultiThreaded() } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestSloppyMath.cs b/src/Lucene.Net.Tests/Util/TestSloppyMath.cs index de988ff537..7348b0efbd 100644 --- a/src/Lucene.Net.Tests/Util/TestSloppyMath.cs +++ b/src/Lucene.Net.Tests/Util/TestSloppyMath.cs @@ -131,4 +131,4 @@ public virtual void TestHaversin() Assert.AreEqual(8.572, SloppyMath.Haversin(40.7143528, -74.0059731, 40.65, -73.95), 0.01D); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestSmallFloat.cs b/src/Lucene.Net.Tests/Util/TestSmallFloat.cs index 106985ec92..ca18ea9c1b 100644 --- a/src/Lucene.Net.Tests/Util/TestSmallFloat.cs +++ b/src/Lucene.Net.Tests/Util/TestSmallFloat.cs @@ -158,4 +158,4 @@ public virtual void TestFloatToByte() } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestStringHelper.cs b/src/Lucene.Net.Tests/Util/TestStringHelper.cs index 396d3e42ea..9576da5fd9 100644 --- a/src/Lucene.Net.Tests/Util/TestStringHelper.cs +++ b/src/Lucene.Net.Tests/Util/TestStringHelper.cs @@ -33,4 +33,4 @@ public virtual void TestMurmurHash3() Assert.AreEqual(0x2c628cd0, (uint)StringHelper.Murmurhash3_x86_32(new BytesRef("You want weapons? We're in a library! Books! The best weapons in the world!"), 3476)); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestTimSorter.cs b/src/Lucene.Net.Tests/Util/TestTimSorter.cs index e9dd7ba997..0bcc503cec 100644 --- a/src/Lucene.Net.Tests/Util/TestTimSorter.cs +++ b/src/Lucene.Net.Tests/Util/TestTimSorter.cs @@ -29,4 +29,4 @@ public override Sorter NewSorter(Entry[] arr) return new ArrayTimSorter(arr, ArrayUtil.GetNaturalComparer(), TestUtil.NextInt32(Random, 0, arr.Length)); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestUnicodeUtil.cs b/src/Lucene.Net.Tests/Util/TestUnicodeUtil.cs index 27801bc995..bb8e736a7c 100644 --- a/src/Lucene.Net.Tests/Util/TestUnicodeUtil.cs +++ b/src/Lucene.Net.Tests/Util/TestUnicodeUtil.cs @@ -328,4 +328,4 @@ public virtual void TestUTF8UTF16CharsRef() } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestVersion.cs b/src/Lucene.Net.Tests/Util/TestVersion.cs index 4283d2ec15..14e7ee460d 100644 --- a/src/Lucene.Net.Tests/Util/TestVersion.cs +++ b/src/Lucene.Net.Tests/Util/TestVersion.cs @@ -80,4 +80,4 @@ public virtual void TestAgainstMainVersionConstant() } } #pragma warning restore 612, 618 -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestVersionComparator.cs b/src/Lucene.Net.Tests/Util/TestVersionComparator.cs index 14f2976b7d..2b3b335929 100644 --- a/src/Lucene.Net.Tests/Util/TestVersionComparator.cs +++ b/src/Lucene.Net.Tests/Util/TestVersionComparator.cs @@ -58,4 +58,4 @@ public virtual void TestVersions() Assert.IsTrue(comp.Compare("3.0", Convert.ToString(int.MinValue, CultureInfo.InvariantCulture)) > 0); } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestVirtualMethod.cs b/src/Lucene.Net.Tests/Util/TestVirtualMethod.cs index 0ac7841410..450eb9480f 100644 --- a/src/Lucene.Net.Tests/Util/TestVirtualMethod.cs +++ b/src/Lucene.Net.Tests/Util/TestVirtualMethod.cs @@ -145,4 +145,4 @@ public virtual void TestExceptions() } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net.Tests/Util/TestWAH8DocIdSet.cs b/src/Lucene.Net.Tests/Util/TestWAH8DocIdSet.cs index d9a0a9c449..effc8b5ec3 100644 --- a/src/Lucene.Net.Tests/Util/TestWAH8DocIdSet.cs +++ b/src/Lucene.Net.Tests/Util/TestWAH8DocIdSet.cs @@ -33,7 +33,7 @@ public class TestWAH8DocIdSet : BaseDocIdSetTestCase public override WAH8DocIdSet CopyOf(BitSet bs, int length) { int indexInterval = TestUtil.NextInt32(Random, 8, 256); - WAH8DocIdSet.Builder builder = (WAH8DocIdSet.Builder)(new WAH8DocIdSet.Builder()).SetIndexInterval(indexInterval); + WAH8DocIdSet.Builder builder = (WAH8DocIdSet.Builder)new WAH8DocIdSet.Builder().SetIndexInterval(indexInterval); for (int i = bs.NextSetBit(0); i != -1; i = bs.NextSetBit(i + 1)) { builder.Add(i); @@ -41,10 +41,11 @@ public override WAH8DocIdSet CopyOf(BitSet bs, int length) return builder.Build(); } + // LUCENENET: Added to support OpenBitSet, see OpenBitSet documentation public WAH8DocIdSet CopyOf(OpenBitSet bs, int length) { int indexInterval = TestUtil.NextInt32(Random, 8, 256); - WAH8DocIdSet.Builder builder = (WAH8DocIdSet.Builder)(new WAH8DocIdSet.Builder()).SetIndexInterval(indexInterval); + WAH8DocIdSet.Builder builder = (WAH8DocIdSet.Builder)new WAH8DocIdSet.Builder().SetIndexInterval(indexInterval); for (int i = bs.NextSetBit(0); i != -1; i = bs.NextSetBit(i + 1)) { builder.Add(i); @@ -92,6 +93,7 @@ public virtual void TestUnion() AssertEquals(numBits, expected, union); } + // LUCENENET specific - added to support OpenBitSet, see OpenBitSet documentation /// /// Create a random set which has of its bits set. protected static OpenBitSet RandomOpenSet(int numBits, int numBitsSet) @@ -121,6 +123,7 @@ protected static OpenBitSet RandomOpenSet(int numBits, int numBitsSet) return set; } + // LUCENENET specific - added to support OpenBitSet, see OpenBitSet documentation /// /// Same as but given a load factor. protected static OpenBitSet RandomOpenSet(int numBits, float percentSet) @@ -128,6 +131,7 @@ protected static OpenBitSet RandomOpenSet(int numBits, float percentSet) return RandomOpenSet(numBits, (int)(percentSet * numBits)); } + // LUCENENET specific - added to support OpenBitSet, see OpenBitSet documentation /// /// Assert that the content of the is the same as the content of the . /// @@ -212,6 +216,8 @@ public virtual void AssertEquals(int numBits, OpenBitSet ds1, WAH8DocIdSet ds2) [Test] public virtual void TestIntersection() { + // LUCENENET: using OpenBitSet instead of BitSet in this test, see OpenBitSet documentation for rationale + int numBits = TestUtil.NextInt32(Random, 100, 1 << 20); int numDocIdSets = TestUtil.NextInt32(Random, 1, 4); IList fixedSets = new JCG.List(numDocIdSets); @@ -246,4 +252,4 @@ public virtual void TestIntersection() AssertEquals(numBits, expected, union); } } -} \ No newline at end of file +}