Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Review T-Z Tests, #259 #897

Merged
merged 7 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions .idea/.idea.Lucene.Net/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.idea.Lucene.Net/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/.idea.Lucene.Net/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.Lucene.Net/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.Lucene.Net/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file modified build
100644 → 100755
Empty file.
19 changes: 15 additions & 4 deletions src/Lucene.Net.Tests.Expressions/JS/TestJavascriptOperations.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -373,7 +384,7 @@ public virtual void TestHexConst2()
AssertEvaluatesTo("0X0", 0);
AssertEvaluatesTo("0X1", 1);
AssertEvaluatesTo("0XF", 15);
AssertEvaluatesTo("0X1234ABCDEF", 78193085935L);
AssertEvaluatesTo("0X1234ABCDEF", 78193085935L);
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.Tests/Util/Automaton/TestBasicOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,4 @@ public virtual void TestGetRandomAcceptedString()
}
}
}
}
}
3 changes: 1 addition & 2 deletions src/Lucene.Net.Tests/Util/Automaton/TestCompiledAutomaton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -148,4 +147,4 @@ public virtual void TestBasic()
TestFloor(c, "zzz", "goo");
}
}
}
}
4 changes: 2 additions & 2 deletions src/Lucene.Net.Tests/Util/Automaton/TestDeterminism.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -89,4 +89,4 @@ private static void AssertAutomaton(Automaton a)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ public void AssertLexicon()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/// <summary>
Expand Down Expand Up @@ -435,4 +435,4 @@ private int GetTDistance(string target, string other)
return Math.Abs(d[n][m]);
}
}
}
}
5 changes: 2 additions & 3 deletions src/Lucene.Net.Tests/Util/Automaton/TestMinimize.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using NUnit.Framework;
using Assert = Lucene.Net.TestFramework.Assert;
using Console = Lucene.Net.Util.SystemConsole;

namespace Lucene.Net.Util.Automaton
{
Expand Down Expand Up @@ -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();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ public virtual void TestFiniteStrings()
Assert.IsTrue(strings.Contains(duck));
}
}
}
}
4 changes: 2 additions & 2 deletions src/Lucene.Net.Tests/Util/Automaton/TestUTF32ToUTF8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -286,4 +286,4 @@ private static void AssertAutomaton(Automaton automaton)
}
}
}
}
}
52 changes: 24 additions & 28 deletions src/Lucene.Net.Tests/Util/BaseSortTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ public virtual int CompareTo(Entry other)
}

private readonly bool stable;
private readonly Random random;
paulirwin marked this conversation as resolved.
Show resolved Hide resolved

protected BaseSortTestCase(bool stable)
{
this.stable = stable;
this.random = Random;
}

public abstract Sorter NewSorter(Entry[] arr);
Expand All @@ -69,6 +67,7 @@ public int Compare(Entry a, Entry b)
public virtual void AssertSorted(Entry[] original, Entry[] sorted)
{
Assert.AreEqual(original.Length, sorted.Length);
// LUCENENET: this code differs significantly from the original Java test which used Arrays.sort().
Entry[] stableSorted = original.OrderBy(e => e, new StableEntryComparer()).ToArray();
paulirwin marked this conversation as resolved.
Show resolved Hide resolved
for (int i = 0; i < original.Length; ++i)
{
Expand All @@ -82,8 +81,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);
Expand All @@ -94,50 +93,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)
Expand Down Expand Up @@ -169,7 +165,7 @@ public virtual void TestOne()
[Test]
public virtual void TestTwo()
{
DoTest(RandomStrategy, 2);
DoTest(RandomLowCardinalityStrategy, 2);
}

[Test]
Expand All @@ -181,31 +177,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);
}
}
}
}
7 changes: 5 additions & 2 deletions src/Lucene.Net.Tests/Util/Fst/Test2BFST.cs
Original file line number Diff line number Diff line change
@@ -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 !NET6_0_OR_GREATER
paulirwin marked this conversation as resolved.
Show resolved Hide resolved
using RandomizedTesting.Generators; // for Random.NextInt64 extension method
#endif

namespace Lucene.Net.Util.Fst
{
/*
Expand Down Expand Up @@ -338,4 +341,4 @@ private void NextInput(Random r, int[] ints)
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Lucene.Net.Tests/Util/Fst/TestBytesStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,4 @@ private void Verify(BytesStore bytes, byte[] expected, int totalLength)
}
}
}
}
}