// 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;
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;
namespace Ringtoets.Common.Forms.Test.PropertyClasses
{
[TestFixture]
public class LogNormalDistributionPropertiesTest
{
private MockRepository mockRepository;
[SetUp]
public void SetUp()
{
mockRepository = new MockRepository();
}
[Test]
public void Constructor_WithoutParameters_ExpectedValues()
{
// Call
var properties = new LogNormalDistributionProperties();
// Assert
Assert.IsInstanceOf>(properties);
Assert.IsNull(properties.Data);
Assert.AreEqual("Lognormaal", properties.DistributionType);
}
[Test]
public void Constructor_WithParameters_ExpectedValues()
{
// Setup
var observerableMock = mockRepository.StrictMock();
mockRepository.ReplayAll();
// Call
var properties = new LogNormalDistributionProperties(DistributionPropertiesReadOnly.None, observerableMock);
// Assert
Assert.IsNull(properties.Data);
Assert.AreEqual("Lognormaal", properties.DistributionType);
mockRepository.VerifyAll();
}
[Test]
[TestCase(DistributionPropertiesReadOnly.Mean)]
[TestCase(DistributionPropertiesReadOnly.StandardDeviation)]
[TestCase(DistributionPropertiesReadOnly.None)]
public void Constructor_NoObservableSetWhileChangesPossible_ThrowArgumentException(
DistributionPropertiesReadOnly flags)
{
// Call
TestDelegate call = () => new LogNormalDistributionProperties(flags, null);
// Assert
TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "Observable must be specified unless no property can be set.");
}
[Test]
public void SetProperties_MeanWithObserverable_ValueSetNotifyObservers()
{
// Setup
var observerableMock = mockRepository.StrictMock();
observerableMock.Expect(o => o.NotifyObservers()).Repeat.Once();
var properties = new LogNormalDistributionProperties(DistributionPropertiesReadOnly.None, observerableMock)
{
Data = new LogNormalDistribution(2)
};
mockRepository.ReplayAll();
RoundedDouble newMeanValue = new RoundedDouble(3, 20);
// Call
properties.Mean = newMeanValue;
// Assert
Assert.AreEqual(newMeanValue, properties.Mean);
mockRepository.VerifyAll();
}
[Test]
[TestCase(DistributionPropertiesReadOnly.All)]
[TestCase(DistributionPropertiesReadOnly.StandardDeviation)]
public void SetProperties_ReadOnlyStandardDeviationWithObserverable_ThrowsArgumentException(DistributionPropertiesReadOnly propertiesReadOnly)
{
// Setup
var observerableMock = mockRepository.StrictMock();
mockRepository.ReplayAll();
var properties = new LogNormalDistributionProperties(propertiesReadOnly, observerableMock)
{
Data = new LogNormalDistribution(2)
};
// Call
TestDelegate test = () => properties.StandardDeviation = new RoundedDouble(2, 20);
// Assert
const string expectedMessage = "StandardDeviation is set to be read-only.";
TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage);
mockRepository.VerifyAll();
}
[Test]
public void SetProperties_StandardDeviationWithObserverable_ValueSetNotifyObservers()
{
// Setup
var observerableMock = mockRepository.StrictMock();
observerableMock.Expect(o => o.NotifyObservers()).Repeat.Once();
mockRepository.ReplayAll();
var properties = new LogNormalDistributionProperties(DistributionPropertiesReadOnly.None, observerableMock)
{
Data = new LogNormalDistribution(2)
};
RoundedDouble newStandardDeviationValue = new RoundedDouble(3, 20);
// Call
properties.StandardDeviation = newStandardDeviationValue;
// Assert
Assert.AreEqual(newStandardDeviationValue, properties.StandardDeviation);
mockRepository.VerifyAll();
}
[Test]
public void Constructor_Always_PropertiesHaveExpectedAttributesValues()
{
// Setup
var observerableMock = mockRepository.StrictMock();
mockRepository.ReplayAll();
// Call
var properties = new LogNormalDistributionProperties(DistributionPropertiesReadOnly.None, observerableMock);
// Assert
PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties);
Assert.AreEqual(3, 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.");
mockRepository.VerifyAll();
}
}
}