diff --git a/test/Microsoft.ML.Tests/CollectionDataSourceTests.cs b/test/Microsoft.ML.Tests/CollectionsDataViewTest.cs
similarity index 70%
rename from test/Microsoft.ML.Tests/CollectionDataSourceTests.cs
rename to test/Microsoft.ML.Tests/CollectionsDataViewTest.cs
index 1003620157..f599a8c850 100644
--- a/test/Microsoft.ML.Tests/CollectionDataSourceTests.cs
+++ b/test/Microsoft.ML.Tests/CollectionsDataViewTest.cs
@@ -7,9 +7,6 @@
using System.Linq;
using System.Reflection;
using Microsoft.ML.Data;
-using Microsoft.ML.Legacy.Data;
-using Microsoft.ML.Legacy.Trainers;
-using Microsoft.ML.Legacy.Transforms;
using Microsoft.ML.TestFramework;
using Xunit;
using Xunit.Abstractions;
@@ -17,241 +14,13 @@
namespace Microsoft.ML.EntryPoints.Tests
{
#pragma warning disable 612
- public class CollectionDataSourceTests : BaseTestClass
+ public class CollectionsDataViewTest : BaseTestClass
{
- public CollectionDataSourceTests(ITestOutputHelper output)
+ public CollectionsDataViewTest(ITestOutputHelper output)
: base(output)
{
}
- [Fact]
- public void CheckConstructor()
- {
- Assert.NotNull(CollectionDataSource.Create(new List() { new Input { Number1 = 1, String1 = "1" } }));
- Assert.NotNull(CollectionDataSource.Create(new Input[1] { new Input { Number1 = 1, String1 = "1" } }));
- Assert.NotNull(CollectionDataSource.Create(new Input[1] { new Input { Number1 = 1, String1 = "1" } }.AsEnumerable()));
-
- bool thrown = false;
- try
- {
- CollectionDataSource.Create(new List());
- }
- catch
- {
- thrown = true;
- }
- Assert.True(thrown);
-
- thrown = false;
- try
- {
- CollectionDataSource.Create(new Input[0]);
- }
- catch
- {
- thrown = true;
- }
- Assert.True(thrown);
- }
-
- [Fact]
- public void CanSuccessfullyApplyATransform()
- {
- var collection = CollectionDataSource.Create(new List() { new Input { Number1 = 1, String1 = "1" } });
- var environment = new MLContext();
- Experiment experiment = environment.CreateExperiment();
- Legacy.ILearningPipelineDataStep output = (Legacy.ILearningPipelineDataStep)collection.ApplyStep(null, experiment);
-
- Assert.NotNull(output.Data);
- Assert.NotNull(output.Data.VarName);
- Assert.Null(output.Model);
- }
-
- [Fact]
- public void CanSuccessfullyEnumerated()
- {
- var collection = CollectionDataSource.Create(new List() {
- new Input { Number1 = 1, String1 = "1" },
- new Input { Number1 = 2, String1 = "2" },
- new Input { Number1 = 3, String1 = "3" }
- });
-
- var environment = new MLContext();
- Experiment experiment = environment.CreateExperiment();
- Legacy.ILearningPipelineDataStep output = collection.ApplyStep(null, experiment) as Legacy.ILearningPipelineDataStep;
-
- experiment.Compile();
- collection.SetInput(environment, experiment);
- experiment.Run();
-
- IDataView data = experiment.GetOutput(output.Data);
- Assert.NotNull(data);
-
- using (var cursor = data.GetRowCursor((a => true)))
- {
- var IDGetter = cursor.GetGetter(0);
- var TextGetter = cursor.GetGetter>(1);
-
- Assert.True(cursor.MoveNext());
-
- float ID = 0;
- IDGetter(ref ID);
- Assert.Equal(1, ID);
-
- ReadOnlyMemory Text = new ReadOnlyMemory();
- TextGetter(ref Text);
- Assert.Equal("1", Text.ToString());
-
- Assert.True(cursor.MoveNext());
-
- ID = 0;
- IDGetter(ref ID);
- Assert.Equal(2, ID);
-
- Text = new ReadOnlyMemory();
- TextGetter(ref Text);
- Assert.Equal("2", Text.ToString());
-
- Assert.True(cursor.MoveNext());
-
- ID = 0;
- IDGetter(ref ID);
- Assert.Equal(3, ID);
-
- Text = new ReadOnlyMemory();
- TextGetter(ref Text);
- Assert.Equal("3", Text.ToString());
-
- Assert.False(cursor.MoveNext());
- }
- }
-
- [Fact]
- public void CanTrain()
- {
- var pipeline = new Legacy.LearningPipeline();
- var data = new List() {
- new IrisData { SepalLength = 1f, SepalWidth = 1f, PetalLength=0.3f, PetalWidth=5.1f, Label=1},
- new IrisData { SepalLength = 1f, SepalWidth = 1f, PetalLength=0.3f, PetalWidth=5.1f, Label=1},
- new IrisData { SepalLength = 1.2f, SepalWidth = 0.5f, PetalLength=0.3f, PetalWidth=5.1f, Label=0}
- };
- var collection = CollectionDataSource.Create(data);
-
- pipeline.Add(collection);
- pipeline.Add(new ColumnConcatenator(outputColumn: "Features",
- "SepalLength", "SepalWidth", "PetalLength", "PetalWidth"));
- pipeline.Add(new StochasticDualCoordinateAscentClassifier());
- var model = pipeline.Train();
-
- IrisPrediction prediction = model.Predict(new IrisData()
- {
- SepalLength = 3.3f,
- SepalWidth = 1.6f,
- PetalLength = 0.2f,
- PetalWidth = 5.1f,
- });
-
- pipeline = new Legacy.LearningPipeline();
- collection = CollectionDataSource.Create(data.AsEnumerable());
- pipeline.Add(collection);
- pipeline.Add(new ColumnConcatenator(outputColumn: "Features",
- "SepalLength", "SepalWidth", "PetalLength", "PetalWidth"));
- pipeline.Add(new StochasticDualCoordinateAscentClassifier());
- model = pipeline.Train();
-
- prediction = model.Predict(new IrisData()
- {
- SepalLength = 3.3f,
- SepalWidth = 1.6f,
- PetalLength = 0.2f,
- PetalWidth = 5.1f,
- });
-
- }
-
- [Fact]
- public void CanTrainProperties()
- {
- var pipeline = new Legacy.LearningPipeline();
- var data = new List() {
- new IrisData { SepalLength = 1f, SepalWidth = 1f, PetalLength=0.3f, PetalWidth=5.1f, Label=1},
- new IrisData { SepalLength = 1f, SepalWidth = 1f, PetalLength=0.3f, PetalWidth=5.1f, Label=1},
- new IrisData { SepalLength = 1.2f, SepalWidth = 0.5f, PetalLength=0.3f, PetalWidth=5.1f, Label=0}
- };
- var collection = CollectionDataSource.Create(data);
-
- pipeline.Add(collection);
- pipeline.Add(new ColumnConcatenator(outputColumn: "Features",
- "SepalLength", "SepalWidth", "PetalLength", "PetalWidth"));
- pipeline.Add(new StochasticDualCoordinateAscentClassifier());
- var model = pipeline.Train();
-
- IrisPredictionProperties prediction = model.Predict(new IrisData
- {
- SepalLength = 3.3f,
- SepalWidth = 1.6f,
- PetalLength = 0.2f,
- PetalWidth = 5.1f,
- });
-
- pipeline = new Legacy.LearningPipeline();
- collection = CollectionDataSource.Create(data.AsEnumerable());
- pipeline.Add(collection);
- pipeline.Add(new ColumnConcatenator(outputColumn: "Features",
- "SepalLength", "SepalWidth", "PetalLength", "PetalWidth"));
- pipeline.Add(new StochasticDualCoordinateAscentClassifier());
- model = pipeline.Train();
-
- prediction = model.Predict(new IrisData
- {
- SepalLength = 3.3f,
- SepalWidth = 1.6f,
- PetalLength = 0.2f,
- PetalWidth = 5.1f,
- });
-
- }
-
- public class Input
- {
- [LoadColumn(0)]
- public float Number1;
-
- [LoadColumn(1)]
- public string String1;
- }
-
- public class IrisData
- {
- [LoadColumn(0)]
- public float Label;
-
- [LoadColumn(1)]
- public float SepalLength;
-
- [LoadColumn(2)]
- public float SepalWidth;
-
- [LoadColumn(3)]
- public float PetalLength;
-
- [LoadColumn(4)]
- public float PetalWidth;
- }
-
- public class IrisPrediction
- {
- [ColumnName("Score")]
- public float[] PredictedLabels;
- }
-
- public class IrisPredictionProperties
- {
- private float[] _PredictedLabels;
- [ColumnName("Score")]
- public float[] PredictedLabels { get { return _PredictedLabels; } set { _PredictedLabels = value; } }
- }
-
public class ConversionSimpleClass
{
public int fInt;