// Copyright (C) Stichting Deltares 2017. All rights reserved.
//
// This file is part of the D-Soil Model application.
//
// The D-Soil Model application is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System.Drawing;
using System.IO;
using Deltares.Geotechnics;
using Deltares.Geotechnics.Soils;
using Deltares.Standard.Logging;
using NUnit.Framework;
namespace Deltares.DSoilModel.Data.Tests
{
[TestFixture]
public class SosSoilProfilesImporterTests
{
///
/// Test of the import of surface lines from Csv file
///
[Test]
public void DSoilModelIO_ImportFromCsvFile()
{
string csvFilePath = Path.Combine(GetTestFilesPath(), "DSoilModelsoilprofiles.csv");
// Locate the test files.
var currentDirectory = Directory.GetCurrentDirectory();
var csvFullFileName = Path.Combine(currentDirectory, csvFilePath);
using (var project = new DSoilModelProject())
{
project.ReadSoilProfiles1DFromFile(csvFullFileName);
Assert.AreEqual(10, project.SoilProfiles1D.Count, "The number of profiles read from the csv file is not right.");
Assert.AreEqual("Segment_11_1D1", project.SoilProfiles1D[0].Name);
Assert.AreEqual(4, project.SoilProfiles1D[0].LayerCount, "The number of layers in the first profile read from csv file is not right.");
Assert.AreEqual(1, project.SoilProfiles1D[0].Layers[0].TopLevel);
Assert.AreEqual(2.5, (project.SoilProfiles1D[0].Layers[0] as SosSoilLayer1D).MaximumTopLevel);
Assert.AreEqual(-0.5, (project.SoilProfiles1D[0].Layers[0] as SosSoilLayer1D).MinimumTopLevel);
Assert.AreEqual("", (project.SoilProfiles1D[0].Layers[0] as SosSoilLayer1D).RemarkTopLevel);
Assert.AreEqual(-9.5, project.SoilProfiles1D[0].Layers[2].TopLevel);
Assert.AreEqual(13.25, (project.SoilProfiles1D[0].Layers[2] as SosSoilLayer1D).MaximumTopLevel);
Assert.AreEqual(-9.5, (project.SoilProfiles1D[0].Layers[2] as SosSoilLayer1D).MinimumTopLevel);
Assert.AreEqual("Aan basis max. 25 cm basisveen", (project.SoilProfiles1D[0].Layers[2] as SosSoilLayer1D).RemarkTopLevel);
}
}
[Test]
public void DSoilModelIO_ImportFromCsvFileWithErrors()
{
string csvFilePath = Path.Combine(GetTestFilesPath(), "DSoilModelsoilprofilesWithErrors.csv");
// Locate the test files.
var currentDirectory = Directory.GetCurrentDirectory();
var csvFullFileName = Path.Combine(currentDirectory, csvFilePath);
LogManager.Messages.Clear();
using (var project = new DSoilModelProject())
{
project.ReadSoilProfiles1DFromFile(csvFullFileName);
Assert.AreEqual(1, project.SoilProfiles1D.Count, "The number of profiles read from the csv file is not right.");
Assert.AreEqual("Segment_11_1D1", project.SoilProfiles1D[0].Name);
Assert.AreEqual(4, project.SoilProfiles1D[0].LayerCount, "The number of layers in the first profile read from csv file is not right.");
Assert.AreEqual(1, project.SoilProfiles1D[0].Layers[0].TopLevel);
Assert.AreEqual(2.5, (project.SoilProfiles1D[0].Layers[0] as SosSoilLayer1D).MaximumTopLevel);
Assert.AreEqual(-0.5, (project.SoilProfiles1D[0].Layers[0] as SosSoilLayer1D).MinimumTopLevel);
Assert.AreEqual("", (project.SoilProfiles1D[0].Layers[0] as SosSoilLayer1D).RemarkTopLevel);
// Log contains 9 profile errors, 47 layer errors and 13 soil errors.
Assert.AreEqual(69, LogManager.Messages.Count);
}
}
[Test]
public void DSoilModelIO_ImportFromCsvFileWithTypes()
{
string csvFilePath = Path.Combine(GetTestFilesPath(), "DSoilModelsoilprofilesWithSoilTypes.csv");
// Locate the test files.
var currentDirectory = Directory.GetCurrentDirectory();
var csvFullFileName = Path.Combine(currentDirectory, csvFilePath);
using (var project = new DSoilModelProject())
{
project.ReadSoilProfiles1DFromFile(csvFullFileName);
Assert.AreEqual(3, project.SoilProfiles1D.Count, "The number of profiles read from the csv file is not right.");
Assert.AreEqual("Segment_11_1D1", project.SoilProfiles1D[0].Name);
Assert.AreEqual(4, project.SoilProfiles1D[0].LayerCount, "The number of layers in the first profile read from csv file is not right.");
Assert.AreEqual(1, project.SoilProfiles1D[0].Layers[0].TopLevel);
Assert.AreEqual(2.5, (project.SoilProfiles1D[0].Layers[0] as SosSoilLayer1D).MaximumTopLevel);
Assert.AreEqual(-0.5, (project.SoilProfiles1D[0].Layers[0] as SosSoilLayer1D).MinimumTopLevel);
Assert.AreEqual("", (project.SoilProfiles1D[0].Layers[0] as SosSoilLayer1D).RemarkTopLevel);
Assert.AreEqual(-9.5, project.SoilProfiles1D[0].Layers[2].TopLevel);
Assert.AreEqual(13.25, (project.SoilProfiles1D[0].Layers[2] as SosSoilLayer1D).MaximumTopLevel);
Assert.AreEqual(-9.5, (project.SoilProfiles1D[0].Layers[2] as SosSoilLayer1D).MinimumTopLevel);
Assert.AreEqual("Aan basis max. 25 cm basisveen", (project.SoilProfiles1D[0].Layers[2] as SosSoilLayer1D).RemarkTopLevel);
Assert.AreEqual(SoilType.Sand, project.SoilProfiles1D[0].Layers[0].Soil.SoilType);
Assert.AreEqual(SoilType.Clay, project.SoilProfiles1D[0].Layers[1].Soil.SoilType);
Assert.AreEqual(SoilType.Clay, project.SoilProfiles1D[0].Layers[2].Soil.SoilType);
Assert.AreEqual(SoilType.Peat, project.SoilProfiles1D[0].Layers[3].Soil.SoilType);
Assert.AreEqual(SoilType.Gravel, project.SoilProfiles1D[1].Layers[0].Soil.SoilType);
Assert.AreEqual(SoilType.Gravel, project.SoilProfiles1D[1].Layers[1].Soil.SoilType);
Assert.AreEqual(SoilType.Sand, project.SoilProfiles1D[1].Layers[2].Soil.SoilType);
Assert.AreEqual(SoilType.Loam, project.SoilProfiles1D[1].Layers[3].Soil.SoilType);
Assert.AreEqual(SoilType.Loam, project.SoilProfiles1D[2].Layers[0].Soil.SoilType);
Assert.AreEqual(SoilType.Sand, project.SoilProfiles1D[2].Layers[1].Soil.SoilType);
Assert.AreEqual(SoilType.Peat, project.SoilProfiles1D[2].Layers[2].Soil.SoilType);
Assert.AreEqual(SoilType.Gravel, project.SoilProfiles1D[2].Layers[3].Soil.SoilType);
Assert.AreEqual(SoilType.Loam, project.SoilProfiles1D[2].Layers[4].Soil.SoilType);
Assert.AreEqual(SoilType.Sand, project.SoilProfiles1D[2].Layers[5].Soil.SoilType);
}
}
[Test]
public void DSoilModelIO_ImportFromCsvFileWithTypesAndColors()
{
string csvFilePath = Path.Combine(GetTestFilesPath(), "DSoilModelsoilprofilesWithSoilTypesAndColorUniqueSoils.csv");
// Locate the test files.
var currentDirectory = Directory.GetCurrentDirectory();
var csvFullFileName = Path.Combine(currentDirectory, csvFilePath);
using (var project = new DSoilModelProject())
{
project.ReadSoilProfiles1DFromFile(csvFullFileName);
Assert.AreEqual(3, project.SoilProfiles1D.Count, "The number of profiles read from the csv file is not right.");
Assert.AreEqual("Segment_11_1D1", project.SoilProfiles1D[0].Name);
Assert.AreEqual(4, project.SoilProfiles1D[0].LayerCount, "The number of layers in the first profile read from csv file is not right.");
Assert.AreEqual(1, project.SoilProfiles1D[0].Layers[0].TopLevel);
Assert.AreEqual(2.5, (project.SoilProfiles1D[0].Layers[0] as SosSoilLayer1D).MaximumTopLevel);
Assert.AreEqual(-0.5, (project.SoilProfiles1D[0].Layers[0] as SosSoilLayer1D).MinimumTopLevel);
Assert.AreEqual("", (project.SoilProfiles1D[0].Layers[0] as SosSoilLayer1D).RemarkTopLevel);
Assert.AreEqual(-9.5, project.SoilProfiles1D[0].Layers[2].TopLevel);
Assert.AreEqual(13.25, (project.SoilProfiles1D[0].Layers[2] as SosSoilLayer1D).MaximumTopLevel);
Assert.AreEqual(-9.5, (project.SoilProfiles1D[0].Layers[2] as SosSoilLayer1D).MinimumTopLevel);
Assert.AreEqual("Aan basis max. 25 cm basisveen", (project.SoilProfiles1D[0].Layers[2] as SosSoilLayer1D).RemarkTopLevel);
Assert.AreEqual(SoilType.Sand, project.SoilProfiles1D[0].Layers[0].Soil.SoilType);
Assert.AreEqual(SoilType.Clay, project.SoilProfiles1D[0].Layers[1].Soil.SoilType);
Assert.AreEqual(SoilType.Clay, project.SoilProfiles1D[0].Layers[2].Soil.SoilType);
Assert.AreEqual(SoilType.Peat, project.SoilProfiles1D[0].Layers[3].Soil.SoilType);
Assert.AreEqual(SoilType.Gravel, project.SoilProfiles1D[1].Layers[0].Soil.SoilType);
Assert.AreEqual(SoilType.Gravel, project.SoilProfiles1D[1].Layers[1].Soil.SoilType);
Assert.AreEqual(SoilType.Sand, project.SoilProfiles1D[1].Layers[2].Soil.SoilType);
Assert.AreEqual(SoilType.Loam, project.SoilProfiles1D[1].Layers[3].Soil.SoilType);
Assert.AreEqual(SoilType.Loam, project.SoilProfiles1D[2].Layers[0].Soil.SoilType);
Assert.AreEqual(SoilType.Sand, project.SoilProfiles1D[2].Layers[1].Soil.SoilType);
Assert.AreEqual(SoilType.Peat, project.SoilProfiles1D[2].Layers[2].Soil.SoilType);
Assert.AreEqual(SoilType.Gravel, project.SoilProfiles1D[2].Layers[3].Soil.SoilType);
Assert.AreEqual(SoilType.Loam, project.SoilProfiles1D[2].Layers[4].Soil.SoilType);
Assert.AreEqual(SoilType.Sand, project.SoilProfiles1D[2].Layers[5].Soil.SoilType);
Assert.AreEqual(Color.Bisque, project.SoilProfiles1D[0].Layers[0].Soil.Color);
Assert.AreEqual(Color.CadetBlue, project.SoilProfiles1D[0].Layers[1].Soil.Color);
Assert.AreEqual(Color.Chocolate, project.SoilProfiles1D[0].Layers[2].Soil.Color);
Assert.AreEqual(Color.Maroon, project.SoilProfiles1D[0].Layers[3].Soil.Color);
Assert.AreEqual(Color.Linen, project.SoilProfiles1D[1].Layers[0].Soil.Color);
Assert.AreEqual(Color.Orchid, project.SoilProfiles1D[1].Layers[1].Soil.Color);
Assert.AreEqual(Color.Yellow, project.SoilProfiles1D[1].Layers[2].Soil.Color);
Assert.AreEqual(Color.Red, project.SoilProfiles1D[1].Layers[3].Soil.Color);
Assert.AreEqual(Color.Blue, project.SoilProfiles1D[2].Layers[0].Soil.Color);
Assert.AreEqual(Color.Azure, project.SoilProfiles1D[2].Layers[1].Soil.Color);
Assert.AreEqual(Color.Beige, project.SoilProfiles1D[2].Layers[2].Soil.Color);
Assert.AreEqual(Color.Coral, project.SoilProfiles1D[2].Layers[3].Soil.Color);
Assert.AreEqual(Color.Cyan, project.SoilProfiles1D[2].Layers[4].Soil.Color);
Assert.AreEqual(Color.Red, project.SoilProfiles1D[2].Layers[5].Soil.Color);
}
}
[Test]
public void DSoilModelIO_ImportFromCsvFileWithTypesAndColorsWithDoubleSoils()
{
string csvFilePath = Path.Combine(GetTestFilesPath(), "DSoilModelsoilprofilesWithSoilTypesAndColor.csv");
// Locate the test files.
var currentDirectory = Directory.GetCurrentDirectory();
var csvFullFileName = Path.Combine(currentDirectory, csvFilePath);
using (var project = new DSoilModelProject())
{
project.ReadSoilProfiles1DFromFile(csvFullFileName);
Assert.AreEqual(3, project.SoilProfiles1D.Count, "The number of profiles read from the csv file is not right.");
Assert.AreEqual("Segment_11_1D1", project.SoilProfiles1D[0].Name);
Assert.AreEqual(4, project.SoilProfiles1D[0].LayerCount, "The number of layers in the first profile read from csv file is not right.");
Assert.AreEqual(1, project.SoilProfiles1D[0].Layers[0].TopLevel);
Assert.AreEqual(2.5, (project.SoilProfiles1D[0].Layers[0] as SosSoilLayer1D).MaximumTopLevel);
Assert.AreEqual(-0.5, (project.SoilProfiles1D[0].Layers[0] as SosSoilLayer1D).MinimumTopLevel);
Assert.AreEqual("", (project.SoilProfiles1D[0].Layers[0] as SosSoilLayer1D).RemarkTopLevel);
Assert.AreEqual(-9.5, project.SoilProfiles1D[0].Layers[2].TopLevel);
Assert.AreEqual(13.25, (project.SoilProfiles1D[0].Layers[2] as SosSoilLayer1D).MaximumTopLevel);
Assert.AreEqual(-9.5, (project.SoilProfiles1D[0].Layers[2] as SosSoilLayer1D).MinimumTopLevel);
Assert.AreEqual("Aan basis max. 25 cm basisveen", (project.SoilProfiles1D[0].Layers[2] as SosSoilLayer1D).RemarkTopLevel);
Assert.AreEqual(SoilType.Sand, project.SoilProfiles1D[0].Layers[0].Soil.SoilType);
Assert.AreEqual(SoilType.Clay, project.SoilProfiles1D[0].Layers[1].Soil.SoilType);
Assert.AreEqual(SoilType.Clay, project.SoilProfiles1D[0].Layers[2].Soil.SoilType);
Assert.AreEqual(SoilType.Peat, project.SoilProfiles1D[0].Layers[3].Soil.SoilType);
//Double so equal to 0, 0
Assert.AreEqual(SoilType.Sand, project.SoilProfiles1D[1].Layers[0].Soil.SoilType);
//Double so equal to 0, 1
Assert.AreEqual(SoilType.Clay, project.SoilProfiles1D[1].Layers[1].Soil.SoilType);
Assert.AreEqual(SoilType.Sand, project.SoilProfiles1D[1].Layers[2].Soil.SoilType);
//Double so equal to 0, 4
Assert.AreEqual(SoilType.Peat, project.SoilProfiles1D[1].Layers[3].Soil.SoilType);
Assert.AreEqual(SoilType.Loam, project.SoilProfiles1D[2].Layers[0].Soil.SoilType);
Assert.AreEqual(SoilType.Sand, project.SoilProfiles1D[2].Layers[1].Soil.SoilType);
Assert.AreEqual(SoilType.Peat, project.SoilProfiles1D[2].Layers[2].Soil.SoilType);
Assert.AreEqual(SoilType.Gravel, project.SoilProfiles1D[2].Layers[3].Soil.SoilType);
Assert.AreEqual(SoilType.Loam, project.SoilProfiles1D[2].Layers[4].Soil.SoilType);
//Double so equal to 0, 4
Assert.AreEqual(SoilType.Peat, project.SoilProfiles1D[2].Layers[5].Soil.SoilType);
Assert.AreEqual(Color.Bisque, project.SoilProfiles1D[0].Layers[0].Soil.Color);
Assert.AreEqual(Color.CadetBlue, project.SoilProfiles1D[0].Layers[1].Soil.Color);
Assert.AreEqual(Color.Chocolate, project.SoilProfiles1D[0].Layers[2].Soil.Color);
Assert.AreEqual(Color.Maroon, project.SoilProfiles1D[0].Layers[3].Soil.Color);
//Double so equal to 0, 0
Assert.AreEqual(Color.Bisque, project.SoilProfiles1D[1].Layers[0].Soil.Color);
//Double so equal to 0, 1
Assert.AreEqual(Color.CadetBlue, project.SoilProfiles1D[1].Layers[1].Soil.Color);
Assert.AreEqual(Color.Yellow, project.SoilProfiles1D[1].Layers[2].Soil.Color);
//Double so equal to 0, 4
Assert.AreEqual(Color.Maroon, project.SoilProfiles1D[1].Layers[3].Soil.Color);
Assert.AreEqual(Color.Blue, project.SoilProfiles1D[2].Layers[0].Soil.Color);
Assert.AreEqual(Color.Azure, project.SoilProfiles1D[2].Layers[1].Soil.Color);
Assert.AreEqual(Color.Beige, project.SoilProfiles1D[2].Layers[2].Soil.Color);
Assert.AreEqual(Color.Coral, project.SoilProfiles1D[2].Layers[3].Soil.Color);
Assert.AreEqual(Color.Cyan, project.SoilProfiles1D[2].Layers[4].Soil.Color);
//Double so equal to 0, 4
Assert.AreEqual(Color.Maroon, project.SoilProfiles1D[2].Layers[5].Soil.Color);
}
}
[Test]
public void DSoilModelIO_ImportFromCsvFileWithInvalidHeaders()
{
string csvFilePath = Path.Combine(GetTestFilesPath(), "DSoilModelsoilprofilesWithInvalidHeaders.csv");
// Locate the test files.
var currentDirectory = Directory.GetCurrentDirectory();
var csvFullFileName = Path.Combine(currentDirectory, csvFilePath);
LogManager.Messages.Clear();
using (var project = new DSoilModelProject())
{
project.ReadSoilProfiles1DFromFile(csvFullFileName);
Assert.AreEqual(5,LogManager.Messages.Count, "Expected five messages");
Assert.AreNotEqual(0,project.SoilProfiles1D.Count, "Expected the profiles were read anyway");
}
}
[Test]
public void DSoilModelIO_ImportFromCsvFileWithMissingHeaders()
{
string csvFilePath = Path.Combine(GetTestFilesPath(), "DSoilModelsoilprofilesWithMissingHeaders.csv");
// Locate the test files.
var currentDirectory = Directory.GetCurrentDirectory();
var csvFullFileName = Path.Combine(currentDirectory, csvFilePath);
LogManager.Messages.Clear();
using (var project = new DSoilModelProject())
{
project.ReadSoilProfiles1DFromFile(csvFullFileName);
Assert.AreEqual(2, LogManager.Messages.Count, "Expected two messages");
Assert.AreEqual(0, project.SoilProfiles1D.Count, "Expected the profiles were not read");
}
}
private string GetTestFilesPath()
{
return Path.GetFullPath(@"..\..\Deltares.DSoilModel.Data.Tests\TestFiles");
}
}
}