Index: Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/FaultTreeIllustrationPoint.cs =================================================================== diff -u -rd7f56db6a475e07dd904bd61c0a56346aac4e565 -r92f0a266f3ee297a3e0332e9a36fc3ec70d47b59 --- Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/FaultTreeIllustrationPoint.cs (.../FaultTreeIllustrationPoint.cs) (revision d7f56db6a475e07dd904bd61c0a56346aac4e565) +++ Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/FaultTreeIllustrationPoint.cs (.../FaultTreeIllustrationPoint.cs) (revision 92f0a266f3ee297a3e0332e9a36fc3ec70d47b59) @@ -22,8 +22,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Core.Common.Utils.Extensions; -using Ringtoets.Common.Data.Properties; namespace Ringtoets.Common.Data.IllustrationPoints { @@ -55,7 +53,7 @@ throw new ArgumentNullException(nameof(stochasts)); } - ValidateStochasts(stochasts); + StochastValidator.ValidateStochasts(stochasts); CombinationType = combinationType; Stochasts = stochasts; @@ -79,14 +77,5 @@ return clone; } - - private static void ValidateStochasts(IEnumerable stochasts) - { - bool hasDuplicates = stochasts.HasDuplicates(s => s.Name); - if (hasDuplicates) - { - throw new ArgumentException(string.Format(Resources.GeneralResult_Imported_non_unique_stochasts)); - } - } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/FaultTreeIllustrationPointExtensions.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/FaultTreeIllustrationPointExtensions.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/FaultTreeIllustrationPointExtensions.cs (revision 92f0a266f3ee297a3e0332e9a36fc3ec70d47b59) @@ -0,0 +1,49 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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 System.Collections.Generic; +using System.Linq; + +namespace Ringtoets.Common.Data.IllustrationPoints +{ + /// + /// Defines extension methods dealing with objects. + /// + public static class FaultTreeIllustrationPointExtensions + { + /// + /// Returns a list of all the stochast names present in the . + /// + /// The fault tree illustration point + /// to retrieve stochast names from. + /// Returns all stochast names as an enumerable result. + public static IEnumerable GetStochastNames(this FaultTreeIllustrationPoint faultTreeIllustrationPoint) + { + if (faultTreeIllustrationPoint == null) + { + throw new ArgumentNullException(nameof(faultTreeIllustrationPoint)); + } + + return faultTreeIllustrationPoint.Stochasts.Select(s => s.Name); + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/GeneralResult.cs =================================================================== diff -u -rd7f56db6a475e07dd904bd61c0a56346aac4e565 -r92f0a266f3ee297a3e0332e9a36fc3ec70d47b59 --- Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/GeneralResult.cs (.../GeneralResult.cs) (revision d7f56db6a475e07dd904bd61c0a56346aac4e565) +++ Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/GeneralResult.cs (.../GeneralResult.cs) (revision 92f0a266f3ee297a3e0332e9a36fc3ec70d47b59) @@ -68,7 +68,7 @@ throw new ArgumentNullException(nameof(topLevelIllustrationPoints)); } - ValidateStochasts(stochasts); + StochastValidator.ValidateStochasts(stochasts); ValidateTopLevelIllustrationPoints(topLevelIllustrationPoints); ValidateStochastInChildren(topLevelIllustrationPoints, stochasts); @@ -103,7 +103,7 @@ return clone; } - private void ValidateStochastInChildren(IEnumerable topLevelillustrationPoints, IEnumerable stochasts) + private static void ValidateStochastInChildren(IEnumerable topLevelillustrationPoints, IEnumerable stochasts) { var childStochastNames = new List(); @@ -112,16 +112,17 @@ var topLevelFaultTreeIllustrationPoint = topLevelIllustrationPoint as TopLevelFaultTreeIllustrationPoint; if (topLevelFaultTreeIllustrationPoint != null) { - childStochastNames.AddRange(GetStochastNamesFromChildren(topLevelFaultTreeIllustrationPoint.FaultTreeNodeRoot)); + childStochastNames.AddRange(topLevelFaultTreeIllustrationPoint.FaultTreeNodeRoot.GetStochastNamesFromChildren()); continue; } var topLevelSubMechanismIllustrationPoint = topLevelIllustrationPoint as TopLevelSubMechanismIllustrationPoint; if (topLevelSubMechanismIllustrationPoint != null) { - childStochastNames.AddRange(topLevelSubMechanismIllustrationPoint.SubMechanismIllustrationPoint.Stochasts.Select(s => s.Name)); + childStochastNames.AddRange(topLevelSubMechanismIllustrationPoint.SubMechanismIllustrationPoint.GetStochastNames()); } } + childStochastNames = childStochastNames.Distinct().ToList(); IEnumerable topLevelStochastNames = stochasts.Select(s => s.Name); @@ -131,27 +132,6 @@ } } - private IEnumerable GetStochastNamesFromChildren(IllustrationPointNode nodeRoot) - { - var stochastNames = new List(); - var faultTreeData = nodeRoot.Data as FaultTreeIllustrationPoint; - if (faultTreeData != null) - { - stochastNames.AddRange(faultTreeData.Stochasts.Select(s => s.Name)); - foreach (IllustrationPointNode illustrationPointNode in nodeRoot.Children) - { - stochastNames.AddRange(GetStochastNamesFromChildren(illustrationPointNode)); - } - return stochastNames; - } - var subMechanismData = nodeRoot.Data as SubMechanismIllustrationPoint; - if (subMechanismData != null) - { - stochastNames.AddRange(subMechanismData.Stochasts.Select(s => s.Name)); - } - return stochastNames; - } - private static void ValidateTopLevelIllustrationPoints(IEnumerable topLevelIllustrationPoints) { bool hasDuplicateIllustrationPointsPerWindDirection = @@ -161,14 +141,5 @@ throw new ArgumentException(string.Format(Resources.GeneralResult_Imported_non_unique_closing_situations_or_wind_direction)); } } - - private static void ValidateStochasts(IEnumerable stochasts) - { - bool hasDuplicateStochasts = stochasts.HasDuplicates(s => s.Name); - if (hasDuplicateStochasts) - { - throw new ArgumentException(string.Format(Resources.GeneralResult_Imported_non_unique_stochasts)); - } - } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/IllustrationPointNode.cs =================================================================== diff -u -rd7f56db6a475e07dd904bd61c0a56346aac4e565 -r92f0a266f3ee297a3e0332e9a36fc3ec70d47b59 --- Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/IllustrationPointNode.cs (.../IllustrationPointNode.cs) (revision d7f56db6a475e07dd904bd61c0a56346aac4e565) +++ Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/IllustrationPointNode.cs (.../IllustrationPointNode.cs) (revision 92f0a266f3ee297a3e0332e9a36fc3ec70d47b59) @@ -112,23 +112,10 @@ private static void ValidateChildStochasts(FaultTreeIllustrationPoint data, IEnumerable children) { - var stochastNames = new List(); - foreach (IllustrationPointNode illustrationPointNode in children) + List stochastNames = children.SelectMany(c => c.GetStochastNames()).ToList(); + + if (data.GetStochastNames().Intersect(stochastNames).Count() != stochastNames.Distinct().Count()) { - var faultTreeData = illustrationPointNode.Data as FaultTreeIllustrationPoint; - if (faultTreeData != null) - { - stochastNames.AddRange(faultTreeData.Stochasts.Select(s => s.Name)); - continue; - } - var subMechanismData = illustrationPointNode.Data as SubMechanismIllustrationPoint; - if (subMechanismData != null) - { - stochastNames.AddRange(subMechanismData.Stochasts.Select(s => s.Name)); - } - } - if (data.Stochasts.Select(s => s.Name).Intersect(stochastNames).Count() != stochastNames.Distinct().Count()) - { throw new ArgumentException(string.Format(Resources.GeneralResult_Imported_with_incorrect_stochasts_in_children)); } } Index: Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/IllustrationPointNodeExtensions.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/IllustrationPointNodeExtensions.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/IllustrationPointNodeExtensions.cs (revision 92f0a266f3ee297a3e0332e9a36fc3ec70d47b59) @@ -0,0 +1,79 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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 System.Collections.Generic; +using System.Linq; + +namespace Ringtoets.Common.Data.IllustrationPoints +{ + /// + /// Defines extension methods dealing with objects. + /// + public static class IllustrationPointNodeExtensions + { + /// + /// Returns a list of all the stochast names present in the . + /// + /// The illustration point node + /// to retrieve stochast names from. + /// Returns all stochast names as an enumerable result. + public static IEnumerable GetStochastNames(this IllustrationPointNode illustrationPointNode) + { + if (illustrationPointNode == null) + { + throw new ArgumentNullException(nameof(illustrationPointNode)); + } + + var faultTreeData = illustrationPointNode.Data as FaultTreeIllustrationPoint; + if (faultTreeData != null) + { + return faultTreeData.GetStochastNames(); + } + var subMechanismData = illustrationPointNode.Data as SubMechanismIllustrationPoint; + if (subMechanismData != null) + { + return subMechanismData.GetStochastNames(); + } + + return new List(); + } + + /// + /// Returns a list of all the stochast names present in the and its children. + /// + /// The illustration point node + /// to retrieve child stochast names from. + /// Returns all stochast names as an enumerable result. + public static IEnumerable GetStochastNamesFromChildren(this IllustrationPointNode illustrationPointNode) + { + if (illustrationPointNode == null) + { + throw new ArgumentNullException(nameof(illustrationPointNode)); + } + + List stochastNames = illustrationPointNode.Children.SelectMany(GetStochastNamesFromChildren).ToList(); + stochastNames.AddRange(illustrationPointNode.GetStochastNames()); + + return stochastNames; + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/StochastValidator.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/StochastValidator.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/StochastValidator.cs (revision 92f0a266f3ee297a3e0332e9a36fc3ec70d47b59) @@ -0,0 +1,52 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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 System.Collections.Generic; +using Core.Common.Utils.Extensions; +using Ringtoets.Common.Data.Properties; + +namespace Ringtoets.Common.Data.IllustrationPoints +{ + /// + /// This class contains validations methods for collections. + /// + public static class StochastValidator + { + /// + /// Validates a collection of objects by checking for duplicate names. + /// + /// The collection of objects to be validated. + public static void ValidateStochasts(IEnumerable stochasts) + { + if (stochasts == null) + { + throw new ArgumentNullException(nameof(stochasts)); + } + + bool hasDuplicates = stochasts.HasDuplicates(s => s.Name); + if (hasDuplicates) + { + throw new ArgumentException(string.Format(Resources.GeneralResult_Imported_non_unique_stochasts)); + } + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/SubMechanismIllustrationPoint.cs =================================================================== diff -u -rd7f56db6a475e07dd904bd61c0a56346aac4e565 -r92f0a266f3ee297a3e0332e9a36fc3ec70d47b59 --- Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/SubMechanismIllustrationPoint.cs (.../SubMechanismIllustrationPoint.cs) (revision d7f56db6a475e07dd904bd61c0a56346aac4e565) +++ Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/SubMechanismIllustrationPoint.cs (.../SubMechanismIllustrationPoint.cs) (revision 92f0a266f3ee297a3e0332e9a36fc3ec70d47b59) @@ -62,7 +62,7 @@ throw new ArgumentNullException(nameof(illustrationPointResults)); } - ValidateStochasts(stochasts); + StochastValidator.ValidateStochasts(stochasts); ValidateResults(illustrationPointResults); Stochasts = stochasts; @@ -89,6 +89,10 @@ return clone; } + /// + /// Validates a collection of objects by checking for duplicate descriptions. + /// + /// The collection of objects to be validated. private static void ValidateResults(IEnumerable illustrationPointResults) { bool hasDuplicateResults = illustrationPointResults.HasDuplicates(i => i.Description); @@ -97,14 +101,5 @@ throw new ArgumentException(string.Format(Resources.GeneralResult_Imported_non_unique_results)); } } - - private static void ValidateStochasts(IEnumerable stochasts) - { - bool hasDuplicateStochasts = stochasts.HasDuplicates(s => s.Name); - if (hasDuplicateStochasts) - { - throw new ArgumentException(string.Format(Resources.GeneralResult_Imported_non_unique_stochasts)); - } - } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/SubMechanismIllustrationPointExtensions.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/SubMechanismIllustrationPointExtensions.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/SubMechanismIllustrationPointExtensions.cs (revision 92f0a266f3ee297a3e0332e9a36fc3ec70d47b59) @@ -0,0 +1,49 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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 System.Collections.Generic; +using System.Linq; + +namespace Ringtoets.Common.Data.IllustrationPoints +{ + /// + /// Defines extension methods dealing with objects. + /// + public static class SubMechanismIllustrationPointExtensions + { + /// + /// Returns a list of all the stochast names present in the . + /// + /// The sub mechanism illustration point + /// to retrieve stochast names from. + /// Returns all stochast names as an enumerable result. + public static IEnumerable GetStochastNames(this SubMechanismIllustrationPoint subMechanismIllustrationPoint) + { + if (subMechanismIllustrationPoint == null) + { + throw new ArgumentNullException(nameof(subMechanismIllustrationPoint)); + } + + return subMechanismIllustrationPoint.Stochasts.Select(s => s.Name); + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj =================================================================== diff -u -r2303e33e596c2b329ade1c18ee24e6bfaa3d2dea -r92f0a266f3ee297a3e0332e9a36fc3ec70d47b59 --- Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj (.../Ringtoets.Common.Data.csproj) (revision 2303e33e596c2b329ade1c18ee24e6bfaa3d2dea) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj (.../Ringtoets.Common.Data.csproj) (revision 92f0a266f3ee297a3e0332e9a36fc3ec70d47b59) @@ -72,9 +72,13 @@ + + + + Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/IllustrationPoints/FaultTreeIllustrationPointExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/IllustrationPoints/FaultTreeIllustrationPointExtensionsTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/IllustrationPoints/FaultTreeIllustrationPointExtensionsTest.cs (revision 92f0a266f3ee297a3e0332e9a36fc3ec70d47b59) @@ -0,0 +1,77 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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 System.Collections.Generic; +using System.Linq; +using NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil.IllustrationPoints; + +namespace Ringtoets.Common.Data.Test.IllustrationPoints +{ + public class FaultTreeIllustrationPointExtensionsTest + { + [Test] + public void GetStochastNames_FaultTreeIllustrationPointNull_ThrowsArgumentNullException() + { + // Setup + FaultTreeIllustrationPoint faultTreeIllustrationPoint = null; + + // Call + TestDelegate test = () => faultTreeIllustrationPoint.GetStochastNames(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("faultTreeIllustrationPoint", exception.ParamName); + } + + [Test] + public void GetStochastNames_FaultTreeIllustrationPointWithoutStochast_ReturnsEmptyList() + { + // Setup + var faultTreeIllustrationPoint = new TestFaultTreeIllustrationPoint(); + + // Call + IEnumerable names = faultTreeIllustrationPoint.GetStochastNames(); + + // Assert + CollectionAssert.IsEmpty(names); + } + + [Test] + public void GetStochastNames_FaultTreeIllustrationPointWithStochast_ReturnsExpectedName() + { + // Setup + const string stochastName = "Stochast A"; + var faultTreeIllustrationPoint = new TestFaultTreeIllustrationPoint(new[] + { + new Stochast(stochastName, 2, 5) + }); + + // Call + IEnumerable names = faultTreeIllustrationPoint.GetStochastNames(); + + // Assert + Assert.AreEqual(stochastName, names.Single()); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/IllustrationPoints/IllustrationPointNodeExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/IllustrationPoints/IllustrationPointNodeExtensionsTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/IllustrationPoints/IllustrationPointNodeExtensionsTest.cs (revision 92f0a266f3ee297a3e0332e9a36fc3ec70d47b59) @@ -0,0 +1,180 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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 System.Collections.Generic; +using System.Linq; +using NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil.IllustrationPoints; + +namespace Ringtoets.Common.Data.Test.IllustrationPoints +{ + public class IllustrationPointNodeExtensionsTest + { + [Test] + public void GetStochastNames_IllustrationPointNodeNull_ThrowsArgumentNullException() + { + // Setup + IllustrationPointNode illustrationPointNode = null; + + // Call + TestDelegate test = () => illustrationPointNode.GetStochastNames(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("illustrationPointNode", exception.ParamName); + } + + [Test] + public void GetStochastNames_IllustrationPointNodeWithSubMechanismIllustrationPointWithoutStochast_ReturnsEmptyList() + { + // Setup + var illustrationPointNode = new IllustrationPointNode(new TestSubMechanismIllustrationPoint()); + + // Call + IEnumerable names = illustrationPointNode.GetStochastNames(); + + // Assert + CollectionAssert.IsEmpty(names); + } + + [Test] + public void GetStochastNames_IllustrationPointNodeWithFaultTreeIllustrationPointWithoutStochast_ReturnsEmptyList() + { + // Setup + var illustrationPointNode = new IllustrationPointNode(new TestFaultTreeIllustrationPoint()); + + // Call + IEnumerable names = illustrationPointNode.GetStochastNames(); + + // Assert + CollectionAssert.IsEmpty(names); + } + + [Test] + public void GetStochastNames_IllustrationPointNodeWithSubMechanismIllustrationPointWithStochast_ReturnsExpectedName() + { + // Setup + const string stochastName = "Stochast A"; + var illustrationPointNode = new IllustrationPointNode(new TestSubMechanismIllustrationPoint(new[] + { + new SubMechanismIllustrationPointStochast(stochastName, 2, 5, 3) + })); + + // Call + IEnumerable names = illustrationPointNode.GetStochastNames(); + + // Assert + Assert.AreEqual(stochastName, names.Single()); + } + + [Test] + public void GetStochastNames_IllustrationPointNodeWithFaultTreeIllustrationPointWithStochast_ReturnsExpectedName() + { + // Setup + const string stochastName = "Stochast A"; + var illustrationPointNode = new IllustrationPointNode(new TestFaultTreeIllustrationPoint(new[] + { + new Stochast(stochastName, 2, 4) + })); + + // Call + IEnumerable names = illustrationPointNode.GetStochastNames(); + + // Assert + Assert.AreEqual(stochastName, names.Single()); + } + + [Test] + public void GetStochastNamesFromChildren_IllustrationPointNodeNull_ThrowsArgumentNullException() + { + // Setup + IllustrationPointNode illustrationPointNode = null; + + // Call + TestDelegate test = () => illustrationPointNode.GetStochastNamesFromChildren(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("illustrationPointNode", exception.ParamName); + } + + [Test] + public void GetStochastNamesFromChildren_IllustrationPointNodeWithFaultTreeIllustrationPointAndChildrenContainingStochasts_ReturnsExpectedNames() + { + // Setup + const string stochastNameA = "Stochast A"; + const string stochastNameB = "Stochast B"; + var illustrationPointNode = new IllustrationPointNode(new TestFaultTreeIllustrationPoint(new[] + { + new Stochast(stochastNameA, 2, 4), + new Stochast(stochastNameB, 1, 5) + })); + illustrationPointNode.SetChildren(new[] + { + new IllustrationPointNode(new FaultTreeIllustrationPoint("Point A", 0.0, new[] + { + new Stochast(stochastNameA, 2, 3) + }, CombinationType.And)), + new IllustrationPointNode(new FaultTreeIllustrationPoint("Point B", 0.0, new[] + { + new Stochast(stochastNameB, 2, 3) + }, CombinationType.And)) + }); + + // Call + IEnumerable names = illustrationPointNode.GetStochastNamesFromChildren(); + + // Assert + CollectionAssert.AreEqual(new[] + { + stochastNameA, + stochastNameB, + stochastNameA, + stochastNameB + }, names); + } + + [Test] + public void GetStochastNamesFromChildren_IllustrationPointNodeWithSubMechanismIllustrationPointAndNoChildren_ReturnsExpectedNames() + { + // Setup + const string stochastNameA = "Stochast A"; + const string stochastNameB = "Stochast B"; + var illustrationPointNode = new IllustrationPointNode(new TestSubMechanismIllustrationPoint(new[] + { + new SubMechanismIllustrationPointStochast(stochastNameA, 2, 4, 2), + new SubMechanismIllustrationPointStochast(stochastNameB, 1, 5, 4) + })); + + // Call + IEnumerable names = illustrationPointNode.GetStochastNamesFromChildren(); + + // Assert + CollectionAssert.AreEqual(new[] + { + stochastNameA, + stochastNameB + }, names); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/IllustrationPoints/StochastValidatorTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/IllustrationPoints/StochastValidatorTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/IllustrationPoints/StochastValidatorTest.cs (revision 92f0a266f3ee297a3e0332e9a36fc3ec70d47b59) @@ -0,0 +1,108 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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 System.Collections.Generic; +using System.Linq; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; + +namespace Ringtoets.Common.Data.Test.IllustrationPoints +{ + [TestFixture] + public class StochastValidatorTest + { + [Test] + public void ValidateStochasts_StochastsNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => StochastValidator.ValidateStochasts(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("stochasts", exception.ParamName); + } + + [Test] + public void ValidateStochasts_StochastsEmpty_DoesNotThrow() + { + // Call + TestDelegate test = () => StochastValidator.ValidateStochasts(Enumerable.Empty()); + + // Assert + Assert.DoesNotThrow(test); + } + + [Test] + public void ValidateStochasts_SingleStochast_DoesNotThrow() + { + // Setup + var stochasts = new List + { + new Stochast("Stochast A", 1, 2) + }; + + // Call + TestDelegate test = () => StochastValidator.ValidateStochasts(stochasts); + + // Assert + Assert.DoesNotThrow(test); + } + + [Test] + public void ValidateStochasts_UniqueStochasts_DoesNotThrow() + { + // Setup + var stochasts = new List + { + new Stochast("Stochast A", 1, 2), + new Stochast("Stochast B", 2, 3), + new Stochast("Stochast C", 1, 3) + }; + + // Call + TestDelegate test = () => StochastValidator.ValidateStochasts(stochasts); + + // Assert + Assert.DoesNotThrow(test); + } + + [Test] + public void ValidateStochasts_DuplicateStochasts_ThrowsArgumentException() + { + // Setup + var stochasts = new List + { + new Stochast("Stochast A", 1, 2), + new Stochast("Stochast B", 2, 3), + new Stochast("Stochast B", 1, 3) + }; + + // Call + TestDelegate test = () => StochastValidator.ValidateStochasts(stochasts); + + // Assert + const string expectedMessage = "Een of meerdere stochasten hebben dezelfde naam."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/IllustrationPoints/SubMechanismIllustrationPointExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/IllustrationPoints/SubMechanismIllustrationPointExtensionsTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/IllustrationPoints/SubMechanismIllustrationPointExtensionsTest.cs (revision 92f0a266f3ee297a3e0332e9a36fc3ec70d47b59) @@ -0,0 +1,77 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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 System.Collections.Generic; +using System.Linq; +using NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil.IllustrationPoints; + +namespace Ringtoets.Common.Data.Test.IllustrationPoints +{ + public class SubMechanismIllustrationPointExtensionsTest + { + [Test] + public void GetStochastNames_SubMechanismIllustrationPointNull_ThrowsArgumentNullException() + { + // Setup + SubMechanismIllustrationPoint subMechanismIllustrationPoint = null; + + // Call + TestDelegate test = () => subMechanismIllustrationPoint.GetStochastNames(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("subMechanismIllustrationPoint", exception.ParamName); + } + + [Test] + public void GetStochastNames_SubMechanismIllustrationPointWithoutStochast_ReturnsEmptyList() + { + // Setup + var subMechanismIllustrationPoint = new TestSubMechanismIllustrationPoint(); + + // Call + IEnumerable names = subMechanismIllustrationPoint.GetStochastNames(); + + // Assert + CollectionAssert.IsEmpty(names); + } + + [Test] + public void GetStochastNames_SubMechanismIllustrationPointWithStochast_ReturnsExpectedName() + { + // Setup + const string stochastName = "Stochast A"; + var subMechanismIllustrationPoint = new TestSubMechanismIllustrationPoint(new[] + { + new SubMechanismIllustrationPointStochast(stochastName, 2, 5, 3) + }); + + // Call + IEnumerable names = subMechanismIllustrationPoint.GetStochastNames(); + + // Assert + Assert.AreEqual(stochastName, names.Single()); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj =================================================================== diff -u -r2303e33e596c2b329ade1c18ee24e6bfaa3d2dea -r92f0a266f3ee297a3e0332e9a36fc3ec70d47b59 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj (.../Ringtoets.Common.Data.Test.csproj) (revision 2303e33e596c2b329ade1c18ee24e6bfaa3d2dea) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj (.../Ringtoets.Common.Data.Test.csproj) (revision 92f0a266f3ee297a3e0332e9a36fc3ec70d47b59) @@ -82,11 +82,15 @@ + + + + Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil.Test/IllustrationPoints/GeneralResultTestFactoryTest.cs =================================================================== diff -u -r2e944cbf52d124fd501ed4ed8e991aa50299cc69 -r92f0a266f3ee297a3e0332e9a36fc3ec70d47b59 --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil.Test/IllustrationPoints/GeneralResultTestFactoryTest.cs (.../GeneralResultTestFactoryTest.cs) (revision 2e944cbf52d124fd501ed4ed8e991aa50299cc69) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil.Test/IllustrationPoints/GeneralResultTestFactoryTest.cs (.../GeneralResultTestFactoryTest.cs) (revision 92f0a266f3ee297a3e0332e9a36fc3ec70d47b59) @@ -19,7 +19,6 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System.Collections.Generic; using System.Linq; using NUnit.Framework; using Ringtoets.HydraRing.Calculation.Data.Output.IllustrationPoints; @@ -50,246 +49,6 @@ CollectionAssert.IsEmpty(generalResult.IllustrationPoints); } - [Test] - public void CreateGeneralResultFaultTreeWithIncorrectTopLevelStochasts_ExpectedProperties() - { - // Call - GeneralResult generalResult = GeneralResultTestFactory.CreateGeneralResultFaultTreeWithIncorrectTopLevelStochasts(); - - // Assert - Assert.IsInstanceOf(generalResult); - Assert.AreEqual(0.5, generalResult.Beta); - - var expectedWindDirection = new TestWindDirection(); - AssertWindDirection(expectedWindDirection, generalResult.GoverningWindDirection); - Assert.AreEqual(2, generalResult.Stochasts.Count()); - Stochast[] stochasts = generalResult.Stochasts.ToArray(); - Assert.AreEqual("Stochast A", stochasts[0].Name); - Assert.AreEqual("Stochast B", stochasts[1].Name); - - KeyValuePair topLevelIllustrationPoint = - generalResult.IllustrationPoints.Single(); - - WindDirectionClosingSituation actualWindDirectionClosingSituation = topLevelIllustrationPoint.Key; - AssertWindDirection(expectedWindDirection, actualWindDirectionClosingSituation.WindDirection); - Assert.AreEqual("closing A", actualWindDirectionClosingSituation.ClosingSituation); - - Assert.IsInstanceOf(topLevelIllustrationPoint.Value.Data); - Assert.AreEqual("Point A", ((FaultTreeIllustrationPoint) topLevelIllustrationPoint.Value.Data).Name); - - Stochast topLevelIllustrationPointStochast = ((FaultTreeIllustrationPoint) topLevelIllustrationPoint.Value.Data).Stochasts.Single(); - Assert.AreEqual("Stochast C", topLevelIllustrationPointStochast.Name); - } - - [Test] - public void CreateGeneralResultSubMechanismWithIncorrectTopLevelStochasts_ExpectedProperties() - { - // Call - GeneralResult generalResult = GeneralResultTestFactory.CreateGeneralResultSubMechanismWithIncorrectTopLevelStochasts(); - - // Assert - Assert.IsInstanceOf(generalResult); - Assert.AreEqual(0.5, generalResult.Beta); - - var expectedWindDirection = new TestWindDirection(); - AssertWindDirection(expectedWindDirection, generalResult.GoverningWindDirection); - Assert.AreEqual(2, generalResult.Stochasts.Count()); - Stochast[] stochasts = generalResult.Stochasts.ToArray(); - Assert.AreEqual("Stochast A", stochasts[0].Name); - Assert.AreEqual("Stochast B", stochasts[1].Name); - - KeyValuePair topLevelIllustrationPoint = - generalResult.IllustrationPoints.Single(); - - WindDirectionClosingSituation actualWindDirectionClosingSituation = topLevelIllustrationPoint.Key; - AssertWindDirection(expectedWindDirection, actualWindDirectionClosingSituation.WindDirection); - Assert.AreEqual("closing A", actualWindDirectionClosingSituation.ClosingSituation); - - Assert.IsInstanceOf(topLevelIllustrationPoint.Value.Data); - Assert.AreEqual("Point A", ((SubMechanismIllustrationPoint) topLevelIllustrationPoint.Value.Data).Name); - - Stochast topLevelIllustrationPointStochast = ((SubMechanismIllustrationPoint) topLevelIllustrationPoint.Value.Data).Stochasts.Single(); - Assert.AreEqual("Stochast C", topLevelIllustrationPointStochast.Name); - } - - [Test] - public void CreateGeneralResultWithIncorrectStochastsInChildren_ExpectedProperties() - { - // Call - GeneralResult generalResult = GeneralResultTestFactory.CreateGeneralResultWithIncorrectStochastsInChildren(); - - // Assert - Assert.IsInstanceOf(generalResult); - Assert.AreEqual(0.5, generalResult.Beta); - - var expectedWindDirection = new TestWindDirection(); - AssertWindDirection(expectedWindDirection, generalResult.GoverningWindDirection); - Assert.AreEqual(2, generalResult.Stochasts.Count()); - Stochast[] stochasts = generalResult.Stochasts.ToArray(); - Assert.AreEqual("Stochast A", stochasts[0].Name); - Assert.AreEqual("Stochast D", stochasts[1].Name); - - KeyValuePair topLevelIllustrationPoint = - generalResult.IllustrationPoints.Single(); - - WindDirectionClosingSituation actualWindDirectionClosingSituation = topLevelIllustrationPoint.Key; - AssertWindDirection(expectedWindDirection, actualWindDirectionClosingSituation.WindDirection); - Assert.AreEqual("closing A", actualWindDirectionClosingSituation.ClosingSituation); - - Assert.IsInstanceOf(topLevelIllustrationPoint.Value.Data); - Assert.AreEqual("Point A", ((FaultTreeIllustrationPoint) topLevelIllustrationPoint.Value.Data).Name); - - Stochast topLevelIllustrationPointStochast = ((FaultTreeIllustrationPoint) topLevelIllustrationPoint.Value.Data).Stochasts.Single(); - Assert.AreEqual("Stochast A", topLevelIllustrationPointStochast.Name); - - IllustrationPointTreeNode[] children = topLevelIllustrationPoint.Value.Children.ToArray(); - Assert.IsInstanceOf(children[0].Data); - SubMechanismIllustrationPointStochast childStochast = ((SubMechanismIllustrationPoint) children[0].Data).Stochasts.Single(); - Assert.AreEqual("Stochast D", childStochast.Name); - Assert.IsInstanceOf(children[1].Data); - } - - [Test] - public void CreateGeneralResultFaultTreeWithDuplicateIllustrationPoints_ExpectedProperties() - { - // Call - GeneralResult generalResult = GeneralResultTestFactory.CreateGeneralResultFaultTreeWithDuplicateIllustrationPoints(); - - // Assert - Assert.IsInstanceOf(generalResult); - Assert.AreEqual(0.5, generalResult.Beta); - - AssertWindDirection(new TestWindDirection(), generalResult.GoverningWindDirection); - - KeyValuePair[] topLevelIllustrationPoints = - generalResult.IllustrationPoints.ToArray(); - Assert.AreEqual(2, topLevelIllustrationPoints.Length); - - AssertWindDirection(new WindDirection("N", 0.0), topLevelIllustrationPoints[0].Key.WindDirection); - Assert.AreEqual("closing A", topLevelIllustrationPoints[0].Key.ClosingSituation); - - AssertWindDirection(new WindDirection("S", 0.0), topLevelIllustrationPoints[1].Key.WindDirection); - Assert.AreEqual("closing A", topLevelIllustrationPoints[1].Key.ClosingSituation); - - Assert.IsInstanceOf(topLevelIllustrationPoints[0].Value.Data); - Assert.IsInstanceOf(topLevelIllustrationPoints[1].Value.Data); - } - - [Test] - public void CreateGeneralResultSubMechanismWithDuplicateIllustrationPoints_ExpectedProperties() - { - // Call - GeneralResult generalResult = GeneralResultTestFactory.CreateGeneralResultSubMechanismWithDuplicateIllustrationPoints(); - - // Assert - Assert.IsInstanceOf(generalResult); - Assert.AreEqual(0.5, generalResult.Beta); - - AssertWindDirection(new TestWindDirection(), generalResult.GoverningWindDirection); - - KeyValuePair[] topLevelIllustrationPoints = - generalResult.IllustrationPoints.ToArray(); - Assert.AreEqual(2, topLevelIllustrationPoints.Length); - - AssertWindDirection(new WindDirection("N", 0.0), topLevelIllustrationPoints[0].Key.WindDirection); - Assert.AreEqual("closing A", topLevelIllustrationPoints[0].Key.ClosingSituation); - - AssertWindDirection(new WindDirection("S", 0.0), topLevelIllustrationPoints[1].Key.WindDirection); - Assert.AreEqual("closing A", topLevelIllustrationPoints[1].Key.ClosingSituation); - - Assert.IsInstanceOf(topLevelIllustrationPoints[0].Value.Data); - Assert.IsInstanceOf(topLevelIllustrationPoints[1].Value.Data); - } - - [Test] - public void CreateGeneralResultFaultTreeWithDuplicateIllustrationPointResults_ExpectedProperties() - { - // Call - GeneralResult generalResult = GeneralResultTestFactory.CreateGeneralResultFaultTreeWithDuplicateIllustrationPointResults(); - - // Assert - Assert.IsInstanceOf(generalResult); - Assert.AreEqual(0.5, generalResult.Beta); - - var expectedWindDirection = new TestWindDirection(); - AssertWindDirection(expectedWindDirection, generalResult.GoverningWindDirection); - - KeyValuePair topLevelIllustrationPoint = - generalResult.IllustrationPoints.Single(); - - WindDirectionClosingSituation actualWindDirectionClosingSituation = topLevelIllustrationPoint.Key; - AssertWindDirection(expectedWindDirection, actualWindDirectionClosingSituation.WindDirection); - Assert.AreEqual("closing A", actualWindDirectionClosingSituation.ClosingSituation); - - Assert.IsInstanceOf(topLevelIllustrationPoint.Value.Data); - Assert.AreEqual("Point A", ((FaultTreeIllustrationPoint) topLevelIllustrationPoint.Value.Data).Name); - - IllustrationPointTreeNode[] children = topLevelIllustrationPoint.Value.Children.ToArray(); - Assert.IsInstanceOf(children[0].Data); - IllustrationPointResult[] illustrationPointResults = ((SubMechanismIllustrationPoint) children[0].Data).Results.ToArray(); - Assert.AreEqual("Result A", illustrationPointResults[0].Description); - Assert.AreEqual(0.0, illustrationPointResults[0].Value); - Assert.AreEqual("Result A", illustrationPointResults[1].Description); - Assert.AreEqual(1.0, illustrationPointResults[1].Value); - Assert.IsInstanceOf(children[1].Data); - } - - [Test] - public void CreateGeneralResultSubMechanismWithDuplicateIllustrationPointResults_ExpectedProperties() - { - // Call - GeneralResult generalResult = GeneralResultTestFactory.CreateGeneralResultSubMechanismWithDuplicateIllustrationPointResults(); - - // Assert - Assert.IsInstanceOf(generalResult); - Assert.AreEqual(0.5, generalResult.Beta); - - var expectedWindDirection = new TestWindDirection(); - AssertWindDirection(expectedWindDirection, generalResult.GoverningWindDirection); - - KeyValuePair topLevelIllustrationPoint = - generalResult.IllustrationPoints.Single(); - - WindDirectionClosingSituation actualWindDirectionClosingSituation = topLevelIllustrationPoint.Key; - AssertWindDirection(expectedWindDirection, actualWindDirectionClosingSituation.WindDirection); - Assert.AreEqual("closing A", actualWindDirectionClosingSituation.ClosingSituation); - - Assert.IsInstanceOf(topLevelIllustrationPoint.Value.Data); - var subMechanismIllustrationPoint = (SubMechanismIllustrationPoint) topLevelIllustrationPoint.Value.Data; - Assert.AreEqual("Point SA", subMechanismIllustrationPoint.Name); - - IllustrationPointResult[] illustrationPointResults = subMechanismIllustrationPoint.Results.ToArray(); - Assert.AreEqual("Result A", illustrationPointResults[0].Description); - Assert.AreEqual(0.0, illustrationPointResults[0].Value); - Assert.AreEqual("Result A", illustrationPointResults[1].Description); - Assert.AreEqual(1.0, illustrationPointResults[1].Value); - } - - [Test] - public void CreateGeneralResultWithDuplicateNamesInChildren_ExpectedProperties() - { - // Call - GeneralResult generalResult = GeneralResultTestFactory.CreateGeneralResultWithDuplicateNamesInChildren(); - - // Assert - Assert.IsInstanceOf(generalResult); - Assert.AreEqual(0.5, generalResult.Beta); - - var expectedWindDirection = new TestWindDirection(); - AssertWindDirection(expectedWindDirection, generalResult.GoverningWindDirection); - - KeyValuePair topLevelIllustrationPoint = - generalResult.IllustrationPoints.Single(); - Assert.IsInstanceOf(topLevelIllustrationPoint.Value.Data); - - IllustrationPointTreeNode[] children = topLevelIllustrationPoint.Value.Children.ToArray(); - Assert.AreEqual("Point B", ((SubMechanismIllustrationPoint) children[0].Data).Name); - Assert.AreEqual("Point B", ((SubMechanismIllustrationPoint) children[1].Data).Name); - - Assert.IsInstanceOf(children[0].Data); - Assert.IsInstanceOf(children[1].Data); - } - private static void AssertWindDirection(WindDirection expected, WindDirection actual) { Assert.AreEqual(expected.Name, actual.Name); Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil/IllustrationPoints/GeneralResultTestFactory.cs =================================================================== diff -u -rd7f56db6a475e07dd904bd61c0a56346aac4e565 -r92f0a266f3ee297a3e0332e9a36fc3ec70d47b59 --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil/IllustrationPoints/GeneralResultTestFactory.cs (.../GeneralResultTestFactory.cs) (revision d7f56db6a475e07dd904bd61c0a56346aac4e565) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil/IllustrationPoints/GeneralResultTestFactory.cs (.../GeneralResultTestFactory.cs) (revision 92f0a266f3ee297a3e0332e9a36fc3ec70d47b59) @@ -20,7 +20,6 @@ // All rights reserved. using System.Collections.Generic; -using System.Linq; using Ringtoets.HydraRing.Calculation.Data.Output.IllustrationPoints; namespace Ringtoets.HydraRing.Calculation.TestUtil.IllustrationPoints @@ -43,229 +42,5 @@ var illustrationPoints = new Dictionary(); return new GeneralResult(0.5, new TestWindDirection(), stochasts, illustrationPoints); } - - /// - /// Creates a new instance of containing a fault tree - /// with an incomplete list of top level stochasts. - /// - /// A with an incomplete list of top level stochasts. - public static GeneralResult CreateGeneralResultFaultTreeWithIncorrectTopLevelStochasts() - { - var stochasts = new[] - { - new Stochast("Stochast A", 0, 0), - new Stochast("Stochast B", 0, 0) - }; - - var faultTreeNode = new IllustrationPointTreeNode(new FaultTreeIllustrationPoint("Point A", 0.0, new[] - { - new Stochast("Stochast C", 0, 0) - }, CombinationType.And)); - - var illustrationPoints = new Dictionary - { - { - new WindDirectionClosingSituation(new TestWindDirection(), "closing A"), - faultTreeNode - } - }; - return new GeneralResult(0.5, new TestWindDirection(), stochasts, illustrationPoints); - } - - /// - /// Creates a new instance of containing a sub mechanism - /// with an incomplete list of top level stochasts. - /// - /// A with an incomplete list of top level stochasts. - public static GeneralResult CreateGeneralResultSubMechanismWithIncorrectTopLevelStochasts() - { - var stochasts = new[] - { - new Stochast("Stochast A", 0, 0), - new Stochast("Stochast B", 0, 0) - }; - - var faultTreeNode = new IllustrationPointTreeNode(new SubMechanismIllustrationPoint("Point A", new[] - { - new SubMechanismIllustrationPointStochast("Stochast C", 0, 0, 0) - }, Enumerable.Empty(), 0.0)); - - var illustrationPoints = new Dictionary - { - { - new WindDirectionClosingSituation(new TestWindDirection(), "closing A"), - faultTreeNode - } - }; - return new GeneralResult(0.5, new TestWindDirection(), stochasts, illustrationPoints); - } - - /// - /// Creates a new instance of - /// with an incomplete list of stochasts in a fault tree illustration point in the tree. - /// - /// A with an incomplete list of stochasts - /// in a fault tree illustration point in the tree. - public static GeneralResult CreateGeneralResultWithIncorrectStochastsInChildren() - { - var stochastA = new Stochast("Stochast A", 0, 0); - var stochasts = new[] - { - stochastA, - new Stochast("Stochast D", 0, 0) - }; - - var illustrationPointNode = new IllustrationPointTreeNode(new FaultTreeIllustrationPoint("Point A", 0.0, new[] - { - stochastA - }, CombinationType.And)); - - illustrationPointNode.SetChildren(new[] - { - new IllustrationPointTreeNode(new SubMechanismIllustrationPoint("Point SA", new[] - { - new SubMechanismIllustrationPointStochast("Stochast D", 0, 0, 0) - }, Enumerable.Empty(), 0.0)), - new IllustrationPointTreeNode(new TestFaultTreeIllustrationPoint()) - }); - - var illustrationPoints = new Dictionary - { - { - new WindDirectionClosingSituation(new TestWindDirection(), "closing A"), - illustrationPointNode - } - }; - return new GeneralResult(0.5, new TestWindDirection(), stochasts, illustrationPoints); - } - - /// - /// Creates a new instance of containing a fault tree - /// with duplicate illustration points. - /// - /// A with duplicate illustration points. - public static GeneralResult CreateGeneralResultFaultTreeWithDuplicateIllustrationPoints() - { - var illustrationPoints = new Dictionary - { - { - new WindDirectionClosingSituation(new WindDirection("N", 0.0), "closing A"), - new IllustrationPointTreeNode(new TestFaultTreeIllustrationPoint()) - }, - { - new WindDirectionClosingSituation(new WindDirection("S", 0.0), "closing A"), - new IllustrationPointTreeNode(new TestFaultTreeIllustrationPoint()) - } - }; - return new GeneralResult(0.5, new TestWindDirection(), Enumerable.Empty(), illustrationPoints); - } - - /// - /// Creates a new instance of containing a sub mechanism - /// with duplicate illustration points. - /// - /// A with duplicate illustration points. - public static GeneralResult CreateGeneralResultSubMechanismWithDuplicateIllustrationPoints() - { - var testSubMechanismIllustrationPoint = new IllustrationPointTreeNode(new TestSubMechanismIllustrationPoint()); - var illustrationPoints = new Dictionary - { - { - new WindDirectionClosingSituation(new WindDirection("N", 0.0), "closing A"), - testSubMechanismIllustrationPoint - }, - { - new WindDirectionClosingSituation(new WindDirection("S", 0.0), "closing A"), - testSubMechanismIllustrationPoint - } - }; - return new GeneralResult(0.5, new TestWindDirection(), Enumerable.Empty(), illustrationPoints); - } - - /// - /// Creates a new instance of containing a fault tree - /// with duplicate illustration point results. - /// - /// A with duplicate illustration point results. - public static GeneralResult CreateGeneralResultFaultTreeWithDuplicateIllustrationPointResults() - { - var illustrationPointNode = new IllustrationPointTreeNode(new FaultTreeIllustrationPoint("Point A", - 0.5, - Enumerable.Empty(), - CombinationType.And)); - - illustrationPointNode.SetChildren(new[] - { - new IllustrationPointTreeNode(new SubMechanismIllustrationPoint("Point SA", - Enumerable.Empty(), - new[] - { - new IllustrationPointResult("Result A", 0.0), - new IllustrationPointResult("Result A", 1.0) - }, 0.0)), - new IllustrationPointTreeNode(new TestFaultTreeIllustrationPoint()) - }); - - var illustrationPoints = new Dictionary - { - { - new WindDirectionClosingSituation(new TestWindDirection(), "closing A"), - illustrationPointNode - } - }; - return new GeneralResult(0.5, new TestWindDirection(), Enumerable.Empty(), illustrationPoints); - } - - /// - /// Creates a new instance of containing a fault tree - /// with duplicate illustration point results. - /// - /// A with duplicate illustration point results. - public static GeneralResult CreateGeneralResultSubMechanismWithDuplicateIllustrationPointResults() - { - var illustrationPointNode = new IllustrationPointTreeNode(new SubMechanismIllustrationPoint("Point SA", - Enumerable.Empty(), - new[] - { - new IllustrationPointResult("Result A", 0.0), - new IllustrationPointResult("Result A", 1.0) - }, 0.0)); - - var illustrationPoints = new Dictionary - { - { - new WindDirectionClosingSituation(new TestWindDirection(), "closing A"), - illustrationPointNode - } - }; - return new GeneralResult(0.5, new TestWindDirection(), Enumerable.Empty(), illustrationPoints); - } - - /// - /// Creates a new instance of - /// with duplicate illustration point names. - /// - /// A with duplicate illustration point names. - public static GeneralResult CreateGeneralResultWithDuplicateNamesInChildren() - { - var illustrationPointNode = new IllustrationPointTreeNode(new FaultTreeIllustrationPoint("Point A", - 0.5, - Enumerable.Empty(), - CombinationType.And)); - var testSubMechanismIllustrationPoint = new IllustrationPointTreeNode(new TestSubMechanismIllustrationPoint("Point B")); - illustrationPointNode.SetChildren(new[] - { - testSubMechanismIllustrationPoint, - testSubMechanismIllustrationPoint - }); - var illustrationPoints = new Dictionary - { - { - new WindDirectionClosingSituation(new TestWindDirection(), "closing A"), - illustrationPointNode - } - }; - return new GeneralResult(0.5, new TestWindDirection(), Enumerable.Empty(), illustrationPoints); - } } } \ No newline at end of file