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. ///