// 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.Base.Data; using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.Data.Probabilistics; namespace Ringtoets.Common.Data.Test.Probabilistics { [TestFixture] public class VariationCoefficientLogNormalDistributionTest { [Test] public void Constructor_ExpectedValues() { // Setup const int numberOfDecimals = 3; // Call var distribution = new VariationCoefficientLogNormalDistribution(numberOfDecimals); // Assert Assert.IsInstanceOf(distribution); Assert.AreEqual(numberOfDecimals, distribution.Mean.NumberOfDecimalPlaces); Assert.AreEqual(1.0, distribution.Mean.Value); Assert.AreEqual(numberOfDecimals, distribution.CoefficientOfVariation.NumberOfDecimalPlaces); Assert.AreEqual(1.0, distribution.CoefficientOfVariation.Value); } [Test] [TestCase(-1)] [TestCase(16)] public void Constructor_InvalidNumberOfDecimalPlaces_ThrowArgumentOutOfRangeException(int numberOfDecimals) { // Call TestDelegate call = () => new VariationCoefficientLogNormalDistribution(numberOfDecimals); // Assert TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "Value must be in range [0, 15]."); } [Test] [TestCase(0.005, 0.01)] [TestCase(34.56789, 34.57)] public void Mean_SetNewValue_ReturnNewlySetValue(double actualSetValue, double expectedRoundedValue) { // Setup var distribution = new VariationCoefficientLogNormalDistribution(2); // Call distribution.Mean = (RoundedDouble)actualSetValue; // Assert Assert.AreEqual(expectedRoundedValue, distribution.Mean.Value); } [Test] [TestCase(0.004)] [TestCase(-1.2)] public void Mean_NegativeOrZeroValue_ThrowArgumentOutOfRangeException(double invalidCoefficient) { // Setup var distribution = new VariationCoefficientLogNormalDistribution(2); // Call TestDelegate call = () => distribution.Mean = (RoundedDouble)invalidCoefficient; // Assert string expectedMessage = "Gemiddelde moet groter zijn dan 0."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); } [Test] [TestCase(-0.004, 0.0)] [TestCase(0.0, 0.0)] [TestCase(34.56789, 34.57)] public void CoefficientOfVariation_SetNewValue_ReturnNewlySetValue( double actualSetValue, double expectedRoundedValue) { // Setup var distribution = new VariationCoefficientLogNormalDistribution(2); // Call distribution.CoefficientOfVariation = (RoundedDouble)actualSetValue; // Assert Assert.AreEqual(expectedRoundedValue, distribution.CoefficientOfVariation.Value); } [Test] [TestCase(-0.005)] [TestCase(-1.2)] public void CoefficientOfVariation_NegativeValue_ThrowArgumentOutOfRangeException(double invalidCoefficient) { // Setup var distribution = new VariationCoefficientLogNormalDistribution(2); // Call TestDelegate call = () => distribution.CoefficientOfVariation = (RoundedDouble)invalidCoefficient; // Assert string expectedMessage = "Variatiecoëfficiënt (CV) moet groter zijn dan of gelijk zijn aan 0."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); } } }