Skip to content

Commit

Permalink
Reviewed classification tests and made minor changes. Part of issue #259
Browse files Browse the repository at this point in the history
 (#420)

* Reviewed classification tests. Made minor changes and uncommented 1 test and verified it passes.  See issue #259

* Finished my work ;-)
  • Loading branch information
rclabo authored Feb 12, 2021
1 parent 1ff46c0 commit d13f8cf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Lucene.Net.Attributes;
using Lucene.Net.Attributes;
using Lucene.Net.Util;
using NUnit.Framework;
using System;
Expand Down Expand Up @@ -111,7 +111,7 @@ public override void TestForPublicMembersNamedSize(Type typeFromTargetAssembly)
public override void TestForPublicMembersContainingNonNetNumeric(Type typeFromTargetAssembly)
{
base.TestForPublicMembersContainingNonNetNumeric(typeFromTargetAssembly);
}
}

[Test, LuceneNetSpecific]
[TestCase(typeof(Lucene.Net.Classification.KNearestNeighborClassifier))]
Expand All @@ -129,12 +129,12 @@ public override void TestForPublicMembersWithNullableEnum(Type typeFromTargetAss

// LUCENENET NOTE: This test is only for identifying members who were changed from
// ICollection, IList or ISet to IEnumerable during the port (that should be changed back)
//[Test, LuceneNetSpecific]
//[TestCase(typeof(Lucene.Net.Classification.KNearestNeighborClassifier))]
//public override void TestForMembersAcceptingOrReturningIEnumerable(Type typeFromTargetAssembly)
//{
// base.TestForMembersAcceptingOrReturningIEnumerable(typeFromTargetAssembly);
//}
[Test, LuceneNetSpecific]
[TestCase(typeof(Lucene.Net.Classification.KNearestNeighborClassifier))]
public override void TestForMembersAcceptingOrReturningIEnumerable(Type typeFromTargetAssembly)
{
base.TestForMembersAcceptingOrReturningIEnumerable(typeFromTargetAssembly);
}

[Test, LuceneNetSpecific]
[TestCase(typeof(Lucene.Net.Classification.KNearestNeighborClassifier))]
Expand Down
42 changes: 21 additions & 21 deletions src/Lucene.Net.Tests.Classification/Utils/DataSplitterTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Text;
using Lucene.Net.Analysis;
using Lucene.Net.Classification.Utils;
Expand Down Expand Up @@ -32,24 +32,24 @@ namespace Lucene.Net.Classification
*/
public class DataSplitterTest : Util.LuceneTestCase
{
private AtomicReader _originalIndex;
private RandomIndexWriter _indexWriter;
private Directory _dir;
private AtomicReader originalIndex;
private RandomIndexWriter indexWriter;
private Directory dir;

private String _textFieldName = "text";
private String _classFieldName = "class";
private String _idFieldName = "id";
private String textFieldName = "text";
private String classFieldName = "class";
private String idFieldName = "id";

[SetUp]
public override void SetUp()
{
base.SetUp();
_dir = NewDirectory();
_indexWriter = new RandomIndexWriter(
dir = NewDirectory();
indexWriter = new RandomIndexWriter(
#if FEATURE_INSTANCE_TESTDATA_INITIALIZATION
this,
#endif
Random, _dir, new MockAnalyzer(Random));
Random, dir, new MockAnalyzer(Random));

FieldType ft = new FieldType(TextField.TYPE_STORED);
ft.StoreTermVectors = true;
Expand All @@ -62,38 +62,38 @@ public override void SetUp()
for (int i = 0; i < 100; i++)
{
doc = new Document();
doc.Add(new Field(_idFieldName, Random.toString(), ft));
doc.Add(new Field(_textFieldName, new StringBuilder(Random.toString()).append(Random.toString()).append(
doc.Add(new Field(idFieldName, Random.toString(), ft));
doc.Add(new Field(textFieldName, new StringBuilder(Random.toString()).append(Random.toString()).append(
Random.toString()).toString(), ft));
doc.Add(new Field(_classFieldName, Random.toString(), ft));
_indexWriter.AddDocument(doc, analyzer);
doc.Add(new Field(classFieldName, Random.toString(), ft));
indexWriter.AddDocument(doc, analyzer);
}

_indexWriter.Commit();
indexWriter.Commit();

_originalIndex = SlowCompositeReaderWrapper.Wrap(_indexWriter.GetReader());
originalIndex = SlowCompositeReaderWrapper.Wrap(indexWriter.GetReader());
}

[TearDown]
public override void TearDown()
{
_originalIndex.Dispose();
_indexWriter.Dispose();
_dir.Dispose();
originalIndex.Dispose();
indexWriter.Dispose();
dir.Dispose();
base.TearDown();
}

[Test]
public void TestSplitOnAllFields()
{
AssertSplit(_originalIndex, 0.1, 0.1);
AssertSplit(originalIndex, 0.1, 0.1);
}


[Test]
public void TestSplitOnSomeFields()
{
AssertSplit(_originalIndex, 0.2, 0.35, _idFieldName, _textFieldName);
AssertSplit(originalIndex, 0.2, 0.35, idFieldName, textFieldName);
}

public static void AssertSplit(AtomicReader originalIndex, double testRatio, double crossValidationRatio, params string[] fieldNames)
Expand Down

0 comments on commit d13f8cf

Please sign in to comment.