// 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.ComponentModel;
using Core.Common.Base.Data;
using Core.Common.TestUtil;
using NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.Common.Data.Probabilistics;
using Ringtoets.Common.Forms.PropertyClasses;
using Ringtoets.Piping.Data;
using Ringtoets.Piping.Data.TestUtil;
using Ringtoets.Piping.Forms.PropertyClasses;
namespace Ringtoets.Piping.Forms.Test.PropertyClasses
{
[TestFixture]
public class ShiftedLogNormalDistributionDesignVariablePropertiesTest
{
[Test]
public void SingleParameterConstructor_DesignVariableNull_ThrowArgumentNullException()
{
// Call
TestDelegate test = () => new ShiftedLogNormalDistributionDesignVariableProperties(null);
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("logNormalDesignVariable", exception.ParamName);
}
[Test]
public void SingleParameterConstructor_ExpectedValues()
{
// Setup
var distribution = new LogNormalDistribution();
var designVariable = new LogNormalDistributionDesignVariable(distribution);
// Call
var properties = new ShiftedLogNormalDistributionDesignVariableProperties(designVariable);
// Assert
Assert.IsInstanceOf(properties);
Assert.AreSame(distribution, properties.Data);
Assert.AreEqual(distribution.Mean, properties.Mean);
Assert.AreEqual(distribution.StandardDeviation, properties.StandardDeviation);
Assert.AreEqual("Lognormaal", properties.DistributionType);
}
[Test]
public void Constructor_DesignVariableNull_ThrowArgumentNullException()
{
// Setup
var mocks = new MockRepository();
var handler = mocks.Stub>();
mocks.ReplayAll();
PipingCalculationScenario calculation = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput();
// Call
TestDelegate test = () => new ShiftedLogNormalDistributionDesignVariableProperties(DistributionPropertiesReadOnly.None,
null,
calculation,
calculation.InputParameters,
handler);
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("logNormalDesignVariable", exception.ParamName);
mocks.VerifyAll();
}
[Test]
public void Constructor_ExpectedValues()
{
// Setup
var mockRepository = new MockRepository();
var handler = mockRepository.Stub>();
mockRepository.ReplayAll();
var distribution = new LogNormalDistribution();
var designVariable = new LogNormalDistributionDesignVariable(distribution);
PipingCalculationScenario calculationScenario = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput();
// Call
var properties = new ShiftedLogNormalDistributionDesignVariableProperties(DistributionPropertiesReadOnly.All,
designVariable,
calculationScenario,
calculationScenario.InputParameters,
handler);
// Assert
Assert.IsInstanceOf(properties);
Assert.AreSame(distribution, properties.Data);
Assert.AreEqual(distribution.Mean, properties.Mean);
Assert.AreEqual(distribution.StandardDeviation, properties.StandardDeviation);
Assert.AreEqual("Lognormaal", properties.DistributionType);
mockRepository.VerifyAll();
}
[Test]
public void Constructor_Always_PropertiesHaveExpectedAttributesValues()
{
// Setup
var mockRepository = new MockRepository();
var handler = mockRepository.Stub>();
mockRepository.ReplayAll();
var distribution = new LogNormalDistribution();
var designVariable = new LogNormalDistributionDesignVariable(distribution);
PipingCalculationScenario calculationScenario = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput();
// Call
var properties = new ShiftedLogNormalDistributionDesignVariableProperties(DistributionPropertiesReadOnly.None,
designVariable,
calculationScenario,
calculationScenario.InputParameters,
handler);
// Assert
PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties);
Assert.AreEqual(5, dynamicProperties.Count);
PropertyDescriptor distributionTypeProperty = dynamicProperties[0];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(distributionTypeProperty,
"Misc",
"Type verdeling",
"Het soort kansverdeling waarin deze parameter gedefinieerd wordt.",
true);
PropertyDescriptor meanProperty = dynamicProperties[1];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(meanProperty,
"Misc",
"Verwachtingswaarde",
"De gemiddelde waarde van de lognormale verdeling.");
PropertyDescriptor standardDeviationProperty = dynamicProperties[2];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(standardDeviationProperty,
"Misc",
"Standaardafwijking",
"De standaardafwijking van de lognormale verdeling.");
PropertyDescriptor shiftProperty = dynamicProperties[3];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(shiftProperty,
"Misc",
"Verschuiving",
"De hoeveelheid waarmee de kansverdeling naar rechts (richting van positieve X-as) verschoven is.",
true);
PropertyDescriptor designValueProperty = dynamicProperties[4];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(designValueProperty,
"Misc",
"Rekenwaarde",
"De representatieve waarde die gebruikt wordt door de berekening.",
true);
mockRepository.VerifyAll();
}
[Test]
public void GetProperties_WithData_ReturnExpectedValues()
{
// Setup
var mockRepository = new MockRepository();
var handler = mockRepository.Stub>();
mockRepository.ReplayAll();
var distribution = new LogNormalDistribution(2)
{
Mean = new RoundedDouble(2, 1),
StandardDeviation = new RoundedDouble(2, 2)
};
var designVariable = new LogNormalDistributionDesignVariable(distribution);
PipingCalculationScenario calculationScenario = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput();
// Call
var properties = new ShiftedLogNormalDistributionDesignVariableProperties(DistributionPropertiesReadOnly.None,
designVariable,
calculationScenario,
calculationScenario.InputParameters,
handler);
// Assert
Assert.AreEqual("Lognormaal", properties.DistributionType);
Assert.AreEqual(distribution.Mean, properties.Mean);
Assert.AreEqual(distribution.StandardDeviation, properties.StandardDeviation);
Assert.AreEqual(designVariable.GetDesignValue(), properties.DesignValue);
}
[Test]
[SetCulture("nl-NL")]
public void ToString_Always_ReturnDistributionName()
{
// Setup
var mockRepository = new MockRepository();
var handler = mockRepository.Stub>();
mockRepository.ReplayAll();
var distribution = new LogNormalDistribution(2)
{
Mean = new RoundedDouble(2, 1),
StandardDeviation = new RoundedDouble(2, 2),
Shift = new RoundedDouble(2, 0.3)
};
var designVariable = new LogNormalDistributionDesignVariable(distribution);
PipingCalculationScenario calculationScenario = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput();
// Call
var properties = new ShiftedLogNormalDistributionDesignVariableProperties(DistributionPropertiesReadOnly.None,
designVariable,
calculationScenario,
calculationScenario.InputParameters,
handler);
// Call
var propertyName = properties.ToString();
// Assert
Assert.AreEqual("0,53 (Verwachtingswaarde = 1,00, Standaardafwijking = 2,00, Verschuiving = 0,30)", propertyName);
}
}
}