// 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 Core.Common.Utils; using NUnit.Framework; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.HydraRing.Calculation.Data.Output; namespace Ringtoets.Common.Service.Test { [TestFixture] public class RingtoetsCommonDataCalculationServiceTest { [Test] public void GetCalculationConvergence_WithConvergedResults_CalculationConvergedTrue() { // Setup const double norm = 0.05; double reliabilityIndex = StatisticsConverter.ProbabilityToReliability(norm); // Call CalculationConvergence calculationConverged = RingtoetsCommonDataCalculationService.GetCalculationConvergence(reliabilityIndex, norm); // Assert Assert.AreEqual(CalculationConvergence.CalculatedConverged, calculationConverged); } [Test] public void GetCalculationConvergence_WithoutConvergedResults_CalculationConvergedFalse() { // Setup var output = new ReliabilityIndexCalculationOutput(5.0e-3, 5.0e-3); const double norm = 1; // Call CalculationConvergence calculationConverged = RingtoetsCommonDataCalculationService.GetCalculationConvergence(output.CalculatedReliabilityIndex, norm); // Assert Assert.AreEqual(CalculationConvergence.CalculatedNotConverged, calculationConverged); } [Test] [Combinatorial] public void ProfileSpecificRequiredProbability_WithValidParameters_ReturnSpecificProbability( [Values(1, 0.5, 0)] double norm, [Values(100, 50, 0)] double failureMechanismContribution, [Values(10, 1)] int n) { // Call double probability = RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability(norm, failureMechanismContribution, n); // Assert double expectedProfileSpecificRequiredProbability = norm * (failureMechanismContribution / 100) / n; Assert.AreEqual(expectedProfileSpecificRequiredProbability, probability); } [Test] [SetCulture("nl-NL")] public void ProfileSpecificRequiredProbability_WithInvalidNorm_ThrowsArgumentException( [Values(150, 1 + 1e-6, -1e-6, -150, double.NaN)] double norm) { // Setup const double failureMechanismContribution = 50; int n = 10; // Call TestDelegate action = () => RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability(norm, failureMechanismContribution, n); // Asserty ArgumentOutOfRangeException exception = Assert.Throws(action); Assert.AreEqual(norm, exception.ActualValue); Assert.AreEqual("norm", exception.ParamName); StringAssert.StartsWith("De norm moet in het bereik [0,0, 1,0] liggen." + Environment.NewLine, exception.Message); } [Test] [SetCulture("nl-NL")] public void ProfileSpecificRequiredProbability_WithInvalidFailureMechanismContribution_ThrowsArgumentException( [Values(150, 100 + 1e-6, -1e-6, -150, double.NaN)] double failureMechanismContribution) { // Setup const double norm = 0.5; int n = 10; // Call TestDelegate action = () => RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability(norm, failureMechanismContribution, n); // Assert ArgumentOutOfRangeException exception = Assert.Throws(action); Assert.AreEqual(failureMechanismContribution, exception.ActualValue); Assert.AreEqual("failureMechanismContribution", exception.ParamName); StringAssert.StartsWith("De bijdrage van dit toetsspoor moet in het bereik [0,0, 100,0] liggen." + Environment.NewLine, exception.Message); } [Test] public void ProfileSpecificRequiredProbability_WithInvalidN_ThrowsArgumentException([Values(0, -1)] int n) { // Setup const double norm = 0.5; const double failureMechanismContribution = 50; // Call TestDelegate action = () => RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability(norm, failureMechanismContribution, n); // Assert ArgumentOutOfRangeException exception = Assert.Throws(action); Assert.AreEqual(n, exception.ActualValue); Assert.AreEqual("n", exception.ParamName); StringAssert.StartsWith("De N-waarde van dit toetsspoor moet groter zijn dan 0." + Environment.NewLine, exception.Message); } } }