diff options
author | Serghei Cebotari <serghei@cebotari.ru> | 2023-12-29 11:24:23 +0300 |
---|---|---|
committer | Serghei Cebotari <serghei@cebotari.ru> | 2023-12-29 11:24:23 +0300 |
commit | 7e22efde3f3be8d9f39856eb704d438feae8eb0f (patch) | |
tree | abacfa6f3309b27457ccb35a17cf75659ce4ba40 /RhSolutions.ML.Tests/TestBase.cs | |
parent | 3be0df94c032b945af803d5056fb01df7af417f3 (diff) |
Implement Data driven tests
Diffstat (limited to 'RhSolutions.ML.Tests/TestBase.cs')
-rw-r--r-- | RhSolutions.ML.Tests/TestBase.cs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/RhSolutions.ML.Tests/TestBase.cs b/RhSolutions.ML.Tests/TestBase.cs new file mode 100644 index 0000000..679d9d3 --- /dev/null +++ b/RhSolutions.ML.Tests/TestBase.cs @@ -0,0 +1,39 @@ +using RhSolutions.ML.Lib; + +namespace RhSolutions.ML.Tests; + +public abstract class TestBase +{ + 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; + + public TestBase() + { + RhSolutionsMLBuilder.RebuildModel(); + _mlContext = new MLContext(seed: 0); + ITransformer loadedNodel = _mlContext.Model.Load(_dataPath, out var _); + _predEngine = _mlContext.Model.CreatePredictionEngine<Product, TypePrediction>(loadedNodel); + } + + public void Execute(string name, string expectedGroup) + { + Product p = new() + { + Name = name + }; + var prediction = _predEngine.Predict(p); + Assert.That(prediction.Type, Is.EqualTo(expectedGroup)); + } + + public void Execute(Product expected) + { + Product actual = new() + { + Name = expected.Name + }; + var prediction = _predEngine.Predict(actual); + Assert.That(prediction.Type, Is.EqualTo(expected.Type)); + } +}
\ No newline at end of file |