Skip to content

Commit

Permalink
Finish test review A-D
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirwin committed Nov 13, 2024
1 parent 139b959 commit 0af80e4
Show file tree
Hide file tree
Showing 32 changed files with 411 additions and 318 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public virtual void TestNoOrds()
Assert.AreEqual(TermsEnum.SeekStatus.FOUND, termsEnum.SeekCeil(new BytesRef("this")));
try
{
var _ = termsEnum.Ord;
_ = termsEnum.Ord;
Assert.Fail();
}
catch (Exception expected) when (expected.IsUnsupportedOperationException())
Expand All @@ -82,4 +82,4 @@ public virtual void TestNoOrds()
dir.Dispose();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace Lucene.Net.Codecs.Lucene3x
/// <summary>
/// Tests Lucene3x postings format
/// </summary>
[TestFixture]
public class TestLucene3xPostingsFormat : BasePostingsFormatTestCase
{
private readonly Codec codec = new PreFlexRWCodec();
Expand All @@ -36,10 +37,9 @@ public override void SetUp()
LuceneTestCase.OldFormatImpersonationIsActive = true;
}


protected override Codec GetCodec()
{
return codec;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Lucene.Net.Codecs.Lucene3x

using BaseTermVectorsFormatTestCase = Lucene.Net.Index.BaseTermVectorsFormatTestCase;

[TestFixture]
public class TestLucene3xTermVectorsFormat : BaseTermVectorsFormatTestCase
{
[SetUp]
Expand All @@ -41,4 +42,4 @@ protected override IEnumerable<Options> ValidOptions()
return ValidOptions(Options.NONE, Options.POSITIONS_AND_OFFSETS);
}
}
}
}
28 changes: 18 additions & 10 deletions src/Lucene.Net.Tests/Codecs/Lucene3x/TestSurrogates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Lucene.Net.Analysis;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.Index.Extensions;
using Lucene.Net.Store;
using Lucene.Net.Util;
using NUnit.Framework;
Expand Down Expand Up @@ -76,12 +77,14 @@ private static string MakeDifficultRandomUnicodeString(Random r)
return new string(buffer, 0, end);
}

// LUCENENET specific - made static
private static string ToHexString(Term t)
{
return t.Field + ":" + UnicodeUtil.ToHexString(t.Text);
}

private string GetRandomString(Random r)
// LUCENENET specific - made static
private static string GetRandomString(Random r)
{
string s;
if (r.Next(5) == 1)
Expand Down Expand Up @@ -116,21 +119,23 @@ public int Compare(Term term1, Term term2)
}
else
{
return System.String.Compare(term1.Field, term2.Field, System.StringComparison.Ordinal);
return string.Compare(term1.Field, term2.Field, StringComparison.Ordinal);
}
}
}

private static readonly SortTermAsUTF16Comparer termAsUTF16Comparer = new SortTermAsUTF16Comparer();

// LUCENENET specific - made static
// single straight enum
private void DoTestStraightEnum(IList<Term> fieldTerms, IndexReader reader, int uniqueTermCount)
private static void DoTestStraightEnum(IList<Term> fieldTerms, IndexReader reader, int uniqueTermCount)
{
if (Verbose)
{
Console.WriteLine("\nTEST: top now enum reader=" + reader);
}
Fields fields = MultiFields.GetFields(reader);

{
// Test straight enum:
int termCount = 0;
Expand Down Expand Up @@ -173,9 +178,10 @@ private void DoTestStraightEnum(IList<Term> fieldTerms, IndexReader reader, int
}
}

// LUCENENET specific - made static
// randomly seeks to term that we know exists, then next's
// from there
private void DoTestSeekExists(Random r, IList<Term> fieldTerms, IndexReader reader)
private static void DoTestSeekExists(Random r, IList<Term> fieldTerms, IndexReader reader)
{
IDictionary<string, TermsEnum> tes = new Dictionary<string, TermsEnum>();

Expand Down Expand Up @@ -248,7 +254,8 @@ private void DoTestSeekExists(Random r, IList<Term> fieldTerms, IndexReader read
}
}

private void DoTestSeekDoesNotExist(Random r, int numField, IList<Term> fieldTerms, Term[] fieldTermsArray, IndexReader reader)
// LUCENENET specific - made static
private static void DoTestSeekDoesNotExist(Random r, int numField, IList<Term> fieldTerms, Term[] fieldTermsArray, IndexReader reader)
{
IDictionary<string, TermsEnum> tes = new Dictionary<string, TermsEnum>();

Expand Down Expand Up @@ -346,9 +353,10 @@ private void DoTestSeekDoesNotExist(Random r, int numField, IList<Term> fieldTer
public virtual void TestSurrogatesOrder()
{
Directory dir = NewDirectory();
var config = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random));
config.Codec = new PreFlexRWCodec();
RandomIndexWriter w = new RandomIndexWriter(Random, dir, config);
RandomIndexWriter w = new RandomIndexWriter(Random,
dir,
NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
.SetCodec(new PreFlexRWCodec()));

int numField = TestUtil.NextInt32(Random, 2, 5);

Expand All @@ -370,7 +378,7 @@ public virtual void TestSurrogatesOrder()
string term = GetRandomString(Random) + "_ " + (tc++);
uniqueTerms.Add(term);
fieldTerms.Add(new Term(field, term));
Documents.Document doc = new Documents.Document();
Document doc = new Document();
doc.Add(NewStringField(field, term, Field.Store.NO));
w.AddDocument(doc);
}
Expand Down Expand Up @@ -418,4 +426,4 @@ public virtual void TestSurrogatesOrder()
dir.Dispose();
}
}
}
}
17 changes: 10 additions & 7 deletions src/Lucene.Net.Tests/Codecs/Lucene3x/TestTermInfosReaderIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Globalization;
using JCG = J2N.Collections.Generic;
using Assert = Lucene.Net.TestFramework.Assert;
using J2N;
#if !FEATURE_RANDOM_NEXTINT64_NEXTSINGLE
using RandomizedTesting.Generators;
#endif

