// Copyright (C) Stichting Deltares 2025. All rights reserved.
//
// This file is part of the application DAM - UI.
//
// DAM - UI 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;
using Deltares.Dam.Data;
using NUnit.Framework;
namespace Deltares.Dam.Tests
{
[TestFixture]
public class Geometry2DDataTests
{
[Test]
public void AddBoundaryLineIncreasesCount()
{
var geometry2DData = new Geometry2DData();
Assert.That(geometry2DData.LayerCount, Is.EqualTo(0), "New Geometry2DData object should have no boundary lines");
geometry2DData.AddLayer(new Geometry2DLayer());
Assert.That(geometry2DData.LayerCount, Is.EqualTo(1), "Adding boundary line did not increase boundary line count");
}
[Test]
public void GetBoundaryLineReturnsCorrectObject()
{
var geometry2DData = new Geometry2DData();
var geometry2DBoundaryLine0 = new Geometry2DBoundaryLine();
geometry2DBoundaryLine0.Points.Add(new Geometry2DPoint(1.0, 0.0));
geometry2DBoundaryLine0.Points.Add(new Geometry2DPoint(10.0, 1.1));
geometry2DData.AddLayer(new Geometry2DLayer
{
boundaryLine = geometry2DBoundaryLine0
});
var geometry2DBoundaryLine1 = new Geometry2DBoundaryLine();
geometry2DBoundaryLine1.Points.Add(new Geometry2DPoint(1.0, 1.0));
geometry2DBoundaryLine1.Points.Add(new Geometry2DPoint(10.0, 2.1));
geometry2DData.AddLayer(new Geometry2DLayer
{
boundaryLine = geometry2DBoundaryLine1
});
Geometry2DLayer layerActual = geometry2DData.GetLayer(0);
Assert.That(geometry2DBoundaryLine0.Equals(layerActual.boundaryLine), Is.True);
Assert.That(layerActual.boundaryLine.Equals(new Geometry2DBoundaryLine()), Is.False);
layerActual = geometry2DData.GetLayer(1);
Assert.That(geometry2DBoundaryLine1.Equals(layerActual.boundaryLine), Is.True);
}
[Test]
public void IndexTooSmallRaisesException()
{
var geometry2DData = new Geometry2DData();
geometry2DData.AddLayer(new Geometry2DLayer());
geometry2DData.GetLayer(0);
Assert.That(() => geometry2DData.GetLayer(-1), Throws.InstanceOf());
}
[Test]
public void IndexTooLargeRaisesException()
{
var geometry2DData = new Geometry2DData();
geometry2DData.AddLayer(new Geometry2DLayer());
geometry2DData.GetLayer(0);
Assert.That(() => geometry2DData.GetLayer(1), Throws.InstanceOf());
}
[Test]
public void AlignedBoundaryLinesValidateSuccesful()
{
var geometry2DData = new Geometry2DData();
Geometry2DBoundaryLine geometry2DBoundaryLine0 = Add2AlignedBoundaryLines(geometry2DData);
geometry2DData.Validate(); // Should succeed
}
[Test]
public void LeftUnalignedBoundaryLinesRaiseExceptionOnValidate()
{
var geometry2DData = new Geometry2DData();
Geometry2DBoundaryLine geometry2DBoundaryLine0 = Add2AlignedBoundaryLines(geometry2DData);
geometry2DBoundaryLine0.Points[0].X += 1.0;
Assert.That(() => geometry2DData.Validate(), Throws.InstanceOf()); // Should fail
}
[Test]
public void RightUnalignedBoundaryLinesRaiseExceptionOnValidate()
{
var geometry2DData = new Geometry2DData();
Geometry2DBoundaryLine geometry2DBoundaryLine0 = Add2AlignedBoundaryLines(geometry2DData);
geometry2DBoundaryLine0.Points[geometry2DBoundaryLine0.Points.Count - 1].X += 1.0;
Assert.That(() => geometry2DData.Validate(), Throws.InstanceOf()); // Should fail
}
private Geometry2DBoundaryLine Add2AlignedBoundaryLines(Geometry2DData geometry2DData)
{
var geometry2DBoundaryLine0 = new Geometry2DBoundaryLine();
geometry2DBoundaryLine0.Points.Add(new Geometry2DPoint(0.0, 0.0));
geometry2DBoundaryLine0.Points.Add(new Geometry2DPoint(10.0, 1.1));
geometry2DData.AddLayer(new Geometry2DLayer
{
boundaryLine = geometry2DBoundaryLine0
});
var geometry2DBoundaryLine1 = new Geometry2DBoundaryLine();
geometry2DBoundaryLine1.Points.Add(new Geometry2DPoint(0.0, 1.0));
geometry2DBoundaryLine1.Points.Add(new Geometry2DPoint(10.0, 2.1));
geometry2DData.AddLayer(new Geometry2DLayer
{
boundaryLine = geometry2DBoundaryLine1
});
return geometry2DBoundaryLine0;
}
}
}