// Copyright (C) Stichting Deltares 2018. 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. namespace Deltares.Dam.Tests { using System; using Deltares.Dam.Data; using NUnit.Framework; [TestFixture] public class Geometry2DDataTests { [Test] public void AddBoundaryLineIncreasesCount() { var geometry2DData = new Geometry2DData(); Assert.AreEqual(0, geometry2DData.LayerCount, "New Geometry2DData object should have no boundary lines"); geometry2DData.AddLayer(new Geometry2DLayer()); Assert.AreEqual(1, geometry2DData.LayerCount, "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.IsTrue(geometry2DBoundaryLine0.Equals(layerActual.boundaryLine)); Assert.IsFalse(layerActual.boundaryLine.Equals(new Geometry2DBoundaryLine())); layerActual = geometry2DData.GetLayer(1); Assert.IsTrue(geometry2DBoundaryLine1.Equals(layerActual.boundaryLine)); } [Test] [ExpectedException(typeof(ArgumentOutOfRangeException))] public void IndexTooSmallRaisesException() { var geometry2DData = new Geometry2DData(); geometry2DData.AddLayer(new Geometry2DLayer()); Geometry2DLayer geometry2DLayerActual = geometry2DData.GetLayer(0); geometry2DLayerActual = geometry2DData.GetLayer(-1); } [Test] [ExpectedException(typeof(ArgumentOutOfRangeException))] public void IndexTooLargeRaisesException() { var geometry2DData = new Geometry2DData(); geometry2DData.AddLayer(new Geometry2DLayer()); Geometry2DLayer geometry2DLayerActual = geometry2DData.GetLayer(0); geometry2DLayerActual = geometry2DData.GetLayer(1); } [Test] public void AlignedBoundaryLinesValidateSuccesful() { var geometry2DData = new Geometry2DData(); Geometry2DBoundaryLine geometry2DBoundaryLine0 = Add2AlignedBoundaryLines(geometry2DData); geometry2DData.Validate(); // Should succeed } [Test] [ExpectedException(typeof(Geometry2DDataException))] public void LeftUnalignedBoundaryLinesRaiseExceptionOnValidate() { var geometry2DData = new Geometry2DData(); Geometry2DBoundaryLine geometry2DBoundaryLine0 = Add2AlignedBoundaryLines(geometry2DData); geometry2DBoundaryLine0.Points[0].X += 1.0; geometry2DData.Validate(); // Should fail } [Test] [ExpectedException(typeof(Geometry2DDataException))] public void RightUnalignedBoundaryLinesRaiseExceptionOnValidate() { var geometry2DData = new Geometry2DData(); Geometry2DBoundaryLine geometry2DBoundaryLine0 = Add2AlignedBoundaryLines(geometry2DData); geometry2DBoundaryLine0.Points[geometry2DBoundaryLine0.Points.Count - 1].X += 1.0; geometry2DData.Validate(); // 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; } } }