/// <summary> /// Asserts whether the values of a distribution are correctly set /// to another distribution. /// </summary> /// <param name="distributionToAssert">The distribution to assert.</param> /// <param name="setDistribution">The distribution which was used to set the properties.</param> /// <param name="expectedDistribution">The expected distribution.</param> /// <exception cref="AssertionException">Thrown when: /// <list type="bullet"> /// <item>The <paramref name="distributionToAssert"/> and <paramref name="setDistribution"/> /// are the same reference.</item> /// <item>The values of the <paramref name="setDistribution"/> do not match with the /// <paramref name="expectedDistribution"/>.</item> /// </list></exception> public static void AssertDistributionCorrectlySet(IVariationCoefficientDistribution distributionToAssert, IVariationCoefficientDistribution setDistribution, IVariationCoefficientDistribution expectedDistribution) { Assert.AreNotSame(setDistribution, distributionToAssert); DistributionAssert.AreEqual(expectedDistribution, distributionToAssert); }
/// <summary> /// Determines if the properties of the actual <see cref="IVariationCoefficientDistribution"/> are the same as /// the expected <see cref="IVariationCoefficientDistribution"/>. /// </summary> /// <param name="expectedDistribution">The expected <see cref="IVariationCoefficientDistribution"/>.</param> /// <param name="actualDistribution">The actual <see cref="IVariationCoefficientDistribution"/>.</param> /// <exception cref="AssertionException">Thrown when the following differences are found between /// the <paramref name="expectedDistribution"/> and <paramref name="actualDistribution"/>: /// <list type="bullet"> /// <item>The probabilistic distribution types.</item> /// <item>The values for the mean and/or the variation.</item> /// <item>The precision for the mean and/or the variation.</item> /// </list></exception> public static void AreEqual(IVariationCoefficientDistribution expectedDistribution, IVariationCoefficientDistribution actualDistribution) { Assert.AreEqual(expectedDistribution.GetType(), actualDistribution.GetType()); AreEqualValue(expectedDistribution.Mean, actualDistribution.Mean); AreEqualValue(expectedDistribution.CoefficientOfVariation, actualDistribution.CoefficientOfVariation); }
/// <summary> /// Attempts to set <see cref="IVariationCoefficientDistribution.CoefficientOfVariation"/>. /// </summary> /// <param name="distribution">The <see cref="IVariationCoefficientDistribution"/> to be updated.</param> /// <param name="variationCoefficient">The new value for <see cref="IVariationCoefficientDistribution.CoefficientOfVariation"/>.</param> /// <param name="stochastName">The descriptive name of <paramref name="distribution"/>.</param> /// <param name="calculationName">The name of the calculation to which <paramref name="distribution"/> /// is associated.</param> /// <returns><c>true</c> if setting <see cref="IVariationCoefficientDistribution.CoefficientOfVariation"/> /// was successful, <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="distribution"/> /// is <c>null</c>.</exception> public static bool TrySetVariationCoefficient(this IVariationCoefficientDistribution distribution, double?variationCoefficient, string stochastName, string calculationName) { if (distribution == null) { throw new ArgumentNullException(nameof(distribution)); } if (variationCoefficient.HasValue) { try { distribution.CoefficientOfVariation = (RoundedDouble)variationCoefficient.Value; } catch (ArgumentOutOfRangeException e) { string errorMessage = string.Format( Resources.IVariationCoefficientDistributionExtensions_TrySetVariationCoefficient_VariationCoefficient_0_is_invalid_for_Stochast_1_, variationCoefficient, stochastName); LogOutOfRangeException(errorMessage, calculationName, e); return(false); } } return(true); }
/// <summary> /// Attempts to set the parameters of an <see cref="IVariationCoefficientDistribution"/>. /// </summary> /// <param name="distribution">The <see cref="IVariationCoefficientDistribution"/> to be updated.</param> /// <param name="configuration">The configuration containing the new values for /// <see cref="IVariationCoefficientDistribution.Mean"/> and <see cref="IVariationCoefficientDistribution.CoefficientOfVariation"/>.</param> /// <param name="stochastName">The descriptive name of <paramref name="distribution"/>.</param> /// <param name="calculationName">The name of the calculation to which <paramref name="distribution"/> /// is associated.</param> /// <returns><c>true</c> if setting all properties was successful, <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="distribution"/> /// is <c>null</c>.</exception> public static bool TrySetDistributionProperties(this IVariationCoefficientDistribution distribution, StochastConfiguration configuration, string stochastName, string calculationName) { return(distribution.TrySetMean(configuration.Mean, stochastName, calculationName) && distribution.TrySetVariationCoefficient(configuration.VariationCoefficient, stochastName, calculationName)); }
/// <summary> /// Attempts to set the parameters of an <see cref="IVariationCoefficientDistribution"/>. /// </summary> /// <param name="distribution">The <see cref="IVariationCoefficientDistribution"/> to be updated.</param> /// <param name="mean">The new value for <see cref="IVariationCoefficientDistribution.Mean"/>.</param> /// <param name="variationCoefficient">The new value for <see cref="IVariationCoefficientDistribution.CoefficientOfVariation"/>.</param> /// <param name="stochastName">The descriptive name of <paramref name="distribution"/>.</param> /// <param name="calculationName">The name of the calculation to which <paramref name="distribution"/> /// is associated.</param> /// <returns><c>true</c> if setting all properties was successful, <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="distribution"/> /// is <c>null</c>.</exception> public static bool TrySetDistributionProperties(this IVariationCoefficientDistribution distribution, double?mean, double?variationCoefficient, string stochastName, string calculationName) { return(distribution.TrySetMean(mean, stochastName, calculationName) && distribution.TrySetVariationCoefficient(variationCoefficient, stochastName, calculationName)); }
/// <summary> /// Indicator whether the <paramref name="pop"/> is valid. /// </summary> /// <param name="pop">The pop to validate.</param> /// <returns><c>true</c> when has no <see cref="RoundedDouble.NaN"/> values; <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="pop"/> is <c>null</c>.</exception> public static bool HasValidPop(IVariationCoefficientDistribution pop) { if (pop == null) { throw new ArgumentNullException(nameof(pop)); } return(pop.Mean != RoundedDouble.NaN && pop.CoefficientOfVariation != RoundedDouble.NaN); }
/// <summary> /// Configure a new <see cref="StochastConfiguration"/> with /// <see cref="StochastConfiguration.Mean"/> taken from /// <paramref name="distribution"/>. /// </summary> /// <param name="distribution">The distribution to take the values from.</param> /// <returns>A new <see cref="StochastConfiguration"/> with /// <see cref="StochastConfiguration.Mean"/> set.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="distribution"/> is <c>null</c>.</exception> public static StochastConfiguration ToStochastConfigurationWithMean(this IVariationCoefficientDistribution distribution) { if (distribution == null) { throw new ArgumentNullException(nameof(distribution)); } return(new StochastConfiguration { Mean = distribution.Mean }); }
public void ToStochastConfigurationWithVariationCoefficient_DistributionNull_ThrowsArgumentNullException() { // Setup IVariationCoefficientDistribution distribution = null; // Call TestDelegate test = () => distribution.ToStochastConfigurationWithVariationCoefficient(); // Assert var exception = Assert.Throws <ArgumentNullException>(test); Assert.AreEqual("distribution", exception.ParamName); }
/// <summary> /// Creates a new instance of <see cref="PersistableStochasticParameter"/>. /// </summary> /// <param name="distribution">The distribution to create the /// <see cref="PersistableStochasticParameter"/> for.</param> /// <param name="isProbabilistic">Indicator whether the /// <see cref="PersistableStochasticParameter"/> is probabilistic.</param> /// <returns>The created <see cref="PersistableStochasticParameter"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="distribution"/> /// is <c>null</c>.</exception> /// <remarks><paramref name="isProbabilistic"/> is default set to <c>true</c>.</remarks> public static PersistableStochasticParameter Create(IVariationCoefficientDistribution distribution, bool isProbabilistic = true) { if (distribution == null) { throw new ArgumentNullException(nameof(distribution)); } return(new PersistableStochasticParameter { IsProbabilistic = isProbabilistic, Mean = distribution.Mean, StandardDeviation = GetStandardDeviation(distribution) }); }
public void TrySetVariationCoefficient_VariationCoefficientDistributionNull_ThrownArgumentNullException() { // Setup IVariationCoefficientDistribution distribution = null; const double mean = 1.1; // Call TestDelegate call = () => distribution.TrySetVariationCoefficient(mean, "A", "B"); // Assert string paramName = Assert.Throws <ArgumentNullException>(call).ParamName; Assert.AreEqual("distribution", paramName); }
private static double GetStandardDeviation(IVariationCoefficientDistribution distribution) { return(distribution.Mean * distribution.CoefficientOfVariation); }
/// <summary> /// Asserts whether the <see cref="PersistableStochasticParameter"/> contains the data /// that is representative for the <paramref name="distribution"/>. /// </summary> /// <param name="distribution">The distribution that contains the original data.</param> /// <param name="stochasticParameter">The <see cref="PersistableStochasticParameter"/> /// that needs to be asserted.</param> /// <param name="expectedIsProbabilistic">The expected value for <see cref="PersistableStochasticParameter.IsProbabilistic"/>.</param> /// <exception cref="AssertionException">Thrown when the data in <paramref name="stochasticParameter"/> /// is not correct.</exception> public static void AssertStochasticParameter(IVariationCoefficientDistribution distribution, PersistableStochasticParameter stochasticParameter, bool expectedIsProbabilistic = true) { Assert.AreEqual(distribution.Mean.Value, stochasticParameter.Mean); Assert.AreEqual(distribution.Mean * distribution.CoefficientOfVariation, stochasticParameter.StandardDeviation); Assert.AreEqual(expectedIsProbabilistic, stochasticParameter.IsProbabilistic); }
/// <summary> /// Gets the accuracy for a <see cref="IVariationCoefficientDistribution"/>. /// </summary> /// <remarks>Assumes that all the parameters of the distribution share the same accuracy.</remarks> public static double GetAccuracy(this IVariationCoefficientDistribution distribution) { return(distribution.Mean.GetAccuracy()); }
private static int GetNumberOfDecimals(IVariationCoefficientDistribution distribution) { return(distribution.Mean.NumberOfDecimalPlaces); }