using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Deltares.Geometry;
using Deltares.Geotechnics.GeotechnicalGeometry;
using Deltares.Geotechnics.IO.Importers;
using Deltares.Standard.Extensions;
using Deltares.Standard.Forms;
using NUnit.Framework;
namespace Deltares.Geotechnics.IO.Tests
{
[TestFixture]
public class CharacteristicPointsImporterTest
{
///
/// Check if Import() returns the correct characteristic points.
///
[Test]
[TestCase(characteristicPointsFilename)] // Ringtoets format
[TestCase("characteristicpointsDAM.csv")] // Dam format
public void ImportRefusesCharacteristicPointsWithoutReadingSurfaceLines(string fileName)
{
var fullName = Path.Combine(mapTestData, fileName);
var characteristicPointsImporter = new CharacteristicPointsImporter();
List surfaceLines = new List(); // empty list of surfaces
characteristicPointsImporter.Read(fullName, surfaceLines);
Assert.AreEqual(0, surfaceLines.Count, "Read incorrect number of surface lines in import of characteristic points");
}
[Test]
public void Import_RD_coordinates_on_LocalizedGeometryPointString()
{
var name = "haha";
var localizedGeometryPointString = new LocalizedGeometryPointString
{
Name = name
};
var schematizedSurfaceLine = new SurfaceLine2
{
CharacteristicPoints =
{
GeometryMustContainPoint = false
},
Geometry = localizedGeometryPointString,
Name = name
};
localizedGeometryPointString.Points.AddRange(new[]
{
new GeometryPoint(104, 102, 4), new GeometryPoint(100, 100, 0)
});
localizedGeometryPointString.ConvertGlobalToLocalXZSurfaceLine();
//check localisation
Assert.AreEqual(100, localizedGeometryPointString.OriginalXy.X);
Assert.AreEqual(0, localizedGeometryPointString.Points.First().X);
Assert.AreEqual(Math.Sqrt(Math.Pow(4, 2) + Math.Pow(2, 2)), localizedGeometryPointString.Points.Last().X, 0.00001);
//Import characteristic point
var characteristicPointsImporterMock = new CharacteristicPointsImporterMock();
characteristicPointsImporterMock.AddCharacteristicPointToSurfaceLine(schematizedSurfaceLine, 102, 101, 2, CharacteristicPointType.DikeToeAtRiver, false);
Assert.AreEqual(1, schematizedSurfaceLine.CharacteristicPoints.Count);
Assert.AreEqual(Math.Sqrt(Math.Pow(2, 2) + Math.Pow(1, 2)), schematizedSurfaceLine.CharacteristicPoints.First().X, 0.00001);
Assert.AreEqual(0, schematizedSurfaceLine.CharacteristicPoints.First().Y);
Assert.AreEqual(2, schematizedSurfaceLine.CharacteristicPoints.First().Z);
}
private string mapTestData = Path.Combine(@"..\..\..\data","D-Soil Model", "CSVImportTest") ;
private const string characteristicPointsFilename = "characteristicpoints.csv";
private const string surfaceLinesFilename = "surfacelines.csv";
private const double tolerance = 0.0000001;
[TestFixtureSetUp]
public void TestFixtureSetUp()
{
Messenger.RerouteMessageBoxMessages = true;
}
public class CharacteristicPointsImporterMock : CharacteristicPointsImporter
{
public new bool AddCharacteristicPointToSurfaceLine(SurfaceLine2 surfaceLine, double xGlobal, double yGlobal, double zGlobal, CharacteristicPointType type, bool isAddPointToSurfaceLineIfMissing)
{
return base.AddCharacteristicPointToSurfaceLine(surfaceLine, xGlobal, yGlobal, zGlobal, type, isAddPointToSurfaceLineIfMissing);
}
}
}
}