From 7c0d009b46057050172b63e4f3713610a6361d24 Mon Sep 17 00:00:00 2001 From: David Prince Date: Fri, 27 Dec 2013 20:27:42 +0800 Subject: [PATCH] ValidateMean unit test for Categorical dist Unit tests to validate Categorical.Mean. Currently they fail, indicating that Categorical.Mean is not correctly implemented. Unit tests for StdDev, Variance, Entropy, and Median properties are still required. --- .../Discrete/CategoricalTests.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/UnitTests/DistributionTests/Discrete/CategoricalTests.cs b/src/UnitTests/DistributionTests/Discrete/CategoricalTests.cs index 34cb76b1..67d2e9e4 100644 --- a/src/UnitTests/DistributionTests/Discrete/CategoricalTests.cs +++ b/src/UnitTests/DistributionTests/Discrete/CategoricalTests.cs @@ -155,6 +155,22 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete Assert.Throws(() => b.P = _badP); } + /// + /// Validate mean. + /// + /// An array of nonnegative ratios. + /// Expected value. + [TestCase(new double[] { 0, 0.25, 0.5, 0.25 }, 2)] + [TestCase(new double[] { 0, 1, 2, 1 }, 2)] + [TestCase(new double[] { 0, 0.5, 0.5 }, 1.5)] + [TestCase(new double[] { 0.75, 0.25 }, 0.25)] + [TestCase(new double[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 5)] + public void ValidateMean(double[] p, double mean) + { + var n = new Categorical(p); + AssertHelpers.AlmostEqual(mean, n.Mean, 14); + } + /// /// Can sample static. ///