// 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.ComponentModel;
using System.Linq;
using Core.Common.TestUtil;
using Core.Common.Utils;
using NUnit.Framework;
using Ringtoets.Common.Data.IllustrationPoints;
using Ringtoets.Common.Data.TestUtil.IllustrationPoints;
using Ringtoets.Common.Forms.PropertyClasses;
namespace Ringtoets.Common.Forms.Test.PropertyClasses
{
[TestFixture]
public class FaultTreeIllustrationPointPropertiesTest
{
private const int probabilityPropertyIndex = 0;
private const int reliabilityPropertyIndex = 1;
private const int windDirectionPropertyIndex = 2;
private const int closingScenarioPropertyIndex = 3;
private const int alphasPropertyIndex = 4;
private const int durationsPropertyIndex = 5;
private const int illustrationPointPropertyIndex = 6;
private const string illustrationPointsCategoryName = "Illustratiepunten";
[Test]
public void Constructor_InvalidIllustrationPointType_ThrowsArgumentException()
{
// Setup
const string expectedMessage = "illustrationPointNode type has to be FaultTreeIllustrationPoint";
// Call
TestDelegate test = () => new FaultTreeIllustrationPointProperties(new IllustrationPointNode(new TestSubMechanismIllustrationPoint()), "N");
// Assert
TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage);
}
[Test]
public void Constructor_FaultTreeIllustrationPoint_ReturnsExpectedValues()
{
// Setup
var illustrationPointNode = new IllustrationPointNode(new TestFaultTreeIllustrationPoint(new[]
{
new Stochast("Stochast A", 10.0, 2.5)
}));
var illustrationPointNodeChild = new IllustrationPointNode(new TestFaultTreeIllustrationPoint());
illustrationPointNode.SetChildren(new[]
{
illustrationPointNodeChild,
illustrationPointNodeChild
});
// Call
var faultTree = new FaultTreeIllustrationPointProperties(illustrationPointNode, "NNE");
// Assert
Assert.AreEqual("NNE", faultTree.WindDirection);
Assert.AreEqual(3.14, faultTree.Reliability.Value);
Assert.AreEqual(5, faultTree.Reliability.NumberOfDecimalPlaces);
Assert.AreEqual(StatisticsConverter.ReliabilityToProbability(3.14), faultTree.CalculatedProbability);
Assert.AreEqual("Illustration Point", faultTree.Name);
Assert.IsNotEmpty(faultTree.AlphaValues);
Assert.AreEqual(1, faultTree.AlphaValues.Length);
Assert.AreEqual(2.5, faultTree.AlphaValues.First().Alpha);
Assert.IsNotEmpty(faultTree.Durations);
Assert.AreEqual(1, faultTree.Durations.Length);
Assert.AreEqual(10.0, faultTree.Durations.First().Duration);
Assert.IsNotNull(faultTree.IllustrationPoints);
Assert.AreEqual(2, faultTree.IllustrationPoints.Length);
Assert.AreEqual("NNE", faultTree.IllustrationPoints[0].WindDirection);
Assert.AreEqual("Illustration Point", faultTree.IllustrationPoints[0].Name);
Assert.AreEqual(StatisticsConverter.ReliabilityToProbability(3.14), faultTree.IllustrationPoints[0].CalculatedProbability);
Assert.AreEqual(3.14, faultTree.IllustrationPoints[0].Reliability);
Assert.AreEqual(0, faultTree.IllustrationPoints[0].IllustrationPoints.Length);
}
[Test]
public void VisibleProperties_WithChildIllustrationPointNodes_ExpectedAttributesValues()
{
// Setup
var illustrationPointNode = new IllustrationPointNode(new TestFaultTreeIllustrationPoint());
illustrationPointNode.SetChildren(new[]
{
new IllustrationPointNode(new TestSubMechanismIllustrationPoint()),
new IllustrationPointNode(new TestSubMechanismIllustrationPoint())
});
// Call
var faultTree = new FaultTreeIllustrationPointProperties(illustrationPointNode, "N");
// Assert
PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(faultTree);
Assert.AreEqual(7, dynamicProperties.Count);
PropertyDescriptor probabilityProperty = dynamicProperties[probabilityPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(probabilityProperty,
illustrationPointsCategoryName,
"Berekende kans [1/jaar]",
"De berekende kans van voorkomen van het berekende resultaat.",
true);
PropertyDescriptor reliabilityProperty = dynamicProperties[reliabilityPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(reliabilityProperty,
illustrationPointsCategoryName,
"Betrouwbaarheidsindex berekende kans [-]",
"Betrouwbaarheidsindex van de berekende kans van voorkomen van het berekende resultaat.",
true);
PropertyDescriptor windDirectionProperty = dynamicProperties[windDirectionPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(windDirectionProperty,
illustrationPointsCategoryName,
"Windrichting",
"De windrichting waarvoor dit illlustratiepunt is berekend.",
true);
PropertyDescriptor closingScenarioProperty = dynamicProperties[closingScenarioPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(closingScenarioProperty,
illustrationPointsCategoryName,
"Sluitscenario",
"Het sluitscenario waarvoor dit illustratiepunt is berekend.",
true);
PropertyDescriptor alphasProperty = dynamicProperties[alphasPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(alphasProperty,
illustrationPointsCategoryName,
"Alfa's [-]",
"Berekende invloedscoëfficiënten voor alle beschouwde stochasten.",
true);
PropertyDescriptor durationsProperty = dynamicProperties[durationsPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(durationsProperty,
illustrationPointsCategoryName,
"Tijdsduren [min]",
"Tijdsduren waarop de stochasten betrekking hebben.",
true);
PropertyDescriptor illustrationPointProperty = dynamicProperties[illustrationPointPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(illustrationPointProperty,
illustrationPointsCategoryName,
"Illustratiepunten",
"De lijst van illustratiepunten voor de berekening.",
true);
}
[Test]
public void VisibleProperties_WithoutChildIllustrationPointNodes_ExpectedAttributesValues()
{
// Setup
var faultTree = new FaultTreeIllustrationPointProperties(
new IllustrationPointNode(
new TestFaultTreeIllustrationPoint()), "N");
// Call
PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(faultTree);
// Assert
Assert.AreEqual(6, dynamicProperties.Count);
PropertyDescriptor probabilityProperty = dynamicProperties[probabilityPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(probabilityProperty,
illustrationPointsCategoryName,
"Berekende kans [1/jaar]",
"De berekende kans van voorkomen van het berekende resultaat.",
true);
PropertyDescriptor reliabilityProperty = dynamicProperties[reliabilityPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(reliabilityProperty,
illustrationPointsCategoryName,
"Betrouwbaarheidsindex berekende kans [-]",
"Betrouwbaarheidsindex van de berekende kans van voorkomen van het berekende resultaat.",
true);
PropertyDescriptor windDirectionProperty = dynamicProperties[windDirectionPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(windDirectionProperty,
illustrationPointsCategoryName,
"Windrichting",
"De windrichting waarvoor dit illlustratiepunt is berekend.",
true);
PropertyDescriptor closingScenarioProperty = dynamicProperties[closingScenarioPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(closingScenarioProperty,
illustrationPointsCategoryName,
"Sluitscenario",
"Het sluitscenario waarvoor dit illustratiepunt is berekend.",
true);
PropertyDescriptor alphasProperty = dynamicProperties[alphasPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(alphasProperty,
illustrationPointsCategoryName,
"Alfa's [-]",
"Berekende invloedscoëfficiënten voor alle beschouwde stochasten.",
true);
PropertyDescriptor durationsProperty = dynamicProperties[durationsPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(durationsProperty,
illustrationPointsCategoryName,
"Tijdsduren [min]",
"Tijdsduren waarop de stochasten betrekking hebben.",
true);
}
[Test]
public void ToString_CorrectValue_ReturnsCorrectString()
{
// Setup
var faultTreeProperties = new FaultTreeIllustrationPointProperties(
new IllustrationPointNode(
new TestFaultTreeIllustrationPoint("VeryImportant")),
"NotImportant");
// Call
string toString = faultTreeProperties.ToString();
// Assert
Assert.AreEqual(toString, "VeryImportant");
}
}
}