Index: Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj
===================================================================
diff -u -r3023413fe1c0f6dd469e8d16f3a6ebf25adac5da -rcfe7c2c39dcb9e0a25af2908650c7191a733f4e2
--- Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj (.../Ringtoets.Common.Service.csproj) (revision 3023413fe1c0f6dd469e8d16f3a6ebf25adac5da)
+++ Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj (.../Ringtoets.Common.Service.csproj) (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2)
@@ -51,6 +51,12 @@
+
+
+
+
+
+
Index: Ringtoets/Common/src/Ringtoets.Common.Service/ValidationRules/LogNormalDistributionRule.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.Service/ValidationRules/LogNormalDistributionRule.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.Service/ValidationRules/LogNormalDistributionRule.cs (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2)
@@ -0,0 +1,67 @@
+// Copyright (C) Stichting Deltares 2016. 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.Collections.Generic;
+using Ringtoets.Common.Data.Probabilistics;
+using RingtoetsCommonServiceResources = Ringtoets.Common.Service.Properties.Resources;
+
+namespace Ringtoets.Common.Service.ValidationRules
+{
+ ///
+ /// Validation rule to validate a .
+ ///
+ public class LogNormalDistributionRule : ValidationRule
+ {
+ private readonly LogNormalDistribution distribution;
+ private readonly string parameterName;
+
+ ///
+ /// Instantiates a to validate a .
+ ///
+ /// The distribution to validate.
+ /// The name of the parameter.
+ /// The validation errors found. Collection is empty if is valid.
+ public LogNormalDistributionRule(LogNormalDistribution distribution, string parameterName)
+ {
+ this.distribution = distribution;
+ this.parameterName = parameterName;
+ }
+
+ public override IEnumerable Validate()
+ {
+ var validationResults = new List();
+
+ if (IsInValidNumber(distribution.Mean))
+ {
+ validationResults.Add(string.Format(RingtoetsCommonServiceResources.DistributionValidationService_ValidateDistribution_Mean_of_0_must_be_positive_value,
+ parameterName));
+ }
+
+ if (IsInValidNumber(distribution.StandardDeviation))
+ {
+ validationResults.Add(string.Format(RingtoetsCommonServiceResources.DistributionValidationService_ValidateDistribution_StandardDeviation_of_ParameterName_0_must_be_larger_or_equal_to_zero,
+ parameterName));
+ }
+
+ return validationResults;
+ }
+ }
+}
Index: Ringtoets/Common/src/Ringtoets.Common.Service/ValidationRules/NormalDistributionRule.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.Service/ValidationRules/NormalDistributionRule.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.Service/ValidationRules/NormalDistributionRule.cs (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2)
@@ -0,0 +1,67 @@
+// Copyright (C) Stichting Deltares 2016. 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.Collections.Generic;
+using Ringtoets.Common.Data.Probabilistics;
+using RingtoetsCommonServiceResources = Ringtoets.Common.Service.Properties.Resources;
+
+namespace Ringtoets.Common.Service.ValidationRules
+{
+ ///
+ /// Validation rule to validate a .
+ ///
+ public class NormalDistributionRule : ValidationRule
+ {
+ private readonly NormalDistribution distribution;
+ private readonly string parameterName;
+
+ ///
+ /// Instantiates a to validate a .
+ ///
+ /// The distribution to validate.
+ /// The name of the parameter.
+ /// The validation errors found. Collection is empty if is valid.
+ public NormalDistributionRule(NormalDistribution distribution, string parameterName)
+ {
+ this.distribution = distribution;
+ this.parameterName = parameterName;
+ }
+
+ public override IEnumerable Validate()
+ {
+ var validationResults = new List();
+
+ if (IsInValidNumber(distribution.Mean))
+ {
+ validationResults.Add(string.Format(RingtoetsCommonServiceResources.DistributionValidationService_ValidateDistribution_Mean_of_0_must_be_a_valid_number,
+ parameterName));
+ }
+
+ if (IsInValidNumber(distribution.StandardDeviation))
+ {
+ validationResults.Add(string.Format(RingtoetsCommonServiceResources.DistributionValidationService_ValidateDistribution_StandardDeviation_of_ParameterName_0_must_be_larger_or_equal_to_zero,
+ parameterName));
+ }
+
+ return validationResults;
+ }
+ }
+}
Index: Ringtoets/Common/src/Ringtoets.Common.Service/ValidationRules/NumericInputRule.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.Service/ValidationRules/NumericInputRule.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.Service/ValidationRules/NumericInputRule.cs (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2)
@@ -0,0 +1,61 @@
+// Copyright (C) Stichting Deltares 2016. 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.Collections.Generic;
+using Core.Common.Base.Data;
+using RingtoetsCommonServiceResources = Ringtoets.Common.Service.Properties.Resources;
+
+namespace Ringtoets.Common.Service.ValidationRules
+{
+ ///
+ /// Validation rule to validate a numeric input.
+ ///
+ public class NumericInputRule : ValidationRule
+ {
+ private readonly RoundedDouble numericInput;
+ private readonly string parameterName;
+
+ ///
+ /// Instantiates a to validate a numeric input.
+ ///
+ /// The numeric input to validate.
+ /// The name of the parameter.
+ /// The validation errors found. Collection is empty if is valid.
+ public NumericInputRule(RoundedDouble numericInput, string parameterName)
+ {
+ this.numericInput = numericInput;
+ this.parameterName = parameterName;
+ }
+
+ public override IEnumerable Validate()
+ {
+ var validationResult = new List();
+
+ if (IsInValidNumber(numericInput))
+ {
+ validationResult.Add(string.Format(RingtoetsCommonServiceResources.Validation_ValidateInput_No_value_entered_for_ParameterName_0_,
+ parameterName));
+ }
+
+ return validationResult;
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.Service/ValidationRules/ValidationRule.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.Service/ValidationRules/ValidationRule.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.Service/ValidationRules/ValidationRule.cs (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2)
@@ -0,0 +1,48 @@
+// Copyright (C) Stichting Deltares 2016. 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.Collections.Generic;
+using Core.Common.Base.Data;
+
+namespace Ringtoets.Common.Service.ValidationRules
+{
+ ///
+ /// Interface for validation rules that are used for validating inputs before performing HydraRing calculations.
+ ///
+ public abstract class ValidationRule
+ {
+ ///
+ /// Validates the subject.
+ ///
+ /// A containing validation messages.
+ public abstract IEnumerable Validate();
+
+ ///
+ /// Checks if a value is NaN or Infinity.
+ ///
+ /// The value which needs to be checked.
+ /// Trueif is invalid, false if otherwise.
+ protected static bool IsInValidNumber(RoundedDouble value)
+ {
+ return double.IsNaN(value) || double.IsInfinity(value);
+ }
+ }
+}
Index: Ringtoets/Common/src/Ringtoets.Common.Service/ValidationRules/VariationCoefficientLogNormalDistributionRule.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.Service/ValidationRules/VariationCoefficientLogNormalDistributionRule.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.Service/ValidationRules/VariationCoefficientLogNormalDistributionRule.cs (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2)
@@ -0,0 +1,69 @@
+// Copyright (C) Stichting Deltares 2016. 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.Collections.Generic;
+using Ringtoets.Common.Data.Probabilistics;
+using RingtoetsCommonServiceResources = Ringtoets.Common.Service.Properties.Resources;
+
+namespace Ringtoets.Common.Service.ValidationRules
+{
+ ///
+ /// Validation rule to validate a .
+ ///
+ public class VariationCoefficientLogNormalDistributionRule : ValidationRule
+ {
+ private readonly VariationCoefficientLogNormalDistribution distribution;
+ private readonly string parameterName;
+
+ ///
+ /// Instantiates a to validate
+ /// a .
+ ///
+ /// The distribution to validate.
+ /// The name of the parameter.
+ /// The validation errors found. Collection is empty if is valid.
+ public VariationCoefficientLogNormalDistributionRule(VariationCoefficientLogNormalDistribution distribution,
+ string parameterName)
+ {
+ this.distribution = distribution;
+ this.parameterName = parameterName;
+ }
+
+ public override IEnumerable Validate()
+ {
+ var validationResults = new List();
+
+ if (IsInValidNumber(distribution.Mean))
+ {
+ validationResults.Add(string.Format(RingtoetsCommonServiceResources.DistributionValidationService_ValidateDistribution_Mean_of_0_must_be_positive_value,
+ parameterName));
+ }
+
+ if (IsInValidNumber(distribution.CoefficientOfVariation))
+ {
+ validationResults.Add(string.Format(RingtoetsCommonServiceResources.DistributionValidationService_ValidateDistribution_CoefficientOfVariation_of_ParameterName_0_must_be_larger_or_equal_to_zero,
+ parameterName));
+ }
+
+ return validationResults;
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.Service/ValidationRules/VariationCoefficientNormalDistributionRule.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.Service/ValidationRules/VariationCoefficientNormalDistributionRule.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.Service/ValidationRules/VariationCoefficientNormalDistributionRule.cs (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2)
@@ -0,0 +1,68 @@
+// Copyright (C) Stichting Deltares 2016. 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.Collections.Generic;
+using Ringtoets.Common.Data.Probabilistics;
+using RingtoetsCommonServiceResources = Ringtoets.Common.Service.Properties.Resources;
+
+namespace Ringtoets.Common.Service.ValidationRules
+{
+ ///
+ /// Validation rule to validate a .
+ ///
+ public class VariationCoefficientNormalDistributionRule : ValidationRule
+ {
+ private readonly VariationCoefficientNormalDistribution distribution;
+ private readonly string parameterName;
+
+ ///
+ /// Instantiates a to validate
+ /// a .
+ ///
+ /// The distribution to validate.
+ /// The name of the parameter.
+ /// The validation errors found. Collection is empty if is valid.
+ public VariationCoefficientNormalDistributionRule(VariationCoefficientNormalDistribution distribution, string parameterName)
+ {
+ this.distribution = distribution;
+ this.parameterName = parameterName;
+ }
+
+ public override IEnumerable Validate()
+ {
+ var validationResults = new List();
+
+ if (IsInValidNumber(distribution.Mean))
+ {
+ validationResults.Add(string.Format(RingtoetsCommonServiceResources.DistributionValidationService_ValidateDistribution_Mean_of_0_must_be_a_valid_number,
+ parameterName));
+ }
+
+ if (IsInValidNumber(distribution.CoefficientOfVariation))
+ {
+ validationResults.Add(string.Format(RingtoetsCommonServiceResources.DistributionValidationService_ValidateDistribution_CoefficientOfVariation_of_ParameterName_0_must_be_larger_or_equal_to_zero,
+ parameterName));
+ }
+
+ return validationResults;
+ }
+ }
+}
Index: Ringtoets/Common/src/Ringtoets.Common.Service/packages.config
===================================================================
diff -u -ra97c4ffe5254af061462539883d25722be13e539 -rcfe7c2c39dcb9e0a25af2908650c7191a733f4e2
--- Ringtoets/Common/src/Ringtoets.Common.Service/packages.config (.../packages.config) (revision a97c4ffe5254af061462539883d25722be13e539)
+++ Ringtoets/Common/src/Ringtoets.Common.Service/packages.config (.../packages.config) (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2)
@@ -24,4 +24,5 @@
+
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj
===================================================================
diff -u -r3023413fe1c0f6dd469e8d16f3a6ebf25adac5da -rcfe7c2c39dcb9e0a25af2908650c7191a733f4e2
--- Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision 3023413fe1c0f6dd469e8d16f3a6ebf25adac5da)
+++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2)
@@ -68,6 +68,12 @@
+
+
+
+
+
+
Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/LogNormalDistributionRuleTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/LogNormalDistributionRuleTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/LogNormalDistributionRuleTest.cs (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2)
@@ -0,0 +1,97 @@
+// Copyright (C) Stichting Deltares 2016. 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.Collections.Generic;
+using System.Linq;
+using Core.Common.Base.Data;
+using NUnit.Framework;
+using Ringtoets.Common.Data.Probabilistics;
+using Ringtoets.Common.Service.ValidationRules;
+
+namespace Ringtoets.Common.Service.Test.ValidationRules
+{
+ [TestFixture]
+ public class LogNormalDistributionRuleTest
+ {
+ private const string paramName = "";
+
+ [Test]
+ public void Validate_ValidNormalDistribution_NoErrorMessage()
+ {
+ // Setup
+ ValidationRule rule = new LogNormalDistributionRule(new LogNormalDistribution(2), paramName);
+
+ // Call
+ IEnumerable message = rule.Validate();
+
+ // Assert
+ CollectionAssert.IsEmpty(message);
+ }
+
+ [Test]
+ [TestCase(double.NaN)]
+ [TestCase(double.PositiveInfinity)]
+ public void Validate_InvalidMean_ErrorMessage(double value)
+ {
+ // Setup
+ var expectedMessage = string.Format("De verwachtingswaarde voor '{0}' moet een positief getal zijn.", paramName);
+ var distribution = new LogNormalDistribution(2)
+ {
+ Mean = (RoundedDouble) value
+ };
+
+ ValidationRule rule = new LogNormalDistributionRule(distribution, paramName);
+
+ // Call
+ IEnumerable messages = rule.Validate();
+
+ string[] validationMessages = messages.ToArray();
+
+ // Assert
+ Assert.AreEqual(1, validationMessages.Length);
+ StringAssert.StartsWith(expectedMessage, validationMessages[0]);
+ }
+
+ [Test]
+ [TestCase(double.NaN)]
+ [TestCase(double.PositiveInfinity)]
+ public void ValidateDistribution_InvalidStandardDeviation_ErrorMessage(double value)
+ {
+ // Setup
+ var expectedMessage = string.Format("De standaard afwijking voor '{0}' moet groter zijn dan of gelijk zijn aan 0.", paramName);
+ var distribution = new LogNormalDistribution(2)
+ {
+ StandardDeviation = (RoundedDouble) value
+ };
+
+ ValidationRule rule = new LogNormalDistributionRule(distribution, paramName);
+
+ // Call
+ IEnumerable messages = rule.Validate();
+
+ string[] validationMessages = messages.ToArray();
+
+ // Assert
+ Assert.AreEqual(1, validationMessages.Length);
+ StringAssert.StartsWith(expectedMessage, validationMessages[0]);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/NormalDistributionRuleTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/NormalDistributionRuleTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/NormalDistributionRuleTest.cs (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2)
@@ -0,0 +1,98 @@
+// Copyright (C) Stichting Deltares 2016. 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.Collections.Generic;
+using System.Linq;
+using Core.Common.Base.Data;
+using NUnit.Framework;
+using Ringtoets.Common.Data.Probabilistics;
+using Ringtoets.Common.Service.ValidationRules;
+
+namespace Ringtoets.Common.Service.Test.ValidationRules
+{
+ [TestFixture]
+ public class NormalDistributionRuleTest
+ {
+ private const string paramName = "";
+
+ [Test]
+ public void Validate_ValidNormalDistribution_NoErrorMessage()
+ {
+ // Setup
+ ValidationRule rule = new NormalDistributionRule(new NormalDistribution(2), paramName);
+
+ // Call
+ IEnumerable message = rule.Validate();
+
+ // Assert
+ CollectionAssert.IsEmpty(message);
+ }
+
+ [Test]
+ [TestCase(double.NaN)]
+ [TestCase(double.NegativeInfinity)]
+ [TestCase(double.PositiveInfinity)]
+ public void Validate_InvalidMean_ErrorMessage(double value)
+ {
+ // Setup
+ var expectedMessage = string.Format("De verwachtingswaarde voor '{0}' moet een concreet getal zijn.", paramName);
+ var distribution = new NormalDistribution(2)
+ {
+ Mean = (RoundedDouble) value
+ };
+
+ ValidationRule rule = new NormalDistributionRule(distribution, paramName);
+
+ // Call
+ IEnumerable messages = rule.Validate();
+
+ string[] validationMessages = messages.ToArray();
+
+ // Assert
+ Assert.AreEqual(1, validationMessages.Length);
+ StringAssert.StartsWith(expectedMessage, validationMessages[0]);
+ }
+
+ [Test]
+ [TestCase(double.NaN)]
+ [TestCase(double.PositiveInfinity)]
+ public void ValidateDistribution_InvalidStandardDeviation_ErrorMessage(double value)
+ {
+ // Setup
+ var expectedMessage = string.Format("De standaard afwijking voor '{0}' moet groter zijn dan of gelijk zijn aan 0.", paramName);
+ var distribution = new NormalDistribution(2)
+ {
+ StandardDeviation = (RoundedDouble) value
+ };
+
+ ValidationRule rule = new NormalDistributionRule(distribution, paramName);
+
+ // Call
+ IEnumerable messages = rule.Validate();
+
+ string[] validationMessages = messages.ToArray();
+
+ // Assert
+ Assert.AreEqual(1, validationMessages.Length);
+ StringAssert.StartsWith(expectedMessage, validationMessages[0]);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/NumericInputRuleTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/NumericInputRuleTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/NumericInputRuleTest.cs (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2)
@@ -0,0 +1,67 @@
+// Copyright (C) Stichting Deltares 2016. 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.Collections.Generic;
+using System.Linq;
+using Core.Common.Base.Data;
+using NUnit.Framework;
+using Ringtoets.Common.Service.ValidationRules;
+
+namespace Ringtoets.Common.Service.Test.ValidationRules
+{
+ [TestFixture]
+ public class NumericInputRuleTest
+ {
+ private const string paramName = "";
+
+ [Test]
+ public void Validate_ValidOrientation_NoErrorMessage()
+ {
+ // Setup
+ ValidationRule rule = new NumericInputRule(new RoundedDouble(2), paramName);
+
+ // Call
+ IEnumerable message = rule.Validate();
+
+ // Assert
+ CollectionAssert.IsEmpty(message);
+ }
+
+ [Test]
+ public void Validate_InvalidOrientation_ErrorMessage()
+ {
+ // Setup
+ var expectedMessage = string.Format("Er is geen concreet getal ingevoerd voor '{0}'.", paramName);
+ var orientation = new RoundedDouble(2, double.NaN);
+
+ ValidationRule rule = new NumericInputRule(orientation, paramName);
+
+ // Call
+ IEnumerable messages = rule.Validate();
+
+ string[] validationMessages = messages.ToArray();
+
+ // Assert
+ Assert.AreEqual(1, validationMessages.Length);
+ StringAssert.StartsWith(expectedMessage, validationMessages[0]);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/ValidationRuleTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/ValidationRuleTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/ValidationRuleTest.cs (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2)
@@ -0,0 +1,60 @@
+// Copyright (C) Stichting Deltares 2016. 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.Base.Data;
+using NUnit.Framework;
+using Ringtoets.Common.Service.ValidationRules;
+
+namespace Ringtoets.Common.Service.Test.ValidationRules
+{
+ [TestFixture]
+ public class ValidationRuleTest
+ {
+ [Test]
+ [TestCase(double.NaN)]
+ [TestCase(double.NegativeInfinity)]
+ [TestCase(double.PositiveInfinity)]
+ public void ValidationRule_ValidatesInvalidNumber_ReturnFalse(double value)
+ {
+ // Call
+ bool isNumberInvalid = TestRule.PublicIsNumberValid((RoundedDouble) value);
+
+ // Assert
+ Assert.IsTrue(isNumberInvalid);
+ }
+ }
+
+ public class TestRule : ValidationRule
+ {
+ public static bool PublicIsNumberValid(RoundedDouble value)
+ {
+ return IsInValidNumber(value);
+ }
+
+ public override IEnumerable Validate()
+ {
+ return Enumerable.Empty();
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/VariationCoefficientLogNormalDistributionRuleTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/VariationCoefficientLogNormalDistributionRuleTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/VariationCoefficientLogNormalDistributionRuleTest.cs (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2)
@@ -0,0 +1,98 @@
+// Copyright (C) Stichting Deltares 2016. 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.Collections.Generic;
+using System.Linq;
+using Core.Common.Base.Data;
+using NUnit.Framework;
+using Ringtoets.Common.Data.Probabilistics;
+using Ringtoets.Common.Service.ValidationRules;
+
+namespace Ringtoets.Common.Service.Test.ValidationRules
+{
+ [TestFixture]
+ public class VariationCoefficientLogNormalDistributionRuleTest
+ {
+ private const string paramName = "";
+
+ [Test]
+ public void Validate_ValidDistribution_NoErrorMessage()
+ {
+ // Setup
+ ValidationRule rule = new VariationCoefficientLogNormalDistributionRule(new VariationCoefficientLogNormalDistribution(2),
+ paramName);
+
+ // Call
+ IEnumerable message = rule.Validate();
+
+ // Assert
+ CollectionAssert.IsEmpty(message);
+ }
+
+ [Test]
+ [TestCase(double.NaN)]
+ [TestCase(double.PositiveInfinity)]
+ public void Validate_InvalidMean_ErrorMessage(double value)
+ {
+ // Setup
+ var expectedMessage = string.Format("De verwachtingswaarde voor '{0}' moet een positief getal zijn.", paramName);
+ var distribution = new VariationCoefficientLogNormalDistribution(2)
+ {
+ Mean = (RoundedDouble) value
+ };
+
+ ValidationRule rule = new VariationCoefficientLogNormalDistributionRule(distribution, paramName);
+
+ // Call
+ IEnumerable messages = rule.Validate();
+
+ string[] validationMessages = messages.ToArray();
+
+ // Assert
+ Assert.AreEqual(1, validationMessages.Length);
+ StringAssert.StartsWith(expectedMessage, validationMessages[0]);
+ }
+
+ [Test]
+ [TestCase(double.NaN)]
+ [TestCase(double.PositiveInfinity)]
+ public void ValidateDistribution_InvalidVariationCoefficient_ErrorMessage(double value)
+ {
+ // Setup
+ var expectedMessage = string.Format("De variatiecoëfficient voor '{0}' moet groter zijn dan of gelijk zijn aan 0.", paramName);
+ var distribution = new VariationCoefficientLogNormalDistribution(2)
+ {
+ CoefficientOfVariation = (RoundedDouble) value
+ };
+
+ ValidationRule rule = new VariationCoefficientLogNormalDistributionRule(distribution, paramName);
+
+ // Call
+ IEnumerable messages = rule.Validate();
+
+ string[] validationMessages = messages.ToArray();
+
+ // Assert
+ Assert.AreEqual(1, validationMessages.Length);
+ StringAssert.StartsWith(expectedMessage, validationMessages[0]);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/VariationCoefficientNormalDistributionRuleTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/VariationCoefficientNormalDistributionRuleTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/ValidationRules/VariationCoefficientNormalDistributionRuleTest.cs (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2)
@@ -0,0 +1,99 @@
+// Copyright (C) Stichting Deltares 2016. 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.Collections.Generic;
+using System.Linq;
+using Core.Common.Base.Data;
+using NUnit.Framework;
+using Ringtoets.Common.Data.Probabilistics;
+using Ringtoets.Common.Service.ValidationRules;
+
+namespace Ringtoets.Common.Service.Test.ValidationRules
+{
+ [TestFixture]
+ public class VariationCoefficientNormalDistributionRuleTest
+ {
+ private const string paramName = "";
+
+ [Test]
+ public void Validate_ValidDistribution_NoErrorMessage()
+ {
+ // Setup
+ ValidationRule rule = new VariationCoefficientNormalDistributionRule(new VariationCoefficientNormalDistribution(2),
+ paramName);
+
+ // Call
+ IEnumerable message = rule.Validate();
+
+ // Assert
+ CollectionAssert.IsEmpty(message);
+ }
+
+ [Test]
+ [TestCase(double.NaN)]
+ [TestCase(double.NegativeInfinity)]
+ [TestCase(double.PositiveInfinity)]
+ public void Validate_InvalidMean_ErrorMessage(double value)
+ {
+ // Setup
+ var expectedMessage = string.Format("De verwachtingswaarde voor '{0}' moet een concreet getal zijn.", paramName);
+ var distribution = new VariationCoefficientNormalDistribution(2)
+ {
+ Mean = (RoundedDouble) value
+ };
+
+ ValidationRule rule = new VariationCoefficientNormalDistributionRule(distribution, paramName);
+
+ // Call
+ IEnumerable messages = rule.Validate();
+
+ string[] validationMessages = messages.ToArray();
+
+ // Assert
+ Assert.AreEqual(1, validationMessages.Length);
+ StringAssert.StartsWith(expectedMessage, validationMessages[0]);
+ }
+
+ [Test]
+ [TestCase(double.NaN)]
+ [TestCase(double.PositiveInfinity)]
+ public void ValidateDistribution_InvalidVariationCoefficient_ErrorMessage(double value)
+ {
+ // Setup
+ var expectedMessage = string.Format("De variatiecoëfficient voor '{0}' moet groter zijn dan of gelijk zijn aan 0.", paramName);
+ var distribution = new VariationCoefficientNormalDistribution(2)
+ {
+ CoefficientOfVariation = (RoundedDouble) value
+ };
+
+ ValidationRule rule = new VariationCoefficientNormalDistributionRule(distribution, paramName);
+
+ // Call
+ IEnumerable messages = rule.Validate();
+
+ string[] validationMessages = messages.ToArray();
+
+ // Assert
+ Assert.AreEqual(1, validationMessages.Length);
+ StringAssert.StartsWith(expectedMessage, validationMessages[0]);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs
===================================================================
diff -u -r183d1e7ed095ea4e8024068bc4ddfcf3ac6997d3 -rcfe7c2c39dcb9e0a25af2908650c7191a733f4e2
--- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs (.../HeightStructuresCalculationService.cs) (revision 183d1e7ed095ea4e8024068bc4ddfcf3ac6997d3)
+++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs (.../HeightStructuresCalculationService.cs) (revision cfe7c2c39dcb9e0a25af2908650c7191a733f4e2)
@@ -28,6 +28,7 @@
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.Common.Data.Structures;
using Ringtoets.Common.Service;
+using Ringtoets.Common.Service.ValidationRules;
using Ringtoets.Common.Utils;
using Ringtoets.HeightStructures.Data;
using Ringtoets.HeightStructures.Service.Properties;
@@ -183,44 +184,44 @@
}
else
{
- validationResults.AddRange(DistributionValidation.ValidateDistribution(inputParameters.StormDuration,
- ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_StormDuration_DisplayName)));
+ IEnumerable inputValidationRules = GetInputValidationRules(inputParameters);
- if (IsInvalidNumber(inputParameters.DeviationWaveDirection))
+ foreach (var validationRule in inputValidationRules)
{
- validationResults.Add(string.Format(RingtoetsCommonServiceResources.Validation_ValidateInput_No_value_entered_for_ParameterName_0_,
- ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_DeviationWaveDirection_DisplayName)));
+ validationResults.AddRange(validationRule.Validate());
}
-
- validationResults.AddRange(DistributionValidation.ValidateDistribution(inputParameters.ModelFactorSuperCriticalFlow,
- ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_ModelFactorSuperCriticalFlow_DisplayName)));
-
- if (IsInvalidNumber(inputParameters.StructureNormalOrientation))
- {
- validationResults.Add(string.Format(RingtoetsCommonServiceResources.Validation_ValidateInput_No_value_entered_for_ParameterName_0_,
- ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Orientation_DisplayName)));
- }
-
- validationResults.AddRange(DistributionValidation.ValidateDistribution(inputParameters.FlowWidthAtBottomProtection,
- ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_FlowWidthAtBottomProtection_DisplayName)));
- validationResults.AddRange(DistributionValidation.ValidateDistribution(inputParameters.WidthFlowApertures,
- ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_WidthFlowApertures_DisplayName)));
- validationResults.AddRange(DistributionValidation.ValidateDistribution(inputParameters.StorageStructureArea,
- ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_StorageStructureArea_DisplayName)));
- validationResults.AddRange(DistributionValidation.ValidateDistribution(inputParameters.AllowedLevelIncreaseStorage,
- ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_AllowedLevelIncreaseStorage_DisplayName)));
- validationResults.AddRange(DistributionValidation.ValidateDistribution(inputParameters.LevelCrestStructure,
- ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_LevelCrestStructure_DisplayName)));
- validationResults.AddRange(DistributionValidation.ValidateDistribution(inputParameters.CriticalOvertoppingDischarge,
- ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_CriticalOvertoppingDischarge_DisplayName)));
}
return validationResults.ToArray();
}
- private static bool IsInvalidNumber(RoundedDouble value)
+ private static IEnumerable GetInputValidationRules(HeightStructuresInput input)
{
- return double.IsNaN(value) || double.IsInfinity(value);
+ var validationRules = new List
+ {
+ new VariationCoefficientLogNormalDistributionRule(input.StormDuration,
+ ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_StormDuration_DisplayName)),
+ new NumericInputRule(input.DeviationWaveDirection,
+ ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_DeviationWaveDirection_DisplayName)),
+ new NormalDistributionRule(input.ModelFactorSuperCriticalFlow,
+ ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_ModelFactorSuperCriticalFlow_DisplayName)),
+ new NumericInputRule(input.StructureNormalOrientation,
+ ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Orientation_DisplayName)),
+ new LogNormalDistributionRule(input.FlowWidthAtBottomProtection,
+ ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_FlowWidthAtBottomProtection_DisplayName)),
+ new VariationCoefficientNormalDistributionRule(input.WidthFlowApertures,
+ ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_WidthFlowApertures_DisplayName)),
+ new VariationCoefficientLogNormalDistributionRule(input.StorageStructureArea,
+ ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_StorageStructureArea_DisplayName)),
+ new LogNormalDistributionRule(input.AllowedLevelIncreaseStorage,
+ ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_AllowedLevelIncreaseStorage_DisplayName)),
+ new NormalDistributionRule(input.LevelCrestStructure,
+ ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_LevelCrestStructure_DisplayName)),
+ new VariationCoefficientLogNormalDistributionRule(input.CriticalOvertoppingDischarge,
+ ParameterNameExtractor.GetFromDisplayName(RingtoetsCommonFormsResources.Structure_CriticalOvertoppingDischarge_DisplayName)),
+ };
+
+ return validationRules;
}
}
}
\ No newline at end of file