namespace Lucene.Net.Codecs.Lucene3x
{
Expand Down Expand Up @@ -79,7 +80,8 @@ public override void BeforeClass()

// NOTE: turn off compound file, this test will open some index files directly.
OldFormatImpersonationIsActive = true;
IndexWriterConfig config = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random, MockTokenizer.KEYWORD, false)).SetUseCompoundFile(false);
IndexWriterConfig config = NewIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(Random, MockTokenizer.KEYWORD, false)).SetUseCompoundFile(false);

termIndexInterval = config.TermIndexInterval;
indexDivisor = TestUtil.NextInt32(Random, 1, 10);
Expand All @@ -101,7 +103,7 @@ public override void BeforeClass()
string segment = r.SegmentName;
r.Dispose();

FieldInfosReader infosReader = (new PreFlexRWCodec()).FieldInfosFormat.FieldInfosReader;
FieldInfosReader infosReader = new PreFlexRWCodec().FieldInfosFormat.FieldInfosReader;
FieldInfos fieldInfos = infosReader.Read(directory, segment, "", IOContext.READ_ONCE);
string segmentFileName = IndexFileNames.SegmentFileName(segment, "", Lucene3xPostingsFormat.TERMS_INDEX_EXTENSION);
long tiiFileLength = directory.FileLength(segmentFileName);
Expand Down Expand Up @@ -135,7 +137,7 @@ public override void AfterClass()
[Test]
public virtual void TestSeekEnum()
{
int indexPosition = 3;
const int indexPosition = 3;
SegmentTermEnum clone = (SegmentTermEnum)termEnum.Clone();
Term term = FindTermThatWouldBeAtIndex(clone, indexPosition);
SegmentTermEnum enumerator = clone;
Expand Down Expand Up @@ -194,7 +196,8 @@ private static IList<Term> Sample(Random random, IndexReader reader, int size)
return sample;
}

private Term FindTermThatWouldBeAtIndex(SegmentTermEnum termEnum, int index)
// LUCENENET specific - made static
private static Term FindTermThatWouldBeAtIndex(SegmentTermEnum termEnum, int index)
{
int termPosition = index * termIndexInterval * indexDivisor;
for (int i = 0; i < termPosition; i++)
Expand All @@ -212,7 +215,7 @@ private Term FindTermThatWouldBeAtIndex(SegmentTermEnum termEnum, int index)
return term;
}

private void Populate(Directory directory, IndexWriterConfig config)
private static void Populate(Directory directory, IndexWriterConfig config)
{
RandomIndexWriter writer = new RandomIndexWriter(Random, directory, config);
for (int i = 0; i < NUMBER_OF_DOCUMENTS; i++)
Expand All @@ -231,4 +234,4 @@ private void Populate(Directory directory, IndexWriterConfig config)
private static string Text => Random.NextInt64().ToString(Character.MaxRadix);
}
#pragma warning restore 612, 618
}
}
32 changes: 20 additions & 12 deletions src/Lucene.Net.Tests/Codecs/Lucene40/TestBitVector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Lucene.Net.Codecs.Lucene40
using TestUtil = Lucene.Net.Util.TestUtil;

/// <summary>
/// <code>TestBitVector</code> tests the <code>BitVector</code>, obviously.
/// <see cref="TestBitVector" /> tests the <see cref="BitVector" />, obviously.
/// </summary>
[TestFixture]
public class TestBitVector : LuceneTestCase
Expand All @@ -44,14 +44,15 @@ public virtual void TestConstructSize()
DoTestConstructOfSize(1000);
}

