public void Test() { //Given var file = new StringBuilder().AppendLine("5.1,3.5,1.4,0.2,Iris-setosa") .AppendLine("4.7,3.2,1.3,0.2,Iris-setosa") .AppendLine("5.9,3.2,4.8,1.8,Iris-versicolor") .AppendLine("6.0,2.2,5.0,1.5,Iris-virginica") .ToString(); var fileBuffer = Encoding.ASCII.GetBytes(file); var reader = new IrisDataReader(); IList <IrisRecord> records; //When using (var stream = new MemoryStream(fileBuffer)) { records = reader.Read(stream); } //Then records.Should().HaveCount(4, "Because it is number of records in the file"); records[0].SepalLength.ShouldBeEquivalentTo(5.1m); records[0].SepalWidth.ShouldBeEquivalentTo(3.5m); records[0].PetalLength.ShouldBeEquivalentTo(1.4m); records[0].PetalWidth.ShouldBeEquivalentTo(0.2m); records[0].Classification.ShouldBeEquivalentTo("Iris-setosa"); }
private void ReadFile(object sender, RoutedEventArgs e) { try { using (var stream = new FileStream(FilePath.Text, FileMode.Open)) { _irisRecords = _irisDataReader.Read(stream); IrisRecords.ItemsSource = _irisRecords; GenerateTrainingSetButton.IsEnabled = true; TrainingSetSize.Maximum = _irisRecords.Count; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }