예제 #1
0
 /// <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);
 }
예제 #2
0
        /// <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);
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
 /// <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));
 }
예제 #5
0
 /// <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));
 }
예제 #6
0
        /// <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);
        }
예제 #7
0
        /// <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
            });
        }
예제 #8
0
        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);
        }
예제 #9
0
        /// <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)
            });
        }
예제 #10
0
        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);
        }
예제 #11
0
 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);
 }
예제 #13
0
 /// <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());
 }
예제 #14
0
 private static int GetNumberOfDecimals(IVariationCoefficientDistribution distribution)
 {
     return(distribution.Mean.NumberOfDecimalPlaces);
 }