private void DoTestConstructOfSize(int n)
// LUCENENET specific - made static
private static void DoTestConstructOfSize(int n)
{
BitVector bv = new BitVector(n);
Assert.AreEqual(n, bv.Length); // LUCENENET NOTE: Length is the equivalent of size()
}

/// <summary>
/// Test the get() and set() methods on BitVectors of various sizes.
/// Test the <see cref="BitVector.Get(int)"/> and <see cref="BitVector.Set(int)"/> methods on BitVectors of various sizes.
/// </summary>
[Test]
public virtual void TestGetSet()
Expand All @@ -62,7 +63,8 @@ public virtual void TestGetSet()
DoTestGetSetVectorOfSize(1000);
}

private void DoTestGetSetVectorOfSize(int n)
// LUCENENET specific - made static
private static void DoTestGetSetVectorOfSize(int n)
{
BitVector bv = new BitVector(n);
for (int i = 0; i < bv.Length; i++) // LUCENENET NOTE: Length is the equivalent of size()
Expand All @@ -75,7 +77,7 @@ private void DoTestGetSetVectorOfSize(int n)
}

/// <summary>
/// Test the clear() method on BitVectors of various sizes.
/// Test the <see cref="BitVector.Clear(int)" /> method on BitVectors of various sizes.
/// </summary>
[Test]
public virtual void TestClear()
Expand All @@ -86,7 +88,7 @@ public virtual void TestClear()
DoTestClearVectorOfSize(1000);
}

private void DoTestClearVectorOfSize(int n)
private static void DoTestClearVectorOfSize(int n)
{
BitVector bv = new BitVector(n);
for (int i = 0; i < bv.Length; i++) // LUCENENET NOTE: Length is the equivalent of size()
Expand All @@ -101,7 +103,7 @@ private void DoTestClearVectorOfSize(int n)
}

/// <summary>
/// Test the count() method on BitVectors of various sizes.
/// Test the <see cref="BitVector.Count()"/> method on BitVectors of various sizes.
/// </summary>
[Test]
public virtual void TestCount()
Expand All @@ -112,7 +114,8 @@ public virtual void TestCount()
DoTestCountVectorOfSize(1000);
}

private void DoTestCountVectorOfSize(int n)
// LUCENENET specific - made static
private static void DoTestCountVectorOfSize(int n)
{
BitVector bv = new BitVector(n);
// test count when incrementally setting bits
Expand Down Expand Up @@ -152,7 +155,8 @@ public virtual void TestWriteRead()
DoTestWriteRead(1000);
}

private void DoTestWriteRead(int n)
// LUCENENET specific - made static
private static void DoTestWriteRead(int n)
{
MockDirectoryWrapper d = new MockDirectoryWrapper(Random, new RAMDirectory());
d.PreventDoubleWrite = false;
Expand Down Expand Up @@ -211,7 +215,8 @@ public virtual void TestDgaps()
Assert.IsTrue(DoCompare(bv, compare));
}

private void DoTestDgaps(int size, int count1, int count2)
// LUCENENET specific - made static
private static void DoTestDgaps(int size, int count1, int count2)
{
MockDirectoryWrapper d = new MockDirectoryWrapper(Random, new RAMDirectory());
d.PreventDoubleWrite = false;
Expand Down Expand Up @@ -307,7 +312,10 @@ public virtual void TestMostlySet()
/// this should really be an equals method on the BitVector itself. </summary>
/// <param name="bv"> One bit vector </param>
/// <param name="compare"> The second to compare </param>
private bool DoCompare(BitVector bv, BitVector compare)
/// <remarks>
/// LUCENENET specific - made static
/// </remarks>
private static bool DoCompare(BitVector bv, BitVector compare)
{
bool equal = true;
for (int i = 0; i < bv.Length; i++) // LUCENENET NOTE: Length is the equivalent of size()
Expand All @@ -323,4 +331,4 @@ private bool DoCompare(BitVector bv, BitVector compare)
return equal;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace Lucene.Net.Codecs.Lucene40
/// <summary>
/// Tests Lucene40DocValuesFormat
/// </summary>
[TestFixture]
public class TestLucene40DocValuesFormat : BaseDocValuesFormatTestCase
{
private readonly Codec codec = new Lucene40RWCodec();
Expand All @@ -46,4 +47,4 @@ protected override bool CodecAcceptsHugeBinaryValues(string field)
return false;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace Lucene.Net.Codecs.Lucene40
/// <summary>
/// Tests Lucene40PostingsFormat
/// </summary>
[TestFixture]
public class TestLucene40PostingsFormat : BasePostingsFormatTestCase
{
private readonly Codec codec = new Lucene40RWCodec();
Expand All @@ -40,4 +41,4 @@ protected override Codec GetCodec()
return codec;
}
}
}
}
Loading

0 comments on commit 0af80e4

Please sign in to comment.