Index: Demo/Ringtoets/test/Demo.Ringtoets.Test/Commands/AddNewDemoAssessmentSectionCommandTest.cs =================================================================== diff -u -r0d12e759b6e46290d83d04a6a5760fe467b339ab -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Demo/Ringtoets/test/Demo.Ringtoets.Test/Commands/AddNewDemoAssessmentSectionCommandTest.cs (.../AddNewDemoAssessmentSectionCommandTest.cs) (revision 0d12e759b6e46290d83d04a6a5760fe467b339ab) +++ Demo/Ringtoets/test/Demo.Ringtoets.Test/Commands/AddNewDemoAssessmentSectionCommandTest.cs (.../AddNewDemoAssessmentSectionCommandTest.cs) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -296,12 +296,12 @@ Assert.AreEqual(18.5, heightStructure.FlowWidthAtBottomProtection.Mean.Value); Assert.AreEqual(0.05, heightStructure.FlowWidthAtBottomProtection.StandardDeviation.Value); Assert.AreEqual(0.1, heightStructure.CriticalOvertoppingDischarge.Mean.Value); - Assert.AreEqual(1.5, heightStructure.CriticalOvertoppingDischarge.StandardDeviation.Value); + Assert.AreEqual(1.5, heightStructure.CriticalOvertoppingDischarge.CoefficientOfVariation.Value); Assert.AreEqual(4.0, heightStructure.WidthFlowApertures.Mean.Value); - Assert.AreEqual(0.05, heightStructure.WidthFlowApertures.StandardDeviation.Value); + Assert.AreEqual(0.05, heightStructure.WidthFlowApertures.CoefficientOfVariation.Value); Assert.AreEqual(1.0, heightStructure.FailureProbabilityStructureWithErosion); Assert.AreEqual(50000.0, heightStructure.StorageStructureArea.Mean.Value); - Assert.AreEqual(0.02, heightStructure.StorageStructureArea.StandardDeviation.Value); + Assert.AreEqual(0.02, heightStructure.StorageStructureArea.CoefficientOfVariation.Value); Assert.AreEqual(6.5, heightStructure.AllowedLevelIncreaseStorage.Mean.Value); Assert.AreEqual(0.1, heightStructure.AllowedLevelIncreaseStorage.StandardDeviation.Value); } Fisheye: Tag 9050ad5f3a80e630b2fcc092942a40d6343286a0 refers to a dead (removed) revision in file `Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/DistributionProperties.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/DistributionPropertiesBase.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/DistributionPropertiesBase.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/DistributionPropertiesBase.cs (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -0,0 +1,137 @@ +// 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; +using Core.Common.Base.Data; +using Core.Common.Gui.Attributes; +using Core.Common.Gui.PropertyBag; +using Core.Common.Utils.Attributes; +using Core.Common.Utils.Reflection; +using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.Common.Forms.Properties; + +namespace Ringtoets.Common.Forms.PropertyClasses +{ + /// + /// Properties class for implementations of . + /// + public abstract class DistributionPropertiesBase : ObjectProperties where T : IDistribution + { + private static string meanDisplayName; + private static string standardDeviationDisplayName; + private readonly bool isMeanReadOnly; + private readonly bool isStandardDeviationReadOnly; + private readonly IObservable observable; + + /// + /// Initializes a new instance of the class. + /// + /// Indicates which properties, if any, should be + /// marked as read-only. + /// The object to be notified of changes to properties. + /// Can be null if all properties are marked as read-only by . + /// Thrown when + /// is null and any number of properties in this class is editable. + protected DistributionPropertiesBase(DistributionPropertiesReadOnly propertiesReadOnly, IObservable observable) + { + if (observable == null && !propertiesReadOnly.HasFlag(DistributionPropertiesReadOnly.All)) + { + throw new ArgumentException("Observable must be specified unless no property can be set.", "observable"); + } + + isMeanReadOnly = propertiesReadOnly.HasFlag(DistributionPropertiesReadOnly.Mean); + isStandardDeviationReadOnly = propertiesReadOnly.HasFlag(DistributionPropertiesReadOnly.StandardDeviation); + + meanDisplayName = TypeUtils.GetMemberName>(rd => rd.Mean); + standardDeviationDisplayName = TypeUtils.GetMemberName>(rd => rd.StandardDeviation); + + this.observable = observable; + } + + [PropertyOrder(1)] + [ResourcesDisplayName(typeof(Resources), "Distribution_DestributionType_DisplayName")] + [ResourcesDescription(typeof(Resources), "Distribution_DestributionType_Description")] + public abstract string DistributionType { get; } + + [PropertyOrder(2)] + [DynamicReadOnly] + [ResourcesDisplayName(typeof(Resources), "NormalDistribution_Mean_DisplayName")] + public virtual RoundedDouble Mean + { + get + { + return data.Mean; + } + set + { + if (isMeanReadOnly) + { + throw new ArgumentException("Mean is set to be read-only."); + } + data.Mean = value; + observable.NotifyObservers(); + } + } + + [PropertyOrder(3)] + [DynamicReadOnly] + [ResourcesDisplayName(typeof(Resources), "NormalDistribution_StandardDeviation_DisplayName")] + [ResourcesDescription(typeof(Resources), "NormalDistribution_StandardDeviation_Description")] + public virtual RoundedDouble StandardDeviation + { + get + { + return data.StandardDeviation; + } + set + { + if (isStandardDeviationReadOnly) + { + throw new ArgumentException("StandardDeviation is set to be read-only."); + } + data.StandardDeviation = value; + observable.NotifyObservers(); + } + } + + [DynamicReadOnlyValidationMethod] + public bool DynamicReadOnlyValidationMethod(string propertyName) + { + if (propertyName == meanDisplayName) + { + return isMeanReadOnly; + } + if (propertyName == standardDeviationDisplayName) + { + return isStandardDeviationReadOnly; + } + return false; + } + + public override string ToString() + { + return data == null ? string.Empty : + string.Format("{0} ({1} = {2})", + Mean, Resources.NormalDistribution_StandardDeviation_DisplayName, StandardDeviation); + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/DistributionPropertiesReadOnly.cs =================================================================== diff -u -r9ee17a39e4ba653cfc2e1a576f0ac53dcdf8a7dc -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/DistributionPropertiesReadOnly.cs (.../DistributionPropertiesReadOnly.cs) (revision 9ee17a39e4ba653cfc2e1a576f0ac53dcdf8a7dc) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/DistributionPropertiesReadOnly.cs (.../DistributionPropertiesReadOnly.cs) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -19,39 +19,36 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using Ringtoets.Common.Data.Probabilistics; +using System; namespace Ringtoets.Common.Forms.PropertyClasses { /// - /// All options to mark properties of as read-only. + /// All options to mark properties of as read-only. /// + [Flags] public enum DistributionPropertiesReadOnly { /// - /// Mark both and read-only. + /// Mark read-only. /// - All, + Mean = 1, /// - /// Mark read-only. + /// Mark read-only. /// - Mean, + StandardDeviation = 2, /// - /// Mark read-only. + /// Mark both and + /// as read-only. /// - StandardDeviation, + All = Mean | StandardDeviation, /// - /// Mark variation coefficient read-only. + /// Mark none of the properties of + /// as read-only. /// - VariationCoefficient, - - /// - /// Mark , , - /// and editable. - /// - None + None = 0 } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/LogNormalDistributionProperties.cs =================================================================== diff -u -r9ee17a39e4ba653cfc2e1a576f0ac53dcdf8a7dc -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/LogNormalDistributionProperties.cs (.../LogNormalDistributionProperties.cs) (revision 9ee17a39e4ba653cfc2e1a576f0ac53dcdf8a7dc) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/LogNormalDistributionProperties.cs (.../LogNormalDistributionProperties.cs) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using Core.Common.Base; using Core.Common.Base.Data; using Core.Common.Gui.PropertyBag; @@ -32,24 +33,24 @@ /// An implementation for /// properties. /// - public class LogNormalDistributionProperties : DistributionProperties + public class LogNormalDistributionProperties : DistributionPropertiesBase { /// /// Creates a new read-only instance of . /// - public LogNormalDistributionProperties() : this(null, DistributionPropertiesReadOnly.All) {} + public LogNormalDistributionProperties() : this(DistributionPropertiesReadOnly.All, null) {} /// /// Creates a new instance of . /// - /// Object to notify upon change. - /// Sets if and/or - /// should be marked read-only. - public LogNormalDistributionProperties(IObservable observerable, DistributionPropertiesReadOnly propertiesReadOnly) - : base(propertiesReadOnly) - { - Observerable = observerable; - } + /// Indicates which properties, if any, should be + /// marked as read-only. + /// The object to be notified of changes to properties. + /// Can be null if all properties are marked as read-only by . + /// Thrown when + /// is null and any number of properties in this class is editable. + public LogNormalDistributionProperties(DistributionPropertiesReadOnly propertiesReadOnly, IObservable observable) + : base(propertiesReadOnly, observable) {} public override string DistributionType { Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/LogNormalDistributionVariationProperties.cs =================================================================== diff -u -r9ee17a39e4ba653cfc2e1a576f0ac53dcdf8a7dc -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/LogNormalDistributionVariationProperties.cs (.../LogNormalDistributionVariationProperties.cs) (revision 9ee17a39e4ba653cfc2e1a576f0ac53dcdf8a7dc) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/LogNormalDistributionVariationProperties.cs (.../LogNormalDistributionVariationProperties.cs) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -20,10 +20,8 @@ // All rights reserved. using System; -using System.ComponentModel; using Core.Common.Base; using Core.Common.Base.Data; -using Core.Common.Gui.Attributes; using Core.Common.Gui.PropertyBag; using Core.Common.Utils.Attributes; using Ringtoets.Common.Data.Probabilistics; @@ -32,25 +30,36 @@ namespace Ringtoets.Common.Forms.PropertyClasses { /// - /// An implementation for - /// properties that displays variation coefficient. + /// An implementation for . /// - public class LogNormalDistributionVariationProperties : LogNormalDistributionProperties, IDistributionVariationCoefficient + public class LogNormalDistributionVariationProperties : VariationCoefficientDistributionPropertiesBase { /// /// Creates a new read-only instance of . /// - public LogNormalDistributionVariationProperties() : this(null, DistributionPropertiesReadOnly.All) {} + public LogNormalDistributionVariationProperties() : this(VariationCoefficientDistributionPropertiesReadOnly.All, null) {} /// /// Creates a new instance of . /// - /// Object to notify upon change. - /// Sets if and/or - /// should be marked read-only. - public LogNormalDistributionVariationProperties(IObservable observerable, DistributionPropertiesReadOnly propertiesReadOnly) - : base(observerable, propertiesReadOnly) {} + /// Indicates which properties, if any, should be + /// marked as read-only. + /// The object to be notified of changes to properties. + /// Can be null if all properties are marked as read-only by . + /// Thrown when + /// is null and any number of properties in this class is editable. + public LogNormalDistributionVariationProperties(VariationCoefficientDistributionPropertiesReadOnly propertiesReadOnly, IObservable observable) + : base(propertiesReadOnly, observable) {} + public override string DistributionType + { + get + { + return Resources.DistributionType_LogNormal; + } + } + + [ResourcesDescription(typeof(Resources), "LogNormalDistribution_Mean_Description")] public override RoundedDouble Mean { get @@ -59,49 +68,21 @@ } set { - var variationCoefficient = data.GetVariationCoefficient(); - - SetMean(value); - if (!double.IsInfinity(variationCoefficient)) - { - data.SetStandardDeviationFromVariationCoefficient(variationCoefficient); - Observerable.NotifyObservers(); - } + base.Mean = value; } } - [Browsable(false)] - public override RoundedDouble StandardDeviation { get; set; } - - [PropertyOrder(3)] - [DynamicReadOnly] - [ResourcesDisplayName(typeof(Resources), "Distribution_VariationCoefficient_DisplayName")] [ResourcesDescription(typeof(Resources), "LogNormalDistribution_VariationCoefficient_Description")] - public RoundedDouble VariationCoefficient + public override RoundedDouble CoefficientOfVariation { get { - return data.GetVariationCoefficient(); + return base.CoefficientOfVariation; } set { - if (IsVariationCoefficientReadOnly) - { - throw new ArgumentException("Variation coefficient is set to be read-only."); - } - if (Observerable == null) - { - throw new ArgumentException("No observerable object set."); - } - data.SetStandardDeviationFromVariationCoefficient(value); - Observerable.NotifyObservers(); + base.CoefficientOfVariation = value; } } - - public override string ToString() - { - return data == null ? Resources.Distribution_VariationCoefficient_DisplayName : - string.Format("{0} ({1} = {2})", Mean, Resources.Distribution_VariationCoefficient_DisplayName, VariationCoefficient); - } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/NormalDistributionProperties.cs =================================================================== diff -u -r9ee17a39e4ba653cfc2e1a576f0ac53dcdf8a7dc -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/NormalDistributionProperties.cs (.../NormalDistributionProperties.cs) (revision 9ee17a39e4ba653cfc2e1a576f0ac53dcdf8a7dc) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/NormalDistributionProperties.cs (.../NormalDistributionProperties.cs) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -19,8 +19,11 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using Core.Common.Base; +using Core.Common.Base.Data; using Core.Common.Gui.PropertyBag; +using Core.Common.Utils.Attributes; using Ringtoets.Common.Data.Probabilistics; using Ringtoets.Common.Forms.Properties; @@ -30,23 +33,24 @@ /// An implementation for /// properties. /// - public class NormalDistributionProperties : DistributionProperties + public class NormalDistributionProperties : DistributionPropertiesBase { /// /// Creates a new read-only instance of . /// - public NormalDistributionProperties() : this(null, DistributionPropertiesReadOnly.All) {} + public NormalDistributionProperties() : this(DistributionPropertiesReadOnly.All, null) {} /// /// Creates a new instance of . /// - /// Object to notify upon change. - /// Sets if and/or - /// should be marked read-only. - public NormalDistributionProperties(IObservable observerable, DistributionPropertiesReadOnly propertiesReadOnly) : base(propertiesReadOnly) - { - Observerable = observerable; - } + /// Indicates which properties, if any, should be + /// marked as read-only. + /// The object to be notified of changes to properties. + /// Can be null if all properties are marked as read-only by . + /// Thrown when + /// is null and any number of properties in this class is editable. + public NormalDistributionProperties(DistributionPropertiesReadOnly propertiesReadOnly, IObservable observable) : + base(propertiesReadOnly, observable) {} public override string DistributionType { @@ -55,5 +59,31 @@ return Resources.DistributionType_Normal; } } + + [ResourcesDescription(typeof(Resources), "NormalDistribution_Mean_Description")] + public override RoundedDouble Mean + { + get + { + return base.Mean; + } + set + { + base.Mean = value; + } + } + + [ResourcesDescription(typeof(Resources), "NormalDistribution_StandardDeviation_Description")] + public override RoundedDouble StandardDeviation + { + get + { + return base.StandardDeviation; + } + set + { + base.StandardDeviation = value; + } + } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/NormalDistributionVariationProperties.cs =================================================================== diff -u -r9ee17a39e4ba653cfc2e1a576f0ac53dcdf8a7dc -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/NormalDistributionVariationProperties.cs (.../NormalDistributionVariationProperties.cs) (revision 9ee17a39e4ba653cfc2e1a576f0ac53dcdf8a7dc) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/NormalDistributionVariationProperties.cs (.../NormalDistributionVariationProperties.cs) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -20,10 +20,8 @@ // All rights reserved. using System; -using System.ComponentModel; using Core.Common.Base; using Core.Common.Base.Data; -using Core.Common.Gui.Attributes; using Core.Common.Gui.PropertyBag; using Core.Common.Utils.Attributes; using Ringtoets.Common.Data.Probabilistics; @@ -35,22 +33,34 @@ /// An implementation for /// properties that displays variation coefficient. /// - public class NormalDistributionVariationProperties : NormalDistributionProperties, IDistributionVariationCoefficient + public class NormalDistributionVariationProperties : VariationCoefficientDistributionPropertiesBase { /// /// Creates a new read-only instance of . /// - public NormalDistributionVariationProperties() : this(null, DistributionPropertiesReadOnly.All) {} + public NormalDistributionVariationProperties() : this(VariationCoefficientDistributionPropertiesReadOnly.All, null) {} /// /// Creates a new instance of . /// - /// Object to notify upon change. - /// Sets if and/or - /// should be marked read-only. - public NormalDistributionVariationProperties(IObservable observerable, DistributionPropertiesReadOnly propertiesReadOnly) - : base(observerable, propertiesReadOnly) {} + /// Indicates which properties, if any, should be + /// marked as read-only. + /// The object to be notified of changes to properties. + /// Can be null if all properties are marked as read-only by . + /// Thrown when + /// is null and any number of properties in this class is editable. + public NormalDistributionVariationProperties(VariationCoefficientDistributionPropertiesReadOnly propertiesReadOnly, IObservable observable) + : base(propertiesReadOnly, observable) {} + public override string DistributionType + { + get + { + return Resources.DistributionType_Normal; + } + } + + [ResourcesDescription(typeof(Resources), "NormalDistribution_Mean_Description")] public override RoundedDouble Mean { get @@ -59,48 +69,21 @@ } set { - var variationCoefficient = data.GetVariationCoefficient(); base.Mean = value; - if (!double.IsInfinity(variationCoefficient)) - { - data.SetStandardDeviationFromVariationCoefficient(variationCoefficient); - Observerable.NotifyObservers(); - } } } - [Browsable(false)] - public override RoundedDouble StandardDeviation { get; set; } - - [PropertyOrder(3)] - [DynamicReadOnly] - [ResourcesDisplayName(typeof(Resources), "Distribution_VariationCoefficient_DisplayName")] [ResourcesDescription(typeof(Resources), "NormalDistribution_VariationCoefficient_Description")] - public RoundedDouble VariationCoefficient + public override RoundedDouble CoefficientOfVariation { get { - return data.GetVariationCoefficient(); + return base.CoefficientOfVariation; } set { - if (IsVariationCoefficientReadOnly) - { - throw new ArgumentException("Variation coefficient is set to be read-only."); - } - if (Observerable == null) - { - throw new ArgumentException("No observerable object set."); - } - data.SetStandardDeviationFromVariationCoefficient(value); - Observerable.NotifyObservers(); + base.CoefficientOfVariation = value; } } - - public override string ToString() - { - return data == null ? Resources.Distribution_VariationCoefficient_DisplayName : - string.Format("{0} ({1} = {2})", Mean, Resources.Distribution_VariationCoefficient_DisplayName, VariationCoefficient); - } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/VariationCoefficientDistributionPropertiesBase.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/VariationCoefficientDistributionPropertiesBase.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/VariationCoefficientDistributionPropertiesBase.cs (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -0,0 +1,137 @@ +// 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; +using Core.Common.Base.Data; +using Core.Common.Gui.Attributes; +using Core.Common.Gui.PropertyBag; +using Core.Common.Utils.Attributes; +using Core.Common.Utils.Reflection; +using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.Common.Forms.Properties; + +namespace Ringtoets.Common.Forms.PropertyClasses +{ + /// + /// Properties class for implementations of . + /// + public abstract class VariationCoefficientDistributionPropertiesBase : ObjectProperties where T : IVariationCoefficientDistribution + { + private readonly string meanDisplayName; + private readonly string variationCoefficientDisplayName; + private readonly bool isMeanReadOnly; + private readonly bool isVariationCoefficientReadOnly; + private readonly IObservable observerable; + + /// + /// Initializes a new instance of the class. + /// + /// Indicates which properties, if any, should be + /// marked as read-only. + /// The object to be notified of changes to properties. + /// Can be null if all properties are marked as read-only by . + /// Thrown when + /// is null and any number of properties in this class is editable. + protected VariationCoefficientDistributionPropertiesBase(VariationCoefficientDistributionPropertiesReadOnly propertiesReadOnly, + IObservable observable) + { + if (observable == null && !propertiesReadOnly.HasFlag(VariationCoefficientDistributionPropertiesReadOnly.All)) + { + throw new ArgumentException("Observable must be specified unless no property can be set.", "observable"); + } + + isMeanReadOnly = propertiesReadOnly.HasFlag(VariationCoefficientDistributionPropertiesReadOnly.Mean); + isVariationCoefficientReadOnly = propertiesReadOnly.HasFlag(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation); + + meanDisplayName = TypeUtils.GetMemberName>(d => d.Mean); + variationCoefficientDisplayName = TypeUtils.GetMemberName>(d => d.CoefficientOfVariation); + + observerable = observable; + } + + [PropertyOrder(1)] + [ResourcesDisplayName(typeof(Resources), "Distribution_DestributionType_DisplayName")] + [ResourcesDescription(typeof(Resources), "Distribution_DestributionType_Description")] + public abstract string DistributionType { get; } + + [PropertyOrder(2)] + [DynamicReadOnly] + [ResourcesDisplayName(typeof(Resources), "NormalDistribution_Mean_DisplayName")] + public virtual RoundedDouble Mean + { + get + { + return data.Mean; + } + set + { + if (isMeanReadOnly) + { + throw new InvalidOperationException("Mean is set to be read-only."); + } + data.Mean = value; + observerable.NotifyObservers(); + } + } + + [PropertyOrder(3)] + [DynamicReadOnly] + [ResourcesDisplayName(typeof(Resources), "Distribution_VariationCoefficient_DisplayName")] + public virtual RoundedDouble CoefficientOfVariation + { + get + { + return data.CoefficientOfVariation; + } + set + { + if (isVariationCoefficientReadOnly) + { + throw new InvalidOperationException("CoefficientOfVariation is set to be read-only."); + } + data.CoefficientOfVariation = value; + observerable.NotifyObservers(); + } + } + + [DynamicReadOnlyValidationMethod] + public bool DynamicReadOnlyValidationMethod(string propertyName) + { + if (propertyName == meanDisplayName) + { + return isMeanReadOnly; + } + if (propertyName == variationCoefficientDisplayName) + { + return isVariationCoefficientReadOnly; + } + return false; + } + + public override string ToString() + { + return data == null ? string.Empty : + string.Format("{0} ({1} = {2})", + Mean, Resources.Distribution_VariationCoefficient_DisplayName, CoefficientOfVariation); + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/VariationCoefficientDistributionPropertiesReadOnly.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/VariationCoefficientDistributionPropertiesReadOnly.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/VariationCoefficientDistributionPropertiesReadOnly.cs (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -0,0 +1,57 @@ +// 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; + +namespace Ringtoets.Common.Forms.PropertyClasses +{ + /// + /// Indicator of what properties to mark as read-only for + /// . + /// + [Flags] + public enum VariationCoefficientDistributionPropertiesReadOnly + { + /// + /// Mark as read-only. + /// + Mean = 1, + + /// + /// Mark + /// as read-only. + /// + CoefficientOfVariation = 2, + + /// + /// Marks both and + /// + /// as read-only. + /// + All = Mean | CoefficientOfVariation, + + /// + /// Mark none of the properties of + /// as read-only. + /// + None = 0 + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj =================================================================== diff -u -r443fcdbfa5d49c306f76bb12f054c6e6bf859e18 -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision 443fcdbfa5d49c306f76bb12f054c6e6bf859e18) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -71,7 +71,7 @@ - + @@ -81,6 +81,8 @@ + + Form Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/DistributionPropertiesBaseTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/DistributionPropertiesBaseTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/DistributionPropertiesBaseTest.cs (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -0,0 +1,266 @@ +// 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; +using System.ComponentModel; +using System.Linq; +using Core.Common.Base; +using Core.Common.Base.Data; +using Core.Common.Gui.PropertyBag; +using Core.Common.TestUtil; +using Core.Common.Utils.Attributes; +using Core.Common.Utils.Reflection; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.Common.Forms.Properties; +using Ringtoets.Common.Forms.PropertyClasses; + +namespace Ringtoets.Common.Forms.Test.PropertyClasses +{ + [TestFixture] + public class DistributionPropertiesBaseTest + { + [Test] + public void Constructor_WithParameters_ExpectedValues() + { + // Call + var properties = new SimpleDistributionProperties(DistributionPropertiesReadOnly.All, null); + + // Assert + Assert.IsInstanceOf>(properties); + Assert.IsNull(properties.Data); + } + + [Test] + [TestCase(DistributionPropertiesReadOnly.Mean)] + [TestCase(DistributionPropertiesReadOnly.StandardDeviation)] + [TestCase(DistributionPropertiesReadOnly.None)] + public void Constructor_NoObservableSetWhileChangesPossible_ThrowArgumentException( + DistributionPropertiesReadOnly flags) + { + // Call + TestDelegate call = () => new SimpleDistributionProperties(flags, null); + + // Assert + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "Observable must be specified unless no property can be set."); + } + + [Test] + [TestCase(DistributionPropertiesReadOnly.All, true, true)] + [TestCase(DistributionPropertiesReadOnly.Mean, true, false)] + [TestCase(DistributionPropertiesReadOnly.None, false, false)] + [TestCase(DistributionPropertiesReadOnly.StandardDeviation, false, true)] + public void DynamicReadOnlyValidationMethod_VariousReadOnlySet_ExpectedValues(DistributionPropertiesReadOnly propertiesReadOnly, bool expectMeanReadOnly, bool expectStandardDeviationReadOnly) + { + // Setup + var mocks = new MockRepository(); + var observable = mocks.Stub(); + mocks.ReplayAll(); + + var properties = new SimpleDistributionProperties(propertiesReadOnly, observable); + + // Call + var meanIsReadOnly = properties.DynamicReadOnlyValidationMethod("Mean"); + var standardDeviationIsReadOnly = properties.DynamicReadOnlyValidationMethod("StandardDeviation"); + var doesNotExist = properties.DynamicReadOnlyValidationMethod("DoesNotExist"); + + // Assert + Assert.AreEqual(expectStandardDeviationReadOnly, standardDeviationIsReadOnly); + Assert.AreEqual(expectMeanReadOnly, meanIsReadOnly); + Assert.IsFalse(doesNotExist); + mocks.VerifyAll(); + } + + [Test] + public void Data_SetNewDistributionContextInstance_ReturnCorrectPropertyValues() + { + // Setup + var mocks = new MockRepository(); + var observable = mocks.Stub(); + var distribution = mocks.Stub(); + distribution.Mean = new RoundedDouble(1, 1.1); + distribution.StandardDeviation = new RoundedDouble(2, 2.2); + mocks.ReplayAll(); + + var properties = new SimpleDistributionProperties(DistributionPropertiesReadOnly.None, observable); + + // Call + properties.Data = distribution; + + // Assert + Assert.AreEqual(distribution.Mean, properties.Mean); + Assert.AreEqual(distribution.StandardDeviation, properties.StandardDeviation); + var expectedToString = string.Format("{0} ({1} = {2})", distribution.Mean, Resources.NormalDistribution_StandardDeviation_DisplayName, distribution.StandardDeviation); + Assert.AreEqual(expectedToString, properties.ToString()); + mocks.VerifyAll(); + } + + [Test] + public void SetProperties_MeanWithObserverable_ValueSetNotifyObservers() + { + // Setup + var mockRepository = new MockRepository(); + var observerableMock = mockRepository.StrictMock(); + observerableMock.Expect(o => o.NotifyObservers()); + var distribution = mockRepository.Stub(); + mockRepository.ReplayAll(); + + var properties = new SimpleDistributionProperties(DistributionPropertiesReadOnly.None, observerableMock) + { + Data = distribution + }; + 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_ReadOnlyStandardDeviationWithoutObserverable_ThrowsArgumentException(DistributionPropertiesReadOnly propertiesReadOnly) + { + // Setup + var mocks = new MockRepository(); + var observable = mocks.Stub(); + var distribution = mocks.Stub(); + mocks.ReplayAll(); + + var properties = new SimpleDistributionProperties(propertiesReadOnly, observable) + { + Data = distribution + }; + + // Call + TestDelegate test = () => properties.StandardDeviation = new RoundedDouble(2, 20); + + // Assert + const string expectedMessage = "StandardDeviation is set to be read-only."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + mocks.VerifyAll(); + } + + [Test] + public void SetProperties_StandardDeviationWithObserverable_ValueSetNotifyObservers() + { + // Setup + var mockRepository = new MockRepository(); + var observerableMock = mockRepository.StrictMock(); + observerableMock.Expect(o => o.NotifyObservers()).Repeat.Once(); + var distribution = mockRepository.Stub(); + mockRepository.ReplayAll(); + + var properties = new SimpleDistributionProperties(DistributionPropertiesReadOnly.None, observerableMock) + { + Data = distribution + }; + RoundedDouble newStandardDeviationValue = new RoundedDouble(3, 20); + + // Call + properties.StandardDeviation = newStandardDeviationValue; + + // Assert + Assert.AreEqual(newStandardDeviationValue, properties.StandardDeviation); + mockRepository.VerifyAll(); + } + + [Test] + [TestCase(DistributionPropertiesReadOnly.All, true, true)] + [TestCase(DistributionPropertiesReadOnly.Mean, true, false)] + [TestCase(DistributionPropertiesReadOnly.None, false, false)] + [TestCase(DistributionPropertiesReadOnly.StandardDeviation, false, true)] + public void PropertyAttributes_ReturnExpectedValues(DistributionPropertiesReadOnly propertiesReadOnly, bool expectMeanReadOnly, bool expectStandardDeviationReadOnly) + { + // Call + var mocks = new MockRepository(); + var observable = mocks.Stub(); + var distribution = mocks.Stub(); + mocks.ReplayAll(); + + var properties = new SimpleDistributionProperties(propertiesReadOnly, observable) + { + Data = distribution + }; + + // Assert + var dynamicPropertyBag = new DynamicPropertyBag(properties); + PropertyDescriptorCollection dynamicProperties = dynamicPropertyBag.GetProperties(new Attribute[] + { + new BrowsableAttribute(true) + }); + Assert.AreEqual(3, dynamicProperties.Count); + + var distributionTypePropertyName = TypeUtils.GetMemberName(ndp => ndp.DistributionType); + PropertyDescriptor distributionTypeProperty = dynamicProperties.Find(distributionTypePropertyName, false); + Assert.IsTrue(distributionTypeProperty.IsReadOnly); + AssertAttributeProperty(distributionTypeProperty.Attributes, "Type verdeling", + attribute => attribute.DisplayName); + AssertAttributeProperty(distributionTypeProperty.Attributes, + "Het soort kansverdeling waarin deze parameter gedefinieerd wordt.", + attribute => attribute.Description); + + var meanPropertyName = TypeUtils.GetMemberName(ndp => ndp.Mean); + PropertyDescriptor meanProperty = dynamicProperties.Find(meanPropertyName, false); + Assert.AreEqual(expectMeanReadOnly, meanProperty.IsReadOnly); + AssertAttributeProperty(meanProperty.Attributes, "Verwachtingswaarde", + attribute => attribute.DisplayName); + + var standardDeviationPropertyName = TypeUtils.GetMemberName(ndp => ndp.StandardDeviation); + PropertyDescriptor standardDeviationProperty = dynamicProperties.Find(standardDeviationPropertyName, false); + Assert.AreEqual(expectStandardDeviationReadOnly, standardDeviationProperty.IsReadOnly); + AssertAttributeProperty(standardDeviationProperty.Attributes, "Standaardafwijking", + attribute => attribute.DisplayName); + mocks.VerifyAll(); + } + + private class SimpleDistributionProperties : DistributionPropertiesBase + { + public SimpleDistributionProperties(DistributionPropertiesReadOnly propertiesReadOnly, IObservable observable) + : base(propertiesReadOnly, observable) {} + + public override string DistributionType + { + get + { + return "SimpleDestributionType"; + } + } + } + + private static void AssertAttributeProperty( + IEnumerable attributes, + TAttributePropertyValueType expectedValue, + Func getAttributePropertyValue) + { + var attributesOfTypeTAttributeType = attributes.OfType(); + Assert.IsNotNull(attributesOfTypeTAttributeType); + var attribute = attributesOfTypeTAttributeType.FirstOrDefault(); + Assert.IsNotNull(attribute, string.Format("Attribute type '{0} not found in {1}'", typeof(TAttributeType), attributes)); + Assert.AreEqual(expectedValue, getAttributePropertyValue(attribute)); + } + } +} \ No newline at end of file Fisheye: Tag 9050ad5f3a80e630b2fcc092942a40d6343286a0 refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/DistributionPropertiesTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/LogNormalDistributionPropertiesTest.cs =================================================================== diff -u -rce31448a066c084f755439f3e7d453bfb042b291 -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/LogNormalDistributionPropertiesTest.cs (.../LogNormalDistributionPropertiesTest.cs) (revision ce31448a066c084f755439f3e7d453bfb042b291) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/LogNormalDistributionPropertiesTest.cs (.../LogNormalDistributionPropertiesTest.cs) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -54,7 +54,7 @@ var properties = new LogNormalDistributionProperties(); // Assert - Assert.IsInstanceOf(properties); + Assert.IsInstanceOf>(properties); Assert.IsNull(properties.Data); Assert.AreEqual("Lognormaal", properties.DistributionType); } @@ -67,7 +67,7 @@ mockRepository.ReplayAll(); // Call - var properties = new LogNormalDistributionProperties(observerableMock, DistributionPropertiesReadOnly.None); + var properties = new LogNormalDistributionProperties(DistributionPropertiesReadOnly.None, observerableMock); // Assert Assert.IsNull(properties.Data); @@ -76,53 +76,26 @@ } [Test] - [TestCase(DistributionPropertiesReadOnly.None)] + [TestCase(DistributionPropertiesReadOnly.Mean)] [TestCase(DistributionPropertiesReadOnly.StandardDeviation)] - public void SetProperties_EditableMeanWithoutObserverable_ThrowsArgumentException(DistributionPropertiesReadOnly propertiesReadOnly) + [TestCase(DistributionPropertiesReadOnly.None)] + public void Constructor_NoObservableSetWhileChangesPossible_ThrowArgumentException( + DistributionPropertiesReadOnly flags) { - // Setup - var properties = new LogNormalDistributionProperties(null, propertiesReadOnly) - { - Data = new LogNormalDistribution(2) - }; - // Call - TestDelegate test = () => properties.Mean = new RoundedDouble(2, 20); + TestDelegate call = () => new LogNormalDistributionProperties(flags, null); // Assert - const string expectedMessage = "No observerable object set."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "Observable must be specified unless no property can be set."); } [Test] - [TestCase(DistributionPropertiesReadOnly.All)] - [TestCase(DistributionPropertiesReadOnly.Mean)] - public void SetProperties_ReadOnlyMeanWithObserverable_ThrowsArgumentException(DistributionPropertiesReadOnly propertiesReadOnly) - { - // Setup - var observerableMock = mockRepository.StrictMock(); - mockRepository.ReplayAll(); - var properties = new LogNormalDistributionProperties(observerableMock, propertiesReadOnly) - { - Data = new LogNormalDistribution(2) - }; - - // Call - TestDelegate test = () => properties.Mean = new RoundedDouble(2, 20); - - // Assert - const string expectedMessage = "Mean is set to be read-only."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); - mockRepository.VerifyAll(); - } - - [Test] public void SetProperties_MeanWithObserverable_ValueSetNotifyObservers() { // Setup var observerableMock = mockRepository.StrictMock(); observerableMock.Expect(o => o.NotifyObservers()).Repeat.Once(); - var properties = new LogNormalDistributionProperties(observerableMock, DistributionPropertiesReadOnly.None) + var properties = new LogNormalDistributionProperties(DistributionPropertiesReadOnly.None, observerableMock) { Data = new LogNormalDistribution(2) }; @@ -138,33 +111,14 @@ } [Test] - [TestCase(DistributionPropertiesReadOnly.None)] - [TestCase(DistributionPropertiesReadOnly.Mean)] - public void SetProperties_EditableStandardDeviationWithoutObserverable_ThrowsArgumentException(DistributionPropertiesReadOnly propertiesReadOnly) - { - // Setup - var properties = new LogNormalDistributionProperties(null, propertiesReadOnly) - { - Data = new LogNormalDistribution(2) - }; - - // Call - TestDelegate test = () => properties.StandardDeviation = new RoundedDouble(2, 20); - - // Assert - const string expectedMessage = "No observerable object set."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); - } - - [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(observerableMock, propertiesReadOnly) + var properties = new LogNormalDistributionProperties(propertiesReadOnly, observerableMock) { Data = new LogNormalDistribution(2) }; @@ -185,7 +139,7 @@ var observerableMock = mockRepository.StrictMock(); observerableMock.Expect(o => o.NotifyObservers()).Repeat.Once(); mockRepository.ReplayAll(); - var properties = new LogNormalDistributionProperties(observerableMock, DistributionPropertiesReadOnly.None) + var properties = new LogNormalDistributionProperties(DistributionPropertiesReadOnly.None, observerableMock) { Data = new LogNormalDistribution(2) }; @@ -207,7 +161,7 @@ mockRepository.ReplayAll(); // Call - var properties = new LogNormalDistributionProperties(observerableMock, DistributionPropertiesReadOnly.None); + var properties = new LogNormalDistributionProperties(DistributionPropertiesReadOnly.None, observerableMock); // Assert var dynamicPropertyBag = new DynamicPropertyBag(properties); Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/LogNormalDistributionVariationPropertiesTest.cs =================================================================== diff -u -rce31448a066c084f755439f3e7d453bfb042b291 -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/LogNormalDistributionVariationPropertiesTest.cs (.../LogNormalDistributionVariationPropertiesTest.cs) (revision ce31448a066c084f755439f3e7d453bfb042b291) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/LogNormalDistributionVariationPropertiesTest.cs (.../LogNormalDistributionVariationPropertiesTest.cs) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -40,59 +40,65 @@ [TestFixture] public class LogNormalDistributionVariationPropertiesTest { - private MockRepository mockRepository; - - [SetUp] - public void SetUp() - { - mockRepository = new MockRepository(); - } - [Test] public void Constructor_WithoutParameters_ExpectedValues() { // Call var properties = new LogNormalDistributionVariationProperties(); // Assert - Assert.IsInstanceOf>(properties); + Assert.IsInstanceOf>(properties); Assert.IsNull(properties.Data); - Assert.AreEqual("Variatiecoëfficiënt", properties.ToString()); Assert.AreEqual("Lognormaal", properties.DistributionType); } [Test] public void Constructor_WithParameters_ExpectedValues() { // Call + var mockRepository = new MockRepository(); var observerableMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); - var properties = new LogNormalDistributionVariationProperties(observerableMock, DistributionPropertiesReadOnly.None); + var properties = new LogNormalDistributionVariationProperties(VariationCoefficientDistributionPropertiesReadOnly.None, observerableMock); + // Assert Assert.IsNull(properties.Data); - Assert.AreEqual("Variatiecoëfficiënt", properties.ToString()); Assert.AreEqual("Lognormaal", properties.DistributionType); mockRepository.VerifyAll(); } [Test] - [TestCase(DistributionPropertiesReadOnly.All, true, true)] - [TestCase(DistributionPropertiesReadOnly.Mean, true, false)] - [TestCase(DistributionPropertiesReadOnly.None, false, false)] - [TestCase(DistributionPropertiesReadOnly.StandardDeviation, false, false)] - [TestCase(DistributionPropertiesReadOnly.VariationCoefficient, false, true)] - public void DynamicReadOnlyValidationMethod_VariousReadOnlySet_ExpectedValues(DistributionPropertiesReadOnly propertiesReadOnly, + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.Mean)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.None)] + public void Constructor_EditableFieldsAndWithoutObervable_ThrowArgumentException(VariationCoefficientDistributionPropertiesReadOnly flags) + { + // Call + TestDelegate call = () => new LogNormalDistributionVariationProperties(flags, null); + + // Assert + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "Observable must be specified unless no property can be set."); + } + + [Test] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.All, true, true)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.Mean, true, false)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.None, false, false)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation, false, true)] + public void DynamicReadOnlyValidationMethod_VariousReadOnlySet_ExpectedValues(VariationCoefficientDistributionPropertiesReadOnly propertiesReadOnly, bool expectMeanReadOnly, bool expectVariarionCoefficient) { // Setup + var mockRepository = new MockRepository(); var observerableMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); - var properties = new LogNormalDistributionVariationProperties(observerableMock, propertiesReadOnly); + var properties = new LogNormalDistributionVariationProperties(propertiesReadOnly, observerableMock); + var meanPropertyName = TypeUtils.GetMemberName(lndvp => lndvp.Mean); - var variationCoefficientPropertyName = TypeUtils.GetMemberName(lndvp => lndvp.VariationCoefficient); + var variationCoefficientPropertyName = TypeUtils.GetMemberName(lndvp => lndvp.CoefficientOfVariation); // Call var meanIsReadOnly = properties.DynamicReadOnlyValidationMethod(meanPropertyName); @@ -110,78 +116,62 @@ public void Data_SetNewDistributionContextInstance_ReturnCorrectPropertyValues() { // Setup + var mockRepository = new MockRepository(); var observerableMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); - var properties = new LogNormalDistributionVariationProperties(observerableMock, DistributionPropertiesReadOnly.None); - var distribution = new LogNormalDistribution(2); + var properties = new LogNormalDistributionVariationProperties(VariationCoefficientDistributionPropertiesReadOnly.None, observerableMock); + var distribution = new VariationCoefficientLogNormalDistribution(2); // Call properties.Data = distribution; // Assert Assert.AreEqual(distribution.Mean, properties.Mean); - Assert.AreEqual(distribution.GetVariationCoefficient(), properties.VariationCoefficient); + Assert.AreEqual(distribution.CoefficientOfVariation, properties.CoefficientOfVariation); var expectedToString = string.Format("{0} ({1} = {2})", distribution.Mean, Resources.Distribution_VariationCoefficient_DisplayName, - distribution.GetVariationCoefficient()); + distribution.CoefficientOfVariation); Assert.AreEqual(expectedToString, properties.ToString()); mockRepository.VerifyAll(); } [Test] - [TestCase(DistributionPropertiesReadOnly.None)] - [TestCase(DistributionPropertiesReadOnly.StandardDeviation)] - [TestCase(DistributionPropertiesReadOnly.VariationCoefficient)] - public void SetProperties_EditableMeanWithoutObserverable_ThrowsArgumentException(DistributionPropertiesReadOnly propertiesReadOnly) + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.All)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.Mean)] + public void SetProperties_ReadOnlyMeanWithObserverable_ThrowsArgumentException(VariationCoefficientDistributionPropertiesReadOnly propertiesReadOnly) { // Setup - var properties = new LogNormalDistributionVariationProperties(null, propertiesReadOnly) - { - Data = new LogNormalDistribution(2) - }; - - // Call - TestDelegate test = () => properties.Mean = new RoundedDouble(2, 20); - - // Assert - const string expectedMessage = "No observerable object set."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); - } - - [Test] - [TestCase(DistributionPropertiesReadOnly.All)] - [TestCase(DistributionPropertiesReadOnly.Mean)] - public void SetProperties_ReadOnlyMeanWithObserverable_ThrowsArgumentException(DistributionPropertiesReadOnly propertiesReadOnly) - { - // Setup + var mockRepository = new MockRepository(); var observerableMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); - var properties = new LogNormalDistributionVariationProperties(observerableMock, propertiesReadOnly) + var properties = new LogNormalDistributionVariationProperties(propertiesReadOnly, observerableMock) { - Data = new LogNormalDistribution(2) + Data = new VariationCoefficientLogNormalDistribution(2) }; // Call TestDelegate test = () => properties.Mean = new RoundedDouble(2, 20); // Assert - const string expectedMessage = "Mean is set to be read-only."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + string message = Assert.Throws(test).Message; + Assert.AreEqual("Mean is set to be read-only.", message); mockRepository.VerifyAll(); } [Test] public void SetProperties_MeanWithObserverable_ValueSetNotifyObservers() { // Setup + var mockRepository = new MockRepository(); var observerableMock = mockRepository.StrictMock(); - observerableMock.Expect(o => o.NotifyObservers()).Repeat.Once(); - var properties = new LogNormalDistributionVariationProperties(observerableMock, DistributionPropertiesReadOnly.None) + observerableMock.Expect(o => o.NotifyObservers()); + mockRepository.ReplayAll(); + + var properties = new LogNormalDistributionVariationProperties(VariationCoefficientDistributionPropertiesReadOnly.None, observerableMock) { - Data = new LogNormalDistribution(2) + Data = new VariationCoefficientLogNormalDistribution(2) }; - mockRepository.ReplayAll(); RoundedDouble newMeanValue = new RoundedDouble(3, 20); // Call @@ -193,79 +183,68 @@ } [Test] - [TestCase(DistributionPropertiesReadOnly.None)] - [TestCase(DistributionPropertiesReadOnly.Mean)] - public void SetProperties_EditableVariationCoefficientWithoutObserverable_ThrowsArgumentException(DistributionPropertiesReadOnly propertiesReadOnly) + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.All)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation)] + public void SetProperties_ReadOnlyVariationCoefficientWithoutObserverable_ThrowsArgumentException(VariationCoefficientDistributionPropertiesReadOnly propertiesReadOnly) { // Setup - var properties = new LogNormalDistributionVariationProperties(null, propertiesReadOnly) - { - Data = new LogNormalDistribution(2) - }; + var mocks = new MockRepository(); + var observable = mocks.Stub(); + mocks.ReplayAll(); - // Call - TestDelegate test = () => properties.VariationCoefficient = new RoundedDouble(2, 20); - - // Assert - const string expectedMessage = "No observerable object set."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); - } - - [Test] - [TestCase(DistributionPropertiesReadOnly.All)] - [TestCase(DistributionPropertiesReadOnly.VariationCoefficient)] - public void SetProperties_ReadOnlyVariationCoefficientWithoutObserverable_ThrowsArgumentException(DistributionPropertiesReadOnly propertiesReadOnly) - { - // Setup - var properties = new LogNormalDistributionVariationProperties(null, propertiesReadOnly) + var properties = new LogNormalDistributionVariationProperties(propertiesReadOnly, observable) { - Data = new LogNormalDistribution(2) + Data = new VariationCoefficientLogNormalDistribution(2) }; // Call - TestDelegate test = () => properties.VariationCoefficient = new RoundedDouble(2, 20); + TestDelegate test = () => properties.CoefficientOfVariation = new RoundedDouble(2, 20); // Assert - const string expectedMessage = "Variation coefficient is set to be read-only."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + string message = Assert.Throws(test).Message; + Assert.AreEqual("CoefficientOfVariation is set to be read-only.", message); + mocks.VerifyAll(); } [Test] public void SetProperties_VariationCoefficientWithObserverable_ValueSetNotifyObservers() { // Setup + var mockRepository = new MockRepository(); var observerableMock = mockRepository.StrictMock(); observerableMock.Expect(o => o.NotifyObservers()).Repeat.Once(); - var properties = new LogNormalDistributionVariationProperties(observerableMock, DistributionPropertiesReadOnly.None) + mockRepository.ReplayAll(); + + var properties = new LogNormalDistributionVariationProperties(VariationCoefficientDistributionPropertiesReadOnly.None, observerableMock) { - Data = new LogNormalDistribution(2) + Data = new VariationCoefficientLogNormalDistribution(2) }; - mockRepository.ReplayAll(); RoundedDouble newVariationCoefficientValue = new RoundedDouble(2, 20); // Call - properties.VariationCoefficient = newVariationCoefficientValue; + properties.CoefficientOfVariation = newVariationCoefficientValue; // Assert - Assert.AreEqual(newVariationCoefficientValue, properties.VariationCoefficient); + Assert.AreEqual(newVariationCoefficientValue, properties.CoefficientOfVariation); mockRepository.VerifyAll(); } [Test] - [TestCase(DistributionPropertiesReadOnly.All, true, true)] - [TestCase(DistributionPropertiesReadOnly.Mean, true, false)] - [TestCase(DistributionPropertiesReadOnly.None, false, false)] - [TestCase(DistributionPropertiesReadOnly.VariationCoefficient, false, true)] - public void PropertyAttributes_ReturnExpectedValues(DistributionPropertiesReadOnly propertiesReadOnly, bool expectMeanReadOnly, bool expectVariationCoefficientReadOnly) + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.All, true, true)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.Mean, true, false)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.None, false, false)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation, false, true)] + public void PropertyAttributes_ReturnExpectedValues(VariationCoefficientDistributionPropertiesReadOnly propertiesReadOnly, bool expectMeanReadOnly, bool expectVariationCoefficientReadOnly) { // Setup + var mockRepository = new MockRepository(); var observerableMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); // Call - var properties = new LogNormalDistributionVariationProperties(observerableMock, propertiesReadOnly) + var properties = new LogNormalDistributionVariationProperties(propertiesReadOnly, observerableMock) { - Data = new LogNormalDistribution(2) + Data = new VariationCoefficientLogNormalDistribution(2) }; // Assert @@ -294,7 +273,7 @@ "De gemiddelde waarde van de lognormale verdeling.", attribute => attribute.Description); - var variationCoefficientPropertyName = TypeUtils.GetMemberName(ndp => ndp.VariationCoefficient); + var variationCoefficientPropertyName = TypeUtils.GetMemberName(ndp => ndp.CoefficientOfVariation); PropertyDescriptor variationCoefficientProperty = dynamicProperties.Find(variationCoefficientPropertyName, false); Assert.AreEqual(expectVariationCoefficientReadOnly, variationCoefficientProperty.IsReadOnly); AssertAttributeProperty(variationCoefficientProperty.Attributes, "Variatiecoëfficiënt", Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/NormalDistributionPropertiesTest.cs =================================================================== diff -u -r4d3652c7a7c699c9d32cba00793ee12f10659b87 -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/NormalDistributionPropertiesTest.cs (.../NormalDistributionPropertiesTest.cs) (revision 4d3652c7a7c699c9d32cba00793ee12f10659b87) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/NormalDistributionPropertiesTest.cs (.../NormalDistributionPropertiesTest.cs) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -25,10 +25,12 @@ using System.Linq; using Core.Common.Base; using Core.Common.Gui.PropertyBag; +using Core.Common.TestUtil; using Core.Common.Utils.Attributes; using Core.Common.Utils.Reflection; using NUnit.Framework; using Rhino.Mocks; +using Ringtoets.Common.Data.Probabilistics; using Ringtoets.Common.Forms.PropertyClasses; namespace Ringtoets.Common.Forms.Test.PropertyClasses @@ -51,23 +53,37 @@ var properties = new NormalDistributionProperties(); // Assert - Assert.IsInstanceOf(properties); + Assert.IsInstanceOf>(properties); Assert.IsNull(properties.Data); Assert.AreEqual("Normaal", properties.DistributionType); } [Test] + [TestCase(DistributionPropertiesReadOnly.Mean)] + [TestCase(DistributionPropertiesReadOnly.StandardDeviation)] + [TestCase(DistributionPropertiesReadOnly.None)] + public void Constructor_NoObservableSetWhileChangesPossible_ThrowArgumentException( + DistributionPropertiesReadOnly flags) + { + // Call + TestDelegate call = () => new NormalDistributionProperties(flags, null); + + // Assert + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "Observable must be specified unless no property can be set."); + } + + [Test] public void Constructor_WithParameters_ExpectedValues() { // Setup var observerableMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); // Call - var properties = new NormalDistributionProperties(observerableMock, DistributionPropertiesReadOnly.None); + var properties = new NormalDistributionProperties(DistributionPropertiesReadOnly.None, observerableMock); // Assert - Assert.IsInstanceOf(properties); + Assert.IsInstanceOf>(properties); Assert.IsNull(properties.Data); Assert.AreEqual("Normaal", properties.DistributionType); mockRepository.VerifyAll(); @@ -81,7 +97,7 @@ mockRepository.ReplayAll(); // Call - var properties = new NormalDistributionProperties(observerableMock, DistributionPropertiesReadOnly.None); + var properties = new NormalDistributionProperties(DistributionPropertiesReadOnly.None, observerableMock); // Assert var dynamicPropertyBag = new DynamicPropertyBag(properties); Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/NormalDistributionVariationPropertiesTest.cs =================================================================== diff -u -rce31448a066c084f755439f3e7d453bfb042b291 -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/NormalDistributionVariationPropertiesTest.cs (.../NormalDistributionVariationPropertiesTest.cs) (revision ce31448a066c084f755439f3e7d453bfb042b291) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/NormalDistributionVariationPropertiesTest.cs (.../NormalDistributionVariationPropertiesTest.cs) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -40,59 +40,65 @@ [TestFixture] public class NormalDistributionVariationPropertiesTest { - private MockRepository mockRepository; - - [SetUp] - public void SetUp() - { - mockRepository = new MockRepository(); - } - [Test] public void Constructor_WithoutParameters_ExpectedValues() { // Call var properties = new NormalDistributionVariationProperties(); // Assert - Assert.IsInstanceOf>(properties); + Assert.IsInstanceOf>(properties); Assert.IsNull(properties.Data); - Assert.AreEqual("Variatiecoëfficiënt", properties.ToString()); Assert.AreEqual("Normaal", properties.DistributionType); } [Test] public void Constructor_WithParameters_ExpectedValues() { // Call + var mockRepository = new MockRepository(); var observerableMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); - var properties = new NormalDistributionVariationProperties(observerableMock, DistributionPropertiesReadOnly.None); + var properties = new NormalDistributionVariationProperties(VariationCoefficientDistributionPropertiesReadOnly.None, observerableMock); + // Assert Assert.IsNull(properties.Data); - Assert.AreEqual("Variatiecoëfficiënt", properties.ToString()); Assert.AreEqual("Normaal", properties.DistributionType); mockRepository.VerifyAll(); } [Test] - [TestCase(DistributionPropertiesReadOnly.All, true, true)] - [TestCase(DistributionPropertiesReadOnly.Mean, true, false)] - [TestCase(DistributionPropertiesReadOnly.None, false, false)] - [TestCase(DistributionPropertiesReadOnly.StandardDeviation, false, false)] - [TestCase(DistributionPropertiesReadOnly.VariationCoefficient, false, true)] - public void DynamicReadOnlyValidationMethod_VariousReadOnlySet_ExpectedValues(DistributionPropertiesReadOnly propertiesReadOnly, + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.Mean)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.None)] + public void Constructor_EditableFieldsAndWithoutObervable_ThrowArgumentException(VariationCoefficientDistributionPropertiesReadOnly flags) + { + // Call + TestDelegate call = () => new NormalDistributionVariationProperties(flags, null); + + // Assert + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "Observable must be specified unless no property can be set."); + } + + [Test] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.All, true, true)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.Mean, true, false)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.None, false, false)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation, false, true)] + public void DynamicReadOnlyValidationMethod_VariousReadOnlySet_ExpectedValues(VariationCoefficientDistributionPropertiesReadOnly propertiesReadOnly, bool expectMeanReadOnly, bool expectVariarionCoefficient) { // Setup + var mockRepository = new MockRepository(); var observerableMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); - var properties = new NormalDistributionVariationProperties(observerableMock, propertiesReadOnly); + var properties = new NormalDistributionVariationProperties(propertiesReadOnly, observerableMock); + var meanPropertyName = TypeUtils.GetMemberName(ndvp => ndvp.Mean); - var variationCoefficientPropertyName = TypeUtils.GetMemberName(ndvp => ndvp.VariationCoefficient); + var variationCoefficientPropertyName = TypeUtils.GetMemberName(ndvp => ndvp.CoefficientOfVariation); // Call var meanIsReadOnly = properties.DynamicReadOnlyValidationMethod(meanPropertyName); @@ -110,11 +116,12 @@ public void Data_SetNewDistributionContextInstance_ReturnCorrectPropertyValues() { // Setup + var mockRepository = new MockRepository(); var observerableMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); - var properties = new NormalDistributionVariationProperties(observerableMock, DistributionPropertiesReadOnly.None); - var distribution = new NormalDistribution(2) + var properties = new NormalDistributionVariationProperties(VariationCoefficientDistributionPropertiesReadOnly.None, observerableMock); + var distribution = new VariationCoefficientNormalDistribution(2) { Mean = (RoundedDouble) 2 }; @@ -124,67 +131,52 @@ // Assert Assert.AreEqual(distribution.Mean, properties.Mean); - Assert.AreEqual(distribution.GetVariationCoefficient(), properties.VariationCoefficient); - var expectedToString = string.Format("{0} ({1} = {2})", distribution.Mean, Resources.Distribution_VariationCoefficient_DisplayName, - distribution.GetVariationCoefficient()); + Assert.AreEqual(distribution.CoefficientOfVariation, properties.CoefficientOfVariation); + var expectedToString = string.Format("{0} ({1} = {2})", + distribution.Mean, Resources.Distribution_VariationCoefficient_DisplayName, distribution.CoefficientOfVariation); Assert.AreEqual(expectedToString, properties.ToString()); mockRepository.VerifyAll(); } [Test] - [TestCase(DistributionPropertiesReadOnly.None)] - [TestCase(DistributionPropertiesReadOnly.StandardDeviation)] - [TestCase(DistributionPropertiesReadOnly.VariationCoefficient)] - public void SetProperties_EditableMeanWithoutObserverable_ThrowsArgumentException(DistributionPropertiesReadOnly propertiesReadOnly) + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.All)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.Mean)] + public void SetProperties_ReadOnlyMeanWithObserverable_ThrowsArgumentException(VariationCoefficientDistributionPropertiesReadOnly propertiesReadOnly) { // Setup - var properties = new NormalDistributionVariationProperties(null, propertiesReadOnly) - { - Data = new NormalDistribution(2) - }; - - // Call - TestDelegate test = () => properties.Mean = new RoundedDouble(2, 20); - - // Assert - const string expectedMessage = "No observerable object set."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); - } - - [Test] - [TestCase(DistributionPropertiesReadOnly.All)] - [TestCase(DistributionPropertiesReadOnly.Mean)] - public void SetProperties_ReadOnlyMeanWithObserverable_ThrowsArgumentException(DistributionPropertiesReadOnly propertiesReadOnly) - { - // Setup + var mockRepository = new MockRepository(); var observerableMock = mockRepository.StrictMock(); + observerableMock.Expect(o => o.NotifyObservers()).Repeat.Never(); mockRepository.ReplayAll(); - var properties = new NormalDistributionVariationProperties(observerableMock, propertiesReadOnly) + var properties = new NormalDistributionVariationProperties(propertiesReadOnly, observerableMock) { - Data = new NormalDistribution(2) + Data = new VariationCoefficientNormalDistribution(2) }; // Call TestDelegate test = () => properties.Mean = new RoundedDouble(2, 20); // Assert - const string expectedMessage = "Mean is set to be read-only."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + string message = Assert.Throws(test).Message; + Assert.AreEqual("Mean is set to be read-only.", message); mockRepository.VerifyAll(); } [Test] public void SetProperties_MeanWithObserverable_ValueSetNotifyObservers() { // Setup + var mockRepository = new MockRepository(); var observerableMock = mockRepository.StrictMock(); observerableMock.Expect(o => o.NotifyObservers()).Repeat.Once(); - var properties = new NormalDistributionVariationProperties(observerableMock, DistributionPropertiesReadOnly.None) + + mockRepository.ReplayAll(); + + var properties = new NormalDistributionVariationProperties(VariationCoefficientDistributionPropertiesReadOnly.None, observerableMock) { - Data = new NormalDistribution(2) + Data = new VariationCoefficientNormalDistribution(2) }; - mockRepository.ReplayAll(); RoundedDouble newMeanValue = new RoundedDouble(3, 5); // Call @@ -196,82 +188,72 @@ } [Test] - [TestCase(DistributionPropertiesReadOnly.None)] - [TestCase(DistributionPropertiesReadOnly.Mean)] - public void SetProperties_EditableVariationCoefficientWithoutObserverable_ThrowsArgumentException(DistributionPropertiesReadOnly propertiesReadOnly) + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.All)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation)] + public void SetProperties_ReadOnlyVariationCoefficientWithoutObserverable_ThrowsArgumentException(VariationCoefficientDistributionPropertiesReadOnly propertiesReadOnly) { // Setup - var properties = new NormalDistributionVariationProperties(null, propertiesReadOnly) - { - Data = new NormalDistribution(2) - }; + var mocks = new MockRepository(); + var observable = mocks.Stub(); + mocks.ReplayAll(); - // Call - TestDelegate test = () => properties.VariationCoefficient = new RoundedDouble(2, 20); - - // Assert - const string expectedMessage = "No observerable object set."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); - } - - [Test] - [TestCase(DistributionPropertiesReadOnly.All)] - [TestCase(DistributionPropertiesReadOnly.VariationCoefficient)] - public void SetProperties_ReadOnlyVariationCoefficientWithoutObserverable_ThrowsArgumentException(DistributionPropertiesReadOnly propertiesReadOnly) - { - // Setup - var properties = new NormalDistributionVariationProperties(null, propertiesReadOnly) + var properties = new NormalDistributionVariationProperties(propertiesReadOnly, observable) { - Data = new NormalDistribution(2) + Data = new VariationCoefficientNormalDistribution(2) }; // Call - TestDelegate test = () => properties.VariationCoefficient = new RoundedDouble(2, 20); + TestDelegate test = () => properties.CoefficientOfVariation = new RoundedDouble(2, 20); // Assert - const string expectedMessage = "Variation coefficient is set to be read-only."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + string message = Assert.Throws(test).Message; + Assert.AreEqual("CoefficientOfVariation is set to be read-only.", message); + mocks.VerifyAll(); } [Test] public void SetProperties_VariationCoefficientWithObserverable_ValueSetNotifyObservers() { // Setup + var mockRepository = new MockRepository(); var observerableMock = mockRepository.StrictMock(); observerableMock.Expect(o => o.NotifyObservers()).Repeat.Once(); - var properties = new NormalDistributionVariationProperties(observerableMock, DistributionPropertiesReadOnly.None) + + mockRepository.ReplayAll(); + + var properties = new NormalDistributionVariationProperties(VariationCoefficientDistributionPropertiesReadOnly.None, observerableMock) { - Data = new NormalDistribution(2) + Data = new VariationCoefficientNormalDistribution(2) { Mean = (RoundedDouble) 2 } }; - mockRepository.ReplayAll(); RoundedDouble newVariationCoefficientValue = new RoundedDouble(2, 20); // Call - properties.VariationCoefficient = newVariationCoefficientValue; + properties.CoefficientOfVariation = newVariationCoefficientValue; // Assert - Assert.AreEqual(newVariationCoefficientValue, properties.VariationCoefficient); + Assert.AreEqual(newVariationCoefficientValue, properties.CoefficientOfVariation); mockRepository.VerifyAll(); } [Test] - [TestCase(DistributionPropertiesReadOnly.All, true, true)] - [TestCase(DistributionPropertiesReadOnly.Mean, true, false)] - [TestCase(DistributionPropertiesReadOnly.None, false, false)] - [TestCase(DistributionPropertiesReadOnly.VariationCoefficient, false, true)] - public void PropertyAttributes_ReturnExpectedValues(DistributionPropertiesReadOnly propertiesReadOnly, bool expectMeanReadOnly, bool expectVariationCoefficientReadOnly) + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.All, true, true)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.Mean, true, false)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.None, false, false)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation, false, true)] + public void PropertyAttributes_ReturnExpectedValues(VariationCoefficientDistributionPropertiesReadOnly propertiesReadOnly, bool expectMeanReadOnly, bool expectVariationCoefficientReadOnly) { // Setup + var mockRepository = new MockRepository(); var observerableMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); // Call - var properties = new NormalDistributionVariationProperties(observerableMock, propertiesReadOnly) + var properties = new NormalDistributionVariationProperties(propertiesReadOnly, observerableMock) { - Data = new NormalDistribution(2) + Data = new VariationCoefficientNormalDistribution(2) }; // Assert @@ -300,7 +282,7 @@ "De gemiddelde waarde van de normale verdeling.", attribute => attribute.Description); - var variationCoefficientPropertyName = TypeUtils.GetMemberName(ndp => ndp.VariationCoefficient); + var variationCoefficientPropertyName = TypeUtils.GetMemberName(ndp => ndp.CoefficientOfVariation); PropertyDescriptor variationCoefficientProperty = dynamicProperties.Find(variationCoefficientPropertyName, false); Assert.AreEqual(expectVariationCoefficientReadOnly, variationCoefficientProperty.IsReadOnly); AssertAttributeProperty(variationCoefficientProperty.Attributes, "Variatiecoëfficiënt", Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/VariationCoefficientDistributionPropertiesBaseTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/VariationCoefficientDistributionPropertiesBaseTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/VariationCoefficientDistributionPropertiesBaseTest.cs (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -0,0 +1,354 @@ +// 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; +using System.ComponentModel; +using System.Linq; +using Core.Common.Base; +using Core.Common.Base.Data; +using Core.Common.Gui.PropertyBag; +using Core.Common.TestUtil; +using Core.Common.Utils.Attributes; +using Core.Common.Utils.Reflection; +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 VariationCoefficientDistributionPropertiesBaseTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Setup + var readOnlyFlags = VariationCoefficientDistributionPropertiesReadOnly.All; + + // Call + var properties = new SimpleVariationCoefficientDistributionProperties(readOnlyFlags, null); + + // Assert + Assert.IsInstanceOf>(properties); + Assert.IsNull(properties.Data); + } + + [Test] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.Mean)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.None)] + public void Constructor_NoObservableSetWhileChangesPossible_ThrowArgumentException( + VariationCoefficientDistributionPropertiesReadOnly flags) + { + // Call + TestDelegate call = () => new SimpleVariationCoefficientDistributionProperties(flags, null); + + // Assert + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "Observable must be specified unless no property can be set."); + } + + [Test] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.None, false, false)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.Mean, true, false)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation, false, true)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.All, true, true)] + public void DynamicReadOnlyValidationMethod_VariousReadOnlyCases_ExpectedValues( + VariationCoefficientDistributionPropertiesReadOnly flags, + bool expectMeanReadOnly, bool expectVariationCoefficientReadOnly) + { + // Setup + var mocks = new MockRepository(); + var observable = mocks.Stub(); + mocks.ReplayAll(); + + var properties = new SimpleVariationCoefficientDistributionProperties(flags, observable); + + // Call + bool isMeanReadonly = properties.DynamicReadOnlyValidationMethod("Mean"); + bool isVariationCoefficientReadOnly = properties.DynamicReadOnlyValidationMethod("CoefficientOfVariation"); + + // Assert + Assert.AreEqual(expectMeanReadOnly, isMeanReadonly); + Assert.AreEqual(expectVariationCoefficientReadOnly, isVariationCoefficientReadOnly); + mocks.VerifyAll(); + } + + [Test] + public void DynamicReadOnlyValidationMethod_AllOtherCases_ReturnFalse() + { + // Setup + var properties = new SimpleVariationCoefficientDistributionProperties(VariationCoefficientDistributionPropertiesReadOnly.All, null); + + // Call + bool isReadonly = properties.DynamicReadOnlyValidationMethod(null); + + // Assert + Assert.IsFalse(isReadonly); + } + + [Test] + public void Data_SetNewDistribution_PropertiesReturnCorrectValues() + { + // Setup + var mocks = new MockRepository(); + var distribution = mocks.Stub(); + distribution.Mean = new RoundedDouble(1, 2.3); + distribution.CoefficientOfVariation = new RoundedDouble(4, 5.6789); + mocks.ReplayAll(); + + var properties = new SimpleVariationCoefficientDistributionProperties(VariationCoefficientDistributionPropertiesReadOnly.All, null); + + // Call + properties.Data = distribution; + + // Assert + Assert.AreEqual(distribution.Mean, properties.Mean); + Assert.AreEqual(distribution.CoefficientOfVariation, properties.CoefficientOfVariation); + mocks.VerifyAll(); + } + + [Test] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.Mean)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.All)] + public void Mean_SetValueWhileReadOnly_ThrowsInvalidOperationException( + VariationCoefficientDistributionPropertiesReadOnly flags) + { + // Setup + var mocks = new MockRepository(); + var distribution = mocks.Stub(); + var observable = mocks.Stub(); + mocks.ReplayAll(); + + var properties = new SimpleVariationCoefficientDistributionProperties(flags, observable) + { + Data = distribution + }; + + // Call + TestDelegate call = () => properties.Mean = new RoundedDouble(1, 2.3); + + // Assert + string message = Assert.Throws(call).Message; + Assert.AreEqual("Mean is set to be read-only.", message); + mocks.VerifyAll(); + } + + [Test] + public void Mean_SetValue_ValueChangedAndObservableNotifies() + { + // Setup + var mocks = new MockRepository(); + var distribution = mocks.Stub(); + var observable = mocks.StrictMock(); + observable.Expect(o => o.NotifyObservers()); + mocks.ReplayAll(); + + var properties = new SimpleVariationCoefficientDistributionProperties( + VariationCoefficientDistributionPropertiesReadOnly.None, observable) + { + Data = distribution + }; + + var newMeanValue = new RoundedDouble(1, 2.3); + + // Call + properties.Mean = newMeanValue; + + // Assert + Assert.AreEqual(newMeanValue, distribution.Mean); + mocks.VerifyAll(); + } + + [Test] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.All)] + public void CoefficientOfVariation_SetValueWhileReadOnly_ThrowsInvalidOperationException( + VariationCoefficientDistributionPropertiesReadOnly flags) + { + // Setup + var mocks = new MockRepository(); + var distribution = mocks.Stub(); + var observable = mocks.Stub(); + mocks.ReplayAll(); + + var properties = new SimpleVariationCoefficientDistributionProperties(flags, observable) + { + Data = distribution + }; + + // Call + TestDelegate call = () => properties.CoefficientOfVariation = new RoundedDouble(1, 2.3); + + // Assert + string message = Assert.Throws(call).Message; + Assert.AreEqual("CoefficientOfVariation is set to be read-only.", message); + mocks.VerifyAll(); + } + + [Test] + public void CoefficientOfVariation_SetValue_ValueChangedAndObservableNotifies() + { + // Setup + var mocks = new MockRepository(); + var distribution = mocks.Stub(); + var observable = mocks.StrictMock(); + observable.Expect(o => o.NotifyObservers()); + mocks.ReplayAll(); + + var properties = new SimpleVariationCoefficientDistributionProperties( + VariationCoefficientDistributionPropertiesReadOnly.None, observable) + { + Data = distribution + }; + + var newMeanValue = new RoundedDouble(1, 2.3); + + // Call + properties.CoefficientOfVariation = newMeanValue; + + // Assert + Assert.AreEqual(newMeanValue, distribution.CoefficientOfVariation); + mocks.VerifyAll(); + } + + [Test] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.All, true, true)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.Mean, true, false)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.None, false, false)] + [TestCase(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation, false, true)] + public void PropertyAttributes_VariousReadOnlyScenarios_ReturnExpectedValues( + VariationCoefficientDistributionPropertiesReadOnly flags, bool expectMeanReadOnly, bool expectVariationCoefficientReadOnly) + { + // Setup + var mocks = new MockRepository(); + var observable = mocks.Stub(); + var distribution = mocks.Stub(); + mocks.ReplayAll(); + + // Call + var properties = new SimpleVariationCoefficientDistributionProperties(flags, observable) + { + Data = distribution + }; + + // Assert + var dynamicPropertyBag = new DynamicPropertyBag(properties); + PropertyDescriptorCollection dynamicProperties = dynamicPropertyBag.GetProperties(new Attribute[] + { + new BrowsableAttribute(true) + }); + Assert.AreEqual(3, dynamicProperties.Count); + + var distributionTypePropertyName = TypeUtils.GetMemberName(ndp => ndp.DistributionType); + PropertyDescriptor distributionTypeProperty = dynamicProperties.Find(distributionTypePropertyName, false); + Assert.IsTrue(distributionTypeProperty.IsReadOnly); + AssertAttributeProperty(distributionTypeProperty.Attributes, "Type verdeling", + attribute => attribute.DisplayName); + AssertAttributeProperty(distributionTypeProperty.Attributes, + "Het soort kansverdeling waarin deze parameter gedefinieerd wordt.", + attribute => attribute.Description); + + var meanPropertyName = TypeUtils.GetMemberName(ndp => ndp.Mean); + PropertyDescriptor meanProperty = dynamicProperties.Find(meanPropertyName, false); + Assert.AreEqual(expectMeanReadOnly, meanProperty.IsReadOnly); + AssertAttributeProperty(meanProperty.Attributes, "Verwachtingswaarde", + attribute => attribute.DisplayName); + + var standardDeviationPropertyName = TypeUtils.GetMemberName(ndp => ndp.CoefficientOfVariation); + PropertyDescriptor standardDeviationProperty = dynamicProperties.Find(standardDeviationPropertyName, false); + Assert.AreEqual(expectVariationCoefficientReadOnly, standardDeviationProperty.IsReadOnly); + AssertAttributeProperty(standardDeviationProperty.Attributes, "Variatiecoëfficiënt", + attribute => attribute.DisplayName); + + mocks.VerifyAll(); + } + + [Test] + public void ToString_DataIsNull_ReturnEmptyString() + { + // Setup + var properties = new SimpleVariationCoefficientDistributionProperties(VariationCoefficientDistributionPropertiesReadOnly.All, null); + + // Precondition + Assert.IsNull(properties.Data); + + // Call + string text = properties.ToString(); + + // Assert + Assert.AreEqual(string.Empty, text); + } + + [Test] + [SetCulture("en-US")] + public void ToString_DataSet_ReturnValuesDescriptionText() + { + // Setup + var mocks = new MockRepository(); + var distribution = mocks.Stub(); + distribution.Mean = new RoundedDouble(2, 1.23); + distribution.CoefficientOfVariation = new RoundedDouble(2, 4.56); + mocks.ReplayAll(); + + var properties = new SimpleVariationCoefficientDistributionProperties(VariationCoefficientDistributionPropertiesReadOnly.All, null) + { + Data = distribution + }; + + // Precondition + Assert.IsNotNull(properties.Data); + + // Call + string text = properties.ToString(); + + // Assert + Assert.AreEqual("1.23 (Variatiecoëfficiënt = 4.56)", text); + mocks.VerifyAll(); + } + + private static void AssertAttributeProperty( + IEnumerable attributes, + TAttributePropertyValueType expectedValue, + Func getAttributePropertyValue) + { + var attributesOfTypeTAttributeType = attributes.OfType(); + Assert.IsNotNull(attributesOfTypeTAttributeType); + var attribute = attributesOfTypeTAttributeType.FirstOrDefault(); + Assert.IsNotNull(attribute, string.Format("Attribute type '{0} not found in {1}'", typeof(TAttributeType), attributes)); + Assert.AreEqual(expectedValue, getAttributePropertyValue(attribute)); + } + + private class SimpleVariationCoefficientDistributionProperties : VariationCoefficientDistributionPropertiesBase + { + public SimpleVariationCoefficientDistributionProperties(VariationCoefficientDistributionPropertiesReadOnly propertiesReadOnly, IObservable observable) : base(propertiesReadOnly, observable) {} + + public override string DistributionType + { + get + { + return "A"; + } + } + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj =================================================================== diff -u -r0a6fd2fa18908a63fc029833ea3735709ebd5829 -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision 0a6fd2fa18908a63fc029833ea3735709ebd5829) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -77,7 +77,7 @@ - + @@ -86,6 +86,7 @@ + Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsInputContextProperties.cs =================================================================== diff -u -raa56a5d7a6ec9f083ce3bd7a65d0c5b06470fd3b -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsInputContextProperties.cs (.../GrassCoverErosionInwardsInputContextProperties.cs) (revision aa56a5d7a6ec9f083ce3bd7a65d0c5b06470fd3b) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsInputContextProperties.cs (.../GrassCoverErosionInwardsInputContextProperties.cs) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -192,7 +192,7 @@ { get { - return new LogNormalDistributionProperties(data.WrappedData, DistributionPropertiesReadOnly.None) + return new LogNormalDistributionProperties(DistributionPropertiesReadOnly.None, data.WrappedData) { Data = data.WrappedData.CriticalFlowRate }; Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructure.cs =================================================================== diff -u -r0d12e759b6e46290d83d04a6a5760fe467b339ab -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructure.cs (.../HeightStructure.cs) (revision 0d12e759b6e46290d83d04a6a5760fe467b339ab) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructure.cs (.../HeightStructure.cs) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -44,12 +44,12 @@ /// The mean flow width of the height structure at the bottom protection. /// The standard deviation of the flow width of the height structure at the bottom protection. /// The mean critical overtopping discharge of the height structure. - /// The standard deviation of critical overtopping discharge of the height structure. + /// The coefficient of variation of critical overtopping discharge of the height structure. /// The mean flow apertures width of the height structure. - /// The standard deviation of flow apertures width of the height structure. + /// The coefficient of variation of flow apertures width of the height structure. /// The failure probability of the height structure, given erosion. /// The mean storage area of the height structure. - /// The standard deviation of storage area of the height structure. + /// The coefficient of variation of storage area of the height structure. /// The mean allowable increase of level for storage of the height structure. /// The standard deviation of allowable increase of level for storage of the height structure. /// Thrown when or is null @@ -59,10 +59,10 @@ double structureNormalOrientation, double levelCrestStructureMean, double levelCrestStructureStandardDeviation, double flowWidthAtBottomProtectionMean, double flowWidthAtBottomProtectionStandardDeviation, - double criticalOvertoppingDischargeMean, double criticalOvertoppingDischargeStandardDeviation, - double widthFlowAperturesMean, double widthFlowAperturesStandardDeviation, + double criticalOvertoppingDischargeMean, double criticalOvertoppingDischargeCoefficientOfVariation, + double widthFlowAperturesMean, double widthFlowAperturesCoefficientOfVariation, double failureProbabilityStructureWithErosion, - double storageStructureAreaMean, double storageStructureAreaStandardDeviation, + double storageStructureAreaMean, double storageStructureAreaCoefficientOfVariation, double allowedLevelIncreaseStorageMean, double allowedLevelIncreaseStorageStandardDeviation) : base(name, id, location) { @@ -77,21 +77,21 @@ Mean = new RoundedDouble(2, flowWidthAtBottomProtectionMean), StandardDeviation = new RoundedDouble(2, flowWidthAtBottomProtectionStandardDeviation) }; - CriticalOvertoppingDischarge = new LogNormalDistribution(2) + CriticalOvertoppingDischarge = new VariationCoefficientLogNormalDistribution(2) { Mean = new RoundedDouble(2, criticalOvertoppingDischargeMean), - StandardDeviation = new RoundedDouble(2, criticalOvertoppingDischargeStandardDeviation) + CoefficientOfVariation = new RoundedDouble(2, criticalOvertoppingDischargeCoefficientOfVariation) }; - WidthFlowApertures = new NormalDistribution(2) + WidthFlowApertures = new VariationCoefficientNormalDistribution(2) { Mean = new RoundedDouble(2, widthFlowAperturesMean), - StandardDeviation = new RoundedDouble(2, widthFlowAperturesStandardDeviation) + CoefficientOfVariation = new RoundedDouble(2, widthFlowAperturesCoefficientOfVariation) }; FailureProbabilityStructureWithErosion = failureProbabilityStructureWithErosion; - StorageStructureArea = new LogNormalDistribution(2) + StorageStructureArea = new VariationCoefficientLogNormalDistribution(2) { Mean = new RoundedDouble(2, storageStructureAreaMean), - StandardDeviation = new RoundedDouble(2, storageStructureAreaStandardDeviation) + CoefficientOfVariation = new RoundedDouble(2, storageStructureAreaCoefficientOfVariation) }; AllowedLevelIncreaseStorage = new LogNormalDistribution(2) { @@ -118,12 +118,12 @@ /// /// Gets the critical overtopping discharge of the height structure. /// - public LogNormalDistribution CriticalOvertoppingDischarge { get; private set; } + public VariationCoefficientLogNormalDistribution CriticalOvertoppingDischarge { get; private set; } /// /// Gets the flow apertures width of the height structure. /// - public NormalDistribution WidthFlowApertures { get; private set; } + public VariationCoefficientNormalDistribution WidthFlowApertures { get; private set; } /// /// Gets the failure probability of the height structure, given erosion. @@ -133,7 +133,7 @@ /// /// Gets the storage area of the height structure. /// - public LogNormalDistribution StorageStructureArea { get; private set; } + public VariationCoefficientLogNormalDistribution StorageStructureArea { get; private set; } /// /// Gets the allowable increase of level for storage of the height structure. Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructuresInput.cs =================================================================== diff -u -r0a6fd2fa18908a63fc029833ea3735709ebd5829 -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructuresInput.cs (.../HeightStructuresInput.cs) (revision 0a6fd2fa18908a63fc029833ea3735709ebd5829) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructuresInput.cs (.../HeightStructuresInput.cs) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -40,11 +40,11 @@ private readonly NormalDistribution levelCrestStructure; private readonly NormalDistribution modelFactorSuperCriticalFlow; private readonly LogNormalDistribution allowedLevelIncreaseStorage; - private readonly LogNormalDistribution storageStructureArea; + private readonly VariationCoefficientLogNormalDistribution storageStructureArea; private readonly LogNormalDistribution flowWidthAtBottomProtection; - private readonly LogNormalDistribution criticalOvertoppingDischarge; - private readonly NormalDistribution widthFlowApertures; - private readonly LogNormalDistribution stormDuration; + private readonly VariationCoefficientLogNormalDistribution criticalOvertoppingDischarge; + private readonly VariationCoefficientNormalDistribution widthFlowApertures; + private readonly VariationCoefficientLogNormalDistribution stormDuration; private RoundedDouble structureNormalOrientation; private RoundedDouble deviationWaveDirection; private double failureProbabilityStructureWithErosion; @@ -77,36 +77,36 @@ StandardDeviation = (RoundedDouble) 0.1 }; - storageStructureArea = new LogNormalDistribution(2) + storageStructureArea = new VariationCoefficientLogNormalDistribution(2) { - Mean = (RoundedDouble) 1.0 + Mean = (RoundedDouble) 1.0, + CoefficientOfVariation = (RoundedDouble) 0.1 }; - storageStructureArea.SetStandardDeviationFromVariationCoefficient(0.1); flowWidthAtBottomProtection = new LogNormalDistribution(2) { Mean = (RoundedDouble) double.NaN, StandardDeviation = (RoundedDouble) 0.05 }; - criticalOvertoppingDischarge = new LogNormalDistribution(2) + criticalOvertoppingDischarge = new VariationCoefficientLogNormalDistribution(2) { - Mean = (RoundedDouble) 1.0 + Mean = (RoundedDouble) 1.0, + CoefficientOfVariation = (RoundedDouble) 0.15 }; - criticalOvertoppingDischarge.SetStandardDeviationFromVariationCoefficient(0.15); - widthFlowApertures = new NormalDistribution(2) + widthFlowApertures = new VariationCoefficientNormalDistribution(2) { - StandardDeviation = (RoundedDouble) 0.05 + CoefficientOfVariation = (RoundedDouble) 0.05 }; deviationWaveDirection = new RoundedDouble(2); - stormDuration = new LogNormalDistribution(2) + stormDuration = new VariationCoefficientLogNormalDistribution(2) { - Mean = (RoundedDouble) 6.0 + Mean = (RoundedDouble) 6.0, + CoefficientOfVariation = (RoundedDouble) 0.25 }; - stormDuration.SetStandardDeviationFromVariationCoefficient(0.25); UpdateHeightStructureProperties(); UpdateForeshoreProperties(); @@ -165,7 +165,7 @@ /// [hrs] /// /// Only sets the mean. - public LogNormalDistribution StormDuration + public VariationCoefficientLogNormalDistribution StormDuration { get { @@ -247,7 +247,7 @@ /// Gets or sets the storage structure area. /// [m^2] /// - public LogNormalDistribution StorageStructureArea + public VariationCoefficientLogNormalDistribution StorageStructureArea { get { @@ -256,7 +256,7 @@ set { storageStructureArea.Mean = value.Mean; - storageStructureArea.StandardDeviation = value.StandardDeviation; + storageStructureArea.CoefficientOfVariation = value.CoefficientOfVariation; } } @@ -281,7 +281,7 @@ /// Gets or sets the critical overtopping discharge. /// [m^3/s/m] /// - public LogNormalDistribution CriticalOvertoppingDischarge + public VariationCoefficientLogNormalDistribution CriticalOvertoppingDischarge { get { @@ -290,7 +290,7 @@ set { criticalOvertoppingDischarge.Mean = value.Mean; - criticalOvertoppingDischarge.StandardDeviation = value.StandardDeviation; + criticalOvertoppingDischarge.CoefficientOfVariation = value.CoefficientOfVariation; } } @@ -319,7 +319,7 @@ /// Gets or sets the width of flow apertures. /// [m] /// - public NormalDistribution WidthFlowApertures + public VariationCoefficientNormalDistribution WidthFlowApertures { get { @@ -328,7 +328,7 @@ set { widthFlowApertures.Mean = value.Mean; - widthFlowApertures.StandardDeviation = value.StandardDeviation; + widthFlowApertures.CoefficientOfVariation = value.CoefficientOfVariation; } } @@ -366,7 +366,6 @@ public bool UseBreakWater { get; set; } - public bool UseForeshore { get; set; } public RoundedPoint2DCollection ForeshoreGeometry @@ -379,7 +378,6 @@ } } - public BreakWater BreakWater { get; private set; } private void UpdateHeightStructureProperties() @@ -394,7 +392,7 @@ FailureProbabilityStructureWithErosion = heightStructure.FailureProbabilityStructureWithErosion; StorageStructureArea = heightStructure.StorageStructureArea; AllowedLevelIncreaseStorage = heightStructure.AllowedLevelIncreaseStorage; - } + } } private void UpdateForeshoreProperties() Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/PropertyClasses/HeightStructureProperties.cs =================================================================== diff -u -r0a6fd2fa18908a63fc029833ea3735709ebd5829 -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/PropertyClasses/HeightStructureProperties.cs (.../HeightStructureProperties.cs) (revision 0a6fd2fa18908a63fc029833ea3735709ebd5829) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/PropertyClasses/HeightStructureProperties.cs (.../HeightStructureProperties.cs) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -111,11 +111,11 @@ [ResourcesCategory(typeof(RingtoetsCommonFormsResources), "Categories_Schematization")] [ResourcesDisplayName(typeof(Resources), "StorageStructureArea_DisplayName")] [ResourcesDescription(typeof(Resources), "StorageStructureArea_Description")] - public LogNormalDistributionProperties StorageStructureArea + public LogNormalDistributionVariationProperties StorageStructureArea { get { - return new LogNormalDistributionProperties + return new LogNormalDistributionVariationProperties { Data = data.StorageStructureArea }; @@ -143,11 +143,11 @@ [ResourcesCategory(typeof(RingtoetsCommonFormsResources), "Categories_Schematization")] [ResourcesDisplayName(typeof(Resources), "WidthFlowApertures_DisplayName")] [ResourcesDescription(typeof(Resources), "WidthFlowApertures_Description")] - public NormalDistributionProperties WidthFlowApertures + public NormalDistributionVariationProperties WidthFlowApertures { get { - return new NormalDistributionProperties + return new NormalDistributionVariationProperties { Data = data.WidthFlowApertures }; @@ -159,11 +159,11 @@ [ResourcesCategory(typeof(RingtoetsCommonFormsResources), "Categories_Schematization")] [ResourcesDisplayName(typeof(Resources), "CriticalOvertoppingDischarge_DisplayName")] [ResourcesDescription(typeof(Resources), "CriticalOvertoppingDischarge_Description")] - public LogNormalDistributionProperties CriticalOvertoppingDischarge + public LogNormalDistributionVariationProperties CriticalOvertoppingDischarge { get { - return new LogNormalDistributionProperties + return new LogNormalDistributionVariationProperties { Data = data.CriticalOvertoppingDischarge }; Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/PropertyClasses/HeightStructuresInputContextProperties.cs =================================================================== diff -u -r0a6fd2fa18908a63fc029833ea3735709ebd5829 -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/PropertyClasses/HeightStructuresInputContextProperties.cs (.../HeightStructuresInputContextProperties.cs) (revision 0a6fd2fa18908a63fc029833ea3735709ebd5829) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/PropertyClasses/HeightStructuresInputContextProperties.cs (.../HeightStructuresInputContextProperties.cs) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -74,7 +74,7 @@ { get { - return new NormalDistributionProperties(data.WrappedData, DistributionPropertiesReadOnly.StandardDeviation) + return new NormalDistributionProperties(DistributionPropertiesReadOnly.StandardDeviation, data.WrappedData) { Data = data.WrappedData.ModelFactorSuperCriticalFlow }; @@ -174,7 +174,7 @@ { get { - return new NormalDistributionProperties(data.WrappedData, DistributionPropertiesReadOnly.None) + return new NormalDistributionProperties(DistributionPropertiesReadOnly.None, data.WrappedData) { Data = data.WrappedData.LevelCrestStructure }; @@ -190,7 +190,7 @@ { get { - return new LogNormalDistributionProperties(data.WrappedData, DistributionPropertiesReadOnly.None) + return new LogNormalDistributionProperties(DistributionPropertiesReadOnly.None, data.WrappedData) { Data = data.WrappedData.AllowedLevelIncreaseStorage }; @@ -206,7 +206,7 @@ { get { - return new LogNormalDistributionVariationProperties(data.WrappedData, DistributionPropertiesReadOnly.None) + return new LogNormalDistributionVariationProperties(VariationCoefficientDistributionPropertiesReadOnly.None, data.WrappedData) { Data = data.WrappedData.StorageStructureArea }; @@ -222,7 +222,7 @@ { get { - return new LogNormalDistributionProperties(data.WrappedData, DistributionPropertiesReadOnly.None) + return new LogNormalDistributionProperties(DistributionPropertiesReadOnly.None, data.WrappedData) { Data = data.WrappedData.FlowWidthAtBottomProtection }; @@ -234,11 +234,11 @@ [ResourcesCategory(typeof(RingtoetsCommonFormsResources), "Categories_Schematization")] [ResourcesDisplayName(typeof(Resources), "WidthFlowApertures_DisplayName")] [ResourcesDescription(typeof(Resources), "WidthFlowApertures_Description")] - public NormalDistributionProperties WidthFlowApertures + public NormalDistributionVariationProperties WidthFlowApertures { get { - return new NormalDistributionProperties(data.WrappedData, DistributionPropertiesReadOnly.None) + return new NormalDistributionVariationProperties(VariationCoefficientDistributionPropertiesReadOnly.None, data.WrappedData) { Data = data.WrappedData.WidthFlowApertures }; @@ -254,7 +254,7 @@ { get { - return new LogNormalDistributionVariationProperties(data.WrappedData, DistributionPropertiesReadOnly.None) + return new LogNormalDistributionVariationProperties(VariationCoefficientDistributionPropertiesReadOnly.None, data.WrappedData) { Data = data.WrappedData.CriticalOvertoppingDischarge }; @@ -373,7 +373,7 @@ { get { - return new LogNormalDistributionVariationProperties(data.WrappedData, DistributionPropertiesReadOnly.VariationCoefficient) + return new LogNormalDistributionVariationProperties(VariationCoefficientDistributionPropertiesReadOnly.CoefficientOfVariation, data.WrappedData) { Data = data.WrappedData.StormDuration }; Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresImporter.cs =================================================================== diff -u -r53ce7ab9ad9a8cf116723e5ddb4108cf655ec955 -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresImporter.cs (.../HeightStructuresImporter.cs) (revision 53ce7ab9ad9a8cf116723e5ddb4108cf655ec955) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresImporter.cs (.../HeightStructuresImporter.cs) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -106,12 +106,11 @@ structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE1").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE2").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE2").VarianceValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE3").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE3").VarianceValue, - structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE4").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE4").VarianceValue, - structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE5").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE5").VarianceValue, + structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE4").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE4").VarianceValue, //TODO: Ensure Coefficient of variation is properly set + structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE5").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE5").VarianceValue, //TODO: Ensure Coefficient of variation is properly set structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE6").NumericalValue, - structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE7").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE7").VarianceValue, - structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE8").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE8").VarianceValue - ); + structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE7").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE7").VarianceValue, //TODO: Ensure Coefficient of variation is properly set + structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE8").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE8").VarianceValue); return heightStructure; } } Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs =================================================================== diff -u -re69acb9595f7bf1d202ddd1fb51934b66768b75d -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs (.../HeightStructuresCalculationService.cs) (revision e69acb9595f7bf1d202ddd1fb51934b66768b75d) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs (.../HeightStructuresCalculationService.cs) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -24,15 +24,13 @@ using log4net; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.FailureMechanism; -using Ringtoets.Common.Data.Probabilistics; using Ringtoets.Common.Service; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.Service.Properties; using Ringtoets.HydraRing.Calculation.Calculator; using Ringtoets.HydraRing.Calculation.Calculator.Factory; using Ringtoets.HydraRing.Calculation.Data; using Ringtoets.HydraRing.Calculation.Data.Input.Structures; -using Ringtoets.HydraRing.Calculation.Data.Output; using Ringtoets.HydraRing.Calculation.Parsers; using Ringtoets.HydraRing.IO; using RingtoetsCommonServiceResources = Ringtoets.Common.Service.Properties.Resources; @@ -143,14 +141,14 @@ calculation.InputParameters.ModelFactorSuperCriticalFlow.Mean, calculation.InputParameters.ModelFactorSuperCriticalFlow.StandardDeviation, calculation.InputParameters.AllowedLevelIncreaseStorage.Mean, calculation.InputParameters.AllowedLevelIncreaseStorage.StandardDeviation, generalInput.ModelFactorStorageVolume.Mean, generalInput.ModelFactorStorageVolume.StandardDeviation, - calculation.InputParameters.StorageStructureArea.Mean, calculation.InputParameters.StorageStructureArea.GetVariationCoefficient(), + calculation.InputParameters.StorageStructureArea.Mean, calculation.InputParameters.StorageStructureArea.CoefficientOfVariation, generalInput.ModelFactorInflowVolume, calculation.InputParameters.FlowWidthAtBottomProtection.Mean, calculation.InputParameters.FlowWidthAtBottomProtection.StandardDeviation, - calculation.InputParameters.CriticalOvertoppingDischarge.Mean, calculation.InputParameters.CriticalOvertoppingDischarge.GetVariationCoefficient(), + calculation.InputParameters.CriticalOvertoppingDischarge.Mean, calculation.InputParameters.CriticalOvertoppingDischarge.CoefficientOfVariation, calculation.InputParameters.FailureProbabilityStructureWithErosion, - calculation.InputParameters.WidthFlowApertures.Mean, calculation.InputParameters.WidthFlowApertures.GetVariationCoefficient(), + calculation.InputParameters.WidthFlowApertures.Mean, calculation.InputParameters.WidthFlowApertures.CoefficientOfVariation, calculation.InputParameters.DeviationWaveDirection, - calculation.InputParameters.StormDuration.Mean, calculation.InputParameters.StormDuration.GetVariationCoefficient()); + calculation.InputParameters.StormDuration.Mean, calculation.InputParameters.StormDuration.CoefficientOfVariation); } private static IEnumerable ParseForeshore(HeightStructuresInput input) Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructureTest.cs =================================================================== diff -u -r0d12e759b6e46290d83d04a6a5760fe467b339ab -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructureTest.cs (.../HeightStructureTest.cs) (revision 0d12e759b6e46290d83d04a6a5760fe467b339ab) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructureTest.cs (.../HeightStructureTest.cs) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -59,45 +59,39 @@ Assert.AreEqual(2, heightStructure.StructureNormalOrientation.NumberOfDecimalPlaces); Assert.AreEqual(0.12, heightStructure.StructureNormalOrientation.Value); - var levelCrestStructure = heightStructure.LevelCrestStructure; - Assert.IsInstanceOf(levelCrestStructure); + NormalDistribution levelCrestStructure = heightStructure.LevelCrestStructure; Assert.AreEqual(2, levelCrestStructure.Mean.NumberOfDecimalPlaces); Assert.AreEqual(234.57, levelCrestStructure.Mean.Value); Assert.AreEqual(2, levelCrestStructure.StandardDeviation.NumberOfDecimalPlaces); Assert.AreEqual(0.23, levelCrestStructure.StandardDeviation.Value); - var flowWidthAtBottomProtection = heightStructure.FlowWidthAtBottomProtection; - Assert.IsInstanceOf(flowWidthAtBottomProtection); + LogNormalDistribution flowWidthAtBottomProtection = heightStructure.FlowWidthAtBottomProtection; Assert.AreEqual(2, flowWidthAtBottomProtection.Mean.NumberOfDecimalPlaces); Assert.AreEqual(345.68, flowWidthAtBottomProtection.Mean.Value); Assert.AreEqual(2, flowWidthAtBottomProtection.StandardDeviation.NumberOfDecimalPlaces); Assert.AreEqual(0.35, flowWidthAtBottomProtection.StandardDeviation.Value); - var criticalOvertoppingDischarge = heightStructure.CriticalOvertoppingDischarge; - Assert.IsInstanceOf(criticalOvertoppingDischarge); + VariationCoefficientLogNormalDistribution criticalOvertoppingDischarge = heightStructure.CriticalOvertoppingDischarge; Assert.AreEqual(2, criticalOvertoppingDischarge.Mean.NumberOfDecimalPlaces); Assert.AreEqual(456.79, criticalOvertoppingDischarge.Mean.Value); - Assert.AreEqual(2, criticalOvertoppingDischarge.StandardDeviation.NumberOfDecimalPlaces); - Assert.AreEqual(0.46, criticalOvertoppingDischarge.StandardDeviation.Value); + Assert.AreEqual(2, criticalOvertoppingDischarge.CoefficientOfVariation.NumberOfDecimalPlaces); + Assert.AreEqual(0.46, criticalOvertoppingDischarge.CoefficientOfVariation.Value); - var widthFlowApertures = heightStructure.WidthFlowApertures; - Assert.IsInstanceOf(widthFlowApertures); + VariationCoefficientNormalDistribution widthFlowApertures = heightStructure.WidthFlowApertures; Assert.AreEqual(2, widthFlowApertures.Mean.NumberOfDecimalPlaces); Assert.AreEqual(567.89, widthFlowApertures.Mean.Value); - Assert.AreEqual(2, widthFlowApertures.StandardDeviation.NumberOfDecimalPlaces); - Assert.AreEqual(0.57, widthFlowApertures.StandardDeviation.Value); + Assert.AreEqual(2, widthFlowApertures.CoefficientOfVariation.NumberOfDecimalPlaces); + Assert.AreEqual(0.57, widthFlowApertures.CoefficientOfVariation.Value); Assert.AreEqual(0.67890, heightStructure.FailureProbabilityStructureWithErosion); - var storageStructureArea = heightStructure.StorageStructureArea; - Assert.IsInstanceOf(storageStructureArea); + VariationCoefficientLogNormalDistribution storageStructureArea = heightStructure.StorageStructureArea; Assert.AreEqual(2, storageStructureArea.Mean.NumberOfDecimalPlaces); Assert.AreEqual(112.22, storageStructureArea.Mean.Value); - Assert.AreEqual(2, storageStructureArea.StandardDeviation.NumberOfDecimalPlaces); - Assert.AreEqual(0.11, storageStructureArea.StandardDeviation.Value); + Assert.AreEqual(2, storageStructureArea.CoefficientOfVariation.NumberOfDecimalPlaces); + Assert.AreEqual(0.11, storageStructureArea.CoefficientOfVariation.Value); - var allowedLevelIncreaseStorage = heightStructure.AllowedLevelIncreaseStorage; - Assert.IsInstanceOf(allowedLevelIncreaseStorage); + LogNormalDistribution allowedLevelIncreaseStorage = heightStructure.AllowedLevelIncreaseStorage; Assert.AreEqual(2, allowedLevelIncreaseStorage.Mean.NumberOfDecimalPlaces); Assert.AreEqual(225.34, allowedLevelIncreaseStorage.Mean.Value); Assert.AreEqual(2, allowedLevelIncreaseStorage.StandardDeviation.NumberOfDecimalPlaces); Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresInputTest.cs =================================================================== diff -u -raa56a5d7a6ec9f083ce3bd7a65d0c5b06470fd3b -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresInputTest.cs (.../HeightStructuresInputTest.cs) (revision aa56a5d7a6ec9f083ce3bd7a65d0c5b06470fd3b) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresInputTest.cs (.../HeightStructuresInputTest.cs) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -55,12 +55,12 @@ AssertAreEqual(1.1, input.ModelFactorSuperCriticalFlow.Mean); AssertAreEqual(0.03, input.ModelFactorSuperCriticalFlow.StandardDeviation); AssertAreEqual(0.1, input.AllowedLevelIncreaseStorage.StandardDeviation); - AssertAreEqual(0.1, input.StorageStructureArea.GetVariationCoefficient()); + AssertAreEqual(0.1, input.StorageStructureArea.CoefficientOfVariation); AssertAreEqual(0.05, input.FlowWidthAtBottomProtection.StandardDeviation); - AssertAreEqual(0.15, input.CriticalOvertoppingDischarge.GetVariationCoefficient()); - AssertAreEqual(0.05, input.WidthFlowApertures.StandardDeviation); + AssertAreEqual(0.15, input.CriticalOvertoppingDischarge.CoefficientOfVariation); + AssertAreEqual(0.05, input.WidthFlowApertures.CoefficientOfVariation); AssertAreEqual(6.0, input.StormDuration.Mean); - AssertAreEqual(0.25, input.StormDuration.GetVariationCoefficient()); + AssertAreEqual(0.25, input.StormDuration.CoefficientOfVariation); } [Test] @@ -122,19 +122,19 @@ var input = new HeightStructuresInput(); var random = new Random(22); - RoundedDouble defaultStormDurationStandardDeviation = input.StormDuration.StandardDeviation; - LogNormalDistribution stormDuration = new LogNormalDistribution(5) + RoundedDouble defaultStormDurationCoefficientOfVariation = input.StormDuration.CoefficientOfVariation; + var stormDuration = new VariationCoefficientLogNormalDistribution(5) { Mean = (RoundedDouble) (0.01 + random.NextDouble()), - StandardDeviation = (RoundedDouble) random.NextDouble() + CoefficientOfVariation = (RoundedDouble) random.NextDouble() }; // Call input.StormDuration = stormDuration; // Assert AssertAreEqual(stormDuration.Mean, input.StormDuration.Mean); - AssertAreEqual(defaultStormDurationStandardDeviation, input.StormDuration.StandardDeviation); + AssertAreEqual(defaultStormDurationCoefficientOfVariation, input.StormDuration.CoefficientOfVariation); } [Test] @@ -170,7 +170,7 @@ var input = new HeightStructuresInput(); // Call - input.StructureNormalOrientation = (RoundedDouble)orientation; + input.StructureNormalOrientation = (RoundedDouble) orientation; // Assert Assert.AreEqual(2, input.StructureNormalOrientation.NumberOfDecimalPlaces); @@ -190,7 +190,7 @@ var input = new HeightStructuresInput(); // Call - TestDelegate call = () => input.StructureNormalOrientation = (RoundedDouble)invalidValue; + TestDelegate call = () => input.StructureNormalOrientation = (RoundedDouble) invalidValue; // Assert TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "De waarde voor de oriëntatie moet in het bereik tussen [0, 360] graden liggen."); @@ -224,18 +224,18 @@ var input = new HeightStructuresInput(); var random = new Random(22); - LogNormalDistribution storageStructureArea = new LogNormalDistribution(5) + var storageStructureArea = new VariationCoefficientLogNormalDistribution(5) { Mean = (RoundedDouble) (0.01 + random.NextDouble()), - StandardDeviation = (RoundedDouble) random.NextDouble() + CoefficientOfVariation = (RoundedDouble) random.NextDouble() }; // Call input.StorageStructureArea = storageStructureArea; // Assert AssertAreEqual(storageStructureArea.Mean, input.StorageStructureArea.Mean); - AssertAreEqual(storageStructureArea.StandardDeviation, input.StorageStructureArea.StandardDeviation); + AssertAreEqual(storageStructureArea.CoefficientOfVariation, input.StorageStructureArea.CoefficientOfVariation); } [Test] @@ -266,18 +266,18 @@ var input = new HeightStructuresInput(); var random = new Random(22); - LogNormalDistribution criticalOvertoppingDischarge = new LogNormalDistribution(5) + var criticalOvertoppingDischarge = new VariationCoefficientLogNormalDistribution(5) { Mean = (RoundedDouble) (0.01 + random.NextDouble()), - StandardDeviation = (RoundedDouble) random.NextDouble() + CoefficientOfVariation = (RoundedDouble) random.NextDouble() }; // Call input.CriticalOvertoppingDischarge = criticalOvertoppingDischarge; // Assert AssertAreEqual(criticalOvertoppingDischarge.Mean, input.CriticalOvertoppingDischarge.Mean); - AssertAreEqual(criticalOvertoppingDischarge.StandardDeviation, input.CriticalOvertoppingDischarge.StandardDeviation); + AssertAreEqual(criticalOvertoppingDischarge.CoefficientOfVariation, input.CriticalOvertoppingDischarge.CoefficientOfVariation); } [Test] @@ -319,18 +319,18 @@ var input = new HeightStructuresInput(); var random = new Random(22); - NormalDistribution widthFlowApertures = new NormalDistribution(5) + var widthFlowApertures = new VariationCoefficientNormalDistribution(5) { Mean = (RoundedDouble) random.NextDouble(), - StandardDeviation = (RoundedDouble) random.NextDouble() + CoefficientOfVariation = (RoundedDouble) random.NextDouble() }; // Call input.WidthFlowApertures = widthFlowApertures; // Assert AssertAreEqual(widthFlowApertures.Mean, input.WidthFlowApertures.Mean); - AssertAreEqual(widthFlowApertures.StandardDeviation, input.WidthFlowApertures.StandardDeviation); + AssertAreEqual(widthFlowApertures.CoefficientOfVariation, input.WidthFlowApertures.CoefficientOfVariation); } private static void AssertAreEqual(double expectedValue, RoundedDouble actualValue) Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PropertyClasses/HeightStructurePropertiesTest.cs =================================================================== diff -u -r0d12e759b6e46290d83d04a6a5760fe467b339ab -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PropertyClasses/HeightStructurePropertiesTest.cs (.../HeightStructurePropertiesTest.cs) (revision 0d12e759b6e46290d83d04a6a5760fe467b339ab) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PropertyClasses/HeightStructurePropertiesTest.cs (.../HeightStructurePropertiesTest.cs) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -84,7 +84,7 @@ Assert.AreEqual("Lognormaal", properties.StorageStructureArea.DistributionType); Assert.AreEqual(structure.StorageStructureArea, properties.StorageStructureArea.Data); Assert.IsTrue(properties.StorageStructureArea.DynamicReadOnlyValidationMethod("Mean")); - Assert.IsTrue(properties.StorageStructureArea.DynamicReadOnlyValidationMethod("StandardDeviation")); + Assert.IsTrue(properties.StorageStructureArea.DynamicReadOnlyValidationMethod("CoefficientOfVariation")); Assert.AreEqual("Lognormaal", properties.FlowWidthAtBottomProtection.DistributionType); Assert.AreEqual(structure.FlowWidthAtBottomProtection, properties.FlowWidthAtBottomProtection.Data); @@ -94,12 +94,12 @@ Assert.AreEqual("Normaal", properties.WidthFlowApertures.DistributionType); Assert.AreEqual(structure.WidthFlowApertures, properties.WidthFlowApertures.Data); Assert.IsTrue(properties.WidthFlowApertures.DynamicReadOnlyValidationMethod("Mean")); - Assert.IsTrue(properties.WidthFlowApertures.DynamicReadOnlyValidationMethod("StandardDeviation")); + Assert.IsTrue(properties.WidthFlowApertures.DynamicReadOnlyValidationMethod("CoefficientOfVariation")); Assert.AreEqual("Lognormaal", properties.CriticalOvertoppingDischarge.DistributionType); Assert.AreEqual(structure.CriticalOvertoppingDischarge, properties.CriticalOvertoppingDischarge.Data); Assert.IsTrue(properties.CriticalOvertoppingDischarge.DynamicReadOnlyValidationMethod("Mean")); - Assert.IsTrue(properties.CriticalOvertoppingDischarge.DynamicReadOnlyValidationMethod("StandardDeviation")); + Assert.IsTrue(properties.CriticalOvertoppingDischarge.DynamicReadOnlyValidationMethod("CoefficientOfVariation")); Assert.AreEqual(structure.FailureProbabilityStructureWithErosion, properties.FailureProbabilityStructureWithErosion); } Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresInputContextPropertiesTest.cs =================================================================== diff -u -r0a6fd2fa18908a63fc029833ea3735709ebd5829 -r9050ad5f3a80e630b2fcc092942a40d6343286a0 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresInputContextPropertiesTest.cs (.../HeightStructuresInputContextPropertiesTest.cs) (revision 0a6fd2fa18908a63fc029833ea3735709ebd5829) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresInputContextPropertiesTest.cs (.../HeightStructuresInputContextPropertiesTest.cs) (revision 9050ad5f3a80e630b2fcc092942a40d6343286a0) @@ -32,6 +32,7 @@ using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Probabilistics; using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.HeightStructures.Data; @@ -530,12 +531,18 @@ 225.336, 0.22533); } - private static void AssertDistributionProperties(DistributionProperties expected, DistributionProperties actual) + private static void AssertDistributionProperties(DistributionPropertiesBase expected, DistributionPropertiesBase actual) where T : IDistribution { Assert.AreEqual(expected.DistributionType, actual.DistributionType); Assert.AreEqual(expected.Data, actual.Data); } + private static void AssertDistributionProperties(VariationCoefficientDistributionPropertiesBase expected, VariationCoefficientDistributionPropertiesBase actual) where T : IVariationCoefficientDistribution + { + Assert.AreEqual(expected.DistributionType, actual.DistributionType); + Assert.AreEqual(expected.Data, actual.Data); + } + private static void AssertLogNormalDistributionVariationProperties(LogNormalDistributionVariationProperties expected, LogNormalDistributionVariationProperties actual) {