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

23 lines
650 B
C#
Raw Normal View History

2023-12-29 11:24:23 +03:00
using System.Collections;
namespace RhSolutions.ML.Tests;
public abstract class DatasetBase : IEnumerable
{
protected virtual string FileName {get;set;} = string.Empty;
public IEnumerator GetEnumerator()
{
string path = Path.Combine("..", "..", "..", "TestData", $"{FileName}.csv");
using FileStream stream = new(path, FileMode.Open, FileAccess.Read);
StreamReader reader = new(stream);
string? inputLine = reader.ReadLine();
while (inputLine != null)
{
var data = inputLine.Split(';');
yield return new Product { Name = data[0], Type = data[1] };
inputLine = reader.ReadLine();
}
reader.Close();
stream.Close();
}
}