0
0
RhSolutions-ML/RhSolutions.ML.Tests/TestBase.cs

37 lines
1.0 KiB
C#
Raw Normal View History

2023-10-03 21:43:15 +03:00
namespace RhSolutions.ML.Tests;
2023-12-29 11:24:23 +03:00
public abstract class TestBase
2023-10-03 21:43:15 +03:00
{
protected static string _appPath = Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]) ?? ".";
protected static string _dataPath = Path.Combine(_appPath, "..", "..", "..", "..", "Models", "model.zip");
protected MLContext _mlContext;
protected PredictionEngine<Product, TypePrediction> _predEngine;
2023-12-29 00:05:17 +03:00
2023-12-29 11:24:23 +03:00
public TestBase()
2023-10-03 21:43:15 +03:00
{
_mlContext = new MLContext(seed: 0);
2024-01-12 00:01:11 +03:00
ITransformer loadedModel = _mlContext.Model.Load(_dataPath, out var _);
_predEngine = _mlContext.Model.CreatePredictionEngine<Product, TypePrediction>(loadedModel);
2023-10-03 21:43:15 +03:00
}
public void Execute(string name, string expectedGroup)
{
Product p = new()
{
Name = name
};
var prediction = _predEngine.Predict(p);
Assert.That(prediction.Type, Is.EqualTo(expectedGroup));
2023-12-29 00:05:17 +03:00
}
2023-12-29 11:24:23 +03:00
public void Execute(Product expected)
{
Product actual = new()
{
Name = expected.Name
};
var prediction = _predEngine.Predict(actual);
Assert.That(prediction.Type, Is.EqualTo(expected.Type));
}
2024-01-11 17:48:01 +03:00
}