Beispiel #1
0
        public void ThrowsOnNullData()
        {
            double[] data = null;

            // ReSharper disable InvokeAsExtensionMethod
            Assert.That(() => Statistics.Minimum(data), Throws.Exception);
            Assert.That(() => Statistics.Maximum(data), Throws.Exception);
            Assert.That(() => Statistics.Mean(data), Throws.Exception);
            Assert.That(() => Statistics.Median(data), Throws.Exception);
            Assert.That(() => Statistics.Quantile(data, 0.3), Throws.Exception);
            Assert.That(() => Statistics.Variance(data), Throws.Exception);
            Assert.That(() => Statistics.StandardDeviation(data), Throws.Exception);
            Assert.That(() => Statistics.PopulationVariance(data), Throws.Exception);
            Assert.That(() => Statistics.PopulationStandardDeviation(data), Throws.Exception);
            Assert.That(() => Statistics.Covariance(data, data), Throws.Exception);
            Assert.That(() => Statistics.PopulationCovariance(data, data), Throws.Exception);
            // ReSharper restore InvokeAsExtensionMethod

            Assert.That(() => SortedArrayStatistics.Minimum(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => SortedArrayStatistics.Minimum(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => SortedArrayStatistics.Maximum(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => SortedArrayStatistics.OrderStatistic(data, 1), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => SortedArrayStatistics.Median(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => SortedArrayStatistics.LowerQuartile(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => SortedArrayStatistics.UpperQuartile(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => SortedArrayStatistics.Percentile(data, 30), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => SortedArrayStatistics.Quantile(data, 0.3), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => SortedArrayStatistics.QuantileCustom(data, 0.3, 0, 0, 1, 0), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => SortedArrayStatistics.QuantileCustom(data, 0.3, QuantileDefinition.Nearest), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => SortedArrayStatistics.InterquartileRange(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => SortedArrayStatistics.FiveNumberSummary(data), Throws.Exception.TypeOf <NullReferenceException>());

            Assert.That(() => ArrayStatistics.Minimum(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => ArrayStatistics.Maximum(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => ArrayStatistics.OrderStatisticInplace(data, 1), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => ArrayStatistics.Mean(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => ArrayStatistics.Variance(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => ArrayStatistics.StandardDeviation(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => ArrayStatistics.PopulationVariance(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => ArrayStatistics.PopulationStandardDeviation(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => ArrayStatistics.Covariance(data, data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => ArrayStatistics.PopulationCovariance(data, data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => ArrayStatistics.MedianInplace(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => ArrayStatistics.QuantileInplace(data, 0.3), Throws.Exception.TypeOf <NullReferenceException>());

            Assert.That(() => StreamingStatistics.Minimum(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => StreamingStatistics.Maximum(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => StreamingStatistics.Mean(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => StreamingStatistics.Variance(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => StreamingStatistics.StandardDeviation(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => StreamingStatistics.PopulationVariance(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => StreamingStatistics.PopulationStandardDeviation(data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => StreamingStatistics.Covariance(data, data), Throws.Exception.TypeOf <NullReferenceException>());
            Assert.That(() => StreamingStatistics.PopulationCovariance(data, data), Throws.Exception.TypeOf <NullReferenceException>());
        }
Beispiel #2
0
        public void ThrowsOnNullData()
        {
            double[] data = null;

            Assert.Throws <ArgumentNullException>(() => Statistics.Minimum(data));
            Assert.Throws <ArgumentNullException>(() => Statistics.Maximum(data));
            Assert.Throws <ArgumentNullException>(() => Statistics.Mean(data));
            Assert.Throws <ArgumentNullException>(() => Statistics.Median(data));
            Assert.Throws <ArgumentNullException>(() => Statistics.Quantile(data, 0.3));
            Assert.Throws <ArgumentNullException>(() => Statistics.Variance(data));
            Assert.Throws <ArgumentNullException>(() => Statistics.StandardDeviation(data));
            Assert.Throws <ArgumentNullException>(() => Statistics.PopulationVariance(data));
            Assert.Throws <ArgumentNullException>(() => Statistics.PopulationStandardDeviation(data));
            Assert.Throws <ArgumentNullException>(() => Statistics.Covariance(data, data));
            Assert.Throws <ArgumentNullException>(() => Statistics.PopulationCovariance(data, data));

            Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.Minimum(data));
            Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.Maximum(data));
            Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.OrderStatistic(data, 1));
            Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.Median(data));
            Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.LowerQuartile(data));
            Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.UpperQuartile(data));
            Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.Percentile(data, 30));
            Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.Quantile(data, 0.3));
            Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.QuantileCustom(data, 0.3, 0, 0, 1, 0));
            Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.QuantileCustom(data, 0.3, QuantileDefinition.Nearest));
            Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.InterquartileRange(data));
            Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.FiveNumberSummary(data));

            Assert.Throws <ArgumentNullException>(() => ArrayStatistics.Minimum(data));
            Assert.Throws <ArgumentNullException>(() => ArrayStatistics.Maximum(data));
            Assert.Throws <ArgumentNullException>(() => ArrayStatistics.OrderStatisticInplace(data, 1));
            Assert.Throws <ArgumentNullException>(() => ArrayStatistics.Mean(data));
            Assert.Throws <ArgumentNullException>(() => ArrayStatistics.Variance(data));
            Assert.Throws <ArgumentNullException>(() => ArrayStatistics.StandardDeviation(data));
            Assert.Throws <ArgumentNullException>(() => ArrayStatistics.PopulationVariance(data));
            Assert.Throws <ArgumentNullException>(() => ArrayStatistics.PopulationStandardDeviation(data));
            Assert.Throws <ArgumentNullException>(() => ArrayStatistics.Covariance(data, data));
            Assert.Throws <ArgumentNullException>(() => ArrayStatistics.PopulationCovariance(data, data));
            Assert.Throws <ArgumentNullException>(() => ArrayStatistics.MedianInplace(data));
            Assert.Throws <ArgumentNullException>(() => ArrayStatistics.QuantileInplace(data, 0.3));

            Assert.Throws <ArgumentNullException>(() => StreamingStatistics.Minimum(data));
            Assert.Throws <ArgumentNullException>(() => StreamingStatistics.Maximum(data));
            Assert.Throws <ArgumentNullException>(() => StreamingStatistics.Mean(data));
            Assert.Throws <ArgumentNullException>(() => StreamingStatistics.Variance(data));
            Assert.Throws <ArgumentNullException>(() => StreamingStatistics.StandardDeviation(data));
            Assert.Throws <ArgumentNullException>(() => StreamingStatistics.PopulationVariance(data));
            Assert.Throws <ArgumentNullException>(() => StreamingStatistics.PopulationStandardDeviation(data));
            Assert.Throws <ArgumentNullException>(() => StreamingStatistics.Covariance(data, data));
            Assert.Throws <ArgumentNullException>(() => StreamingStatistics.PopulationCovariance(data, data));
        }
Beispiel #3
0
        public void DoesNotThrowOnEmptyData()
        {
            double[] data = new double[0];

            Assert.DoesNotThrow(() => Statistics.Minimum(data));
            Assert.DoesNotThrow(() => Statistics.Maximum(data));
            Assert.DoesNotThrow(() => Statistics.Mean(data));
            Assert.DoesNotThrow(() => Statistics.Median(data));
            Assert.DoesNotThrow(() => Statistics.Quantile(data, 0.3));
            Assert.DoesNotThrow(() => Statistics.Variance(data));
            Assert.DoesNotThrow(() => Statistics.StandardDeviation(data));
            Assert.DoesNotThrow(() => Statistics.PopulationVariance(data));
            Assert.DoesNotThrow(() => Statistics.PopulationStandardDeviation(data));

            Assert.DoesNotThrow(() => SortedArrayStatistics.Minimum(data));
            Assert.DoesNotThrow(() => SortedArrayStatistics.Maximum(data));
            Assert.DoesNotThrow(() => SortedArrayStatistics.OrderStatistic(data, 1));
            Assert.DoesNotThrow(() => SortedArrayStatistics.Median(data));
            Assert.DoesNotThrow(() => SortedArrayStatistics.LowerQuartile(data));
            Assert.DoesNotThrow(() => SortedArrayStatistics.UpperQuartile(data));
            Assert.DoesNotThrow(() => SortedArrayStatistics.Percentile(data, 30));
            Assert.DoesNotThrow(() => SortedArrayStatistics.Quantile(data, 0.3));
            Assert.DoesNotThrow(() => SortedArrayStatistics.QuantileCustom(data, 0.3, 0, 0, 1, 0));
            Assert.DoesNotThrow(() => SortedArrayStatistics.QuantileCustom(data, 0.3, QuantileDefinition.Nearest));
            Assert.DoesNotThrow(() => SortedArrayStatistics.InterquartileRange(data));
            Assert.DoesNotThrow(() => SortedArrayStatistics.FiveNumberSummary(data));

            Assert.DoesNotThrow(() => ArrayStatistics.Minimum(data));
            Assert.DoesNotThrow(() => ArrayStatistics.Maximum(data));
            Assert.DoesNotThrow(() => ArrayStatistics.OrderStatisticInplace(data, 1));
            Assert.DoesNotThrow(() => ArrayStatistics.Mean(data));
            Assert.DoesNotThrow(() => ArrayStatistics.Variance(data));
            Assert.DoesNotThrow(() => ArrayStatistics.StandardDeviation(data));
            Assert.DoesNotThrow(() => ArrayStatistics.PopulationVariance(data));
            Assert.DoesNotThrow(() => ArrayStatistics.PopulationStandardDeviation(data));
            Assert.DoesNotThrow(() => ArrayStatistics.MedianInplace(data));
            Assert.DoesNotThrow(() => ArrayStatistics.QuantileInplace(data, 0.3));

            Assert.DoesNotThrow(() => StreamingStatistics.Minimum(data));
            Assert.DoesNotThrow(() => StreamingStatistics.Maximum(data));
            Assert.DoesNotThrow(() => StreamingStatistics.Mean(data));
            Assert.DoesNotThrow(() => StreamingStatistics.Variance(data));
            Assert.DoesNotThrow(() => StreamingStatistics.StandardDeviation(data));
            Assert.DoesNotThrow(() => StreamingStatistics.PopulationVariance(data));
            Assert.DoesNotThrow(() => StreamingStatistics.PopulationStandardDeviation(data));
        }
Beispiel #4
0
        public void OrderStatisticsOnShortSequence()
        {
            // -3 -1 -0.5 0  1  4 5 6 10
            var samples = new[] { -1, 5, 0, -3, 10, -0.5, 4, 1, 6 };

            var f = Statistics.OrderStatisticFunc(samples);

            Assert.That(f(0), Is.NaN, "Order-0 (bad)");
            Assert.That(f(1), Is.EqualTo(-3), "Order-1");
            Assert.That(f(2), Is.EqualTo(-1), "Order-2");
            Assert.That(f(3), Is.EqualTo(-0.5), "Order-3");
            Assert.That(f(7), Is.EqualTo(5), "Order-7");
            Assert.That(f(8), Is.EqualTo(6), "Order-8");
            Assert.That(f(9), Is.EqualTo(10), "Order-9");
            Assert.That(f(10), Is.NaN, "Order-10 (bad)");

            Assert.That(Statistics.OrderStatistic(samples, 0), Is.NaN, "Order-0 (bad)");
            Assert.That(Statistics.OrderStatistic(samples, 1), Is.EqualTo(-3), "Order-1");
            Assert.That(Statistics.OrderStatistic(samples, 2), Is.EqualTo(-1), "Order-2");
            Assert.That(Statistics.OrderStatistic(samples, 3), Is.EqualTo(-0.5), "Order-3");
            Assert.That(Statistics.OrderStatistic(samples, 7), Is.EqualTo(5), "Order-7");
            Assert.That(Statistics.OrderStatistic(samples, 8), Is.EqualTo(6), "Order-8");
            Assert.That(Statistics.OrderStatistic(samples, 9), Is.EqualTo(10), "Order-9");
            Assert.That(Statistics.OrderStatistic(samples, 10), Is.NaN, "Order-10 (bad)");

            Assert.That(ArrayStatistics.OrderStatisticInplace(samples, 0), Is.NaN, "Order-0 (bad)");
            Assert.That(ArrayStatistics.OrderStatisticInplace(samples, 1), Is.EqualTo(-3), "Order-1");
            Assert.That(ArrayStatistics.OrderStatisticInplace(samples, 2), Is.EqualTo(-1), "Order-2");
            Assert.That(ArrayStatistics.OrderStatisticInplace(samples, 3), Is.EqualTo(-0.5), "Order-3");
            Assert.That(ArrayStatistics.OrderStatisticInplace(samples, 7), Is.EqualTo(5), "Order-7");
            Assert.That(ArrayStatistics.OrderStatisticInplace(samples, 8), Is.EqualTo(6), "Order-8");
            Assert.That(ArrayStatistics.OrderStatisticInplace(samples, 9), Is.EqualTo(10), "Order-9");
            Assert.That(ArrayStatistics.OrderStatisticInplace(samples, 10), Is.NaN, "Order-10 (bad)");

            Array.Sort(samples);
            Assert.That(SortedArrayStatistics.OrderStatistic(samples, 0), Is.NaN, "Order-0 (bad)");
            Assert.That(SortedArrayStatistics.OrderStatistic(samples, 1), Is.EqualTo(-3), "Order-1");
            Assert.That(SortedArrayStatistics.OrderStatistic(samples, 2), Is.EqualTo(-1), "Order-2");
            Assert.That(SortedArrayStatistics.OrderStatistic(samples, 3), Is.EqualTo(-0.5), "Order-3");
            Assert.That(SortedArrayStatistics.OrderStatistic(samples, 7), Is.EqualTo(5), "Order-7");
            Assert.That(SortedArrayStatistics.OrderStatistic(samples, 8), Is.EqualTo(6), "Order-8");
            Assert.That(SortedArrayStatistics.OrderStatistic(samples, 9), Is.EqualTo(10), "Order-9");
            Assert.That(SortedArrayStatistics.OrderStatistic(samples, 10), Is.NaN, "Order-10 (bad)");
        }