diff --git a/src/Numerics/Distributions/Multivariate/NormalGamma.cs b/src/Numerics/Distributions/Multivariate/NormalGamma.cs index eff86d00..73b3adf8 100644 --- a/src/Numerics/Distributions/Multivariate/NormalGamma.cs +++ b/src/Numerics/Distributions/Multivariate/NormalGamma.cs @@ -183,6 +183,7 @@ namespace MathNet.Numerics.Distributions public double MeanLocation { get { return _meanLocation; } + set { SetParameters(value, _meanScale, _precisionShape, _precisionInvScale); } } /// @@ -191,6 +192,7 @@ namespace MathNet.Numerics.Distributions public double MeanScale { get { return _meanScale; } + set { SetParameters(_meanLocation, value, _precisionShape, _precisionInvScale); } } /// diff --git a/src/UnitTests/DistributionTests/Multivariate/NormalGammaTests.cs b/src/UnitTests/DistributionTests/Multivariate/NormalGammaTests.cs index 84ffbed9..c38895db 100644 --- a/src/UnitTests/DistributionTests/Multivariate/NormalGammaTests.cs +++ b/src/UnitTests/DistributionTests/Multivariate/NormalGammaTests.cs @@ -37,14 +37,16 @@ namespace MathNet.Numerics.UnitTests.DistributionTests public class NormalGammaTests { [Test, MultipleAsserts] - public void NormalGammaTest() + [Row(0.0, 1.0, 1.0, 1.0)] + [Row(10.0, 1.0, 2.0, 2.0)] + public void CanCreateNormalGamma(double meanLocation, double meanScale, double precShape, double precInvScale) { - NormalGamma ng = new NormalGamma(10.0, 1.0, 2.0, 2.0); + NormalGamma ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); - AssertEx.AreEqual(10.0, ng.MeanLocation); - AssertEx.AreEqual(1.0, ng.MeanScale); - AssertEx.AreEqual(2.0, ng.PrecisionShape); - AssertEx.AreEqual(2.0, ng.PrecisionInverseScale); + AssertEx.AreEqual(meanLocation, ng.MeanLocation); + AssertEx.AreEqual(meanScale, ng.MeanScale); + AssertEx.AreEqual(precShape, ng.PrecisionShape); + AssertEx.AreEqual(precInvScale, ng.PrecisionInverseScale); } [Test] @@ -52,9 +54,54 @@ namespace MathNet.Numerics.UnitTests.DistributionTests [Row(1.0, 1.0, -1.0, 1.0)] [Row(1.0, 1.0, 1.0, -1.0)] [ExpectedException(typeof(ArgumentOutOfRangeException))] - public void InvalidParams(double a, double b, double c, double d) + public void NormalGammaConstructorFailsWithInvalidParams(double meanLocation, double meanScale, double precShape, double precInvScale) { - var nb = new NormalGamma(a, b, c, d); + var nb = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); + } + + [Test] + [Row(0.0, 1.0, 1.0, 1.0)] + [Row(10.0, 1.0, 2.0, 2.0)] + public void CanGetMeanLocation(double meanLocation, double meanScale, double precShape, double precInvScale) + { + NormalGamma ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); + AssertEx.AreEqual(meanLocation, ng.MeanLocation); + } + + [Test, MultipleAsserts] + [Row(0.0, 1.0, 1.0, 1.0)] + [Row(10.0, 1.0, 2.0, 2.0)] + public void CanSetMeanLocation(double meanLocation, double meanScale, double precShape, double precInvScale) + { + NormalGamma ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); + ng.MeanLocation = -5.0; + + AssertEx.AreEqual(-5.0, ng.MeanLocation); + AssertEx.AreEqual(meanScale, ng.MeanScale); + AssertEx.AreEqual(precShape, ng.PrecisionShape); + AssertEx.AreEqual(precInvScale, ng.PrecisionInverseScale); + } + + [Test] + [Row(0.0, 1.0, 1.0, 1.0)] + [Row(10.0, 1.0, 2.0, 2.0)] + public void CanGetMeanScale(double meanLocation, double meanScale, double precShape, double precInvScale) + { + NormalGamma ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); + AssertEx.AreEqual(meanScale, ng.MeanScale); + } + + [Test, MultipleAsserts] + [Row(0.0, 1.0, 1.0, 1.0)] + [Row(10.0, 1.0, 2.0, 2.0)] + public void CanSetMeanScale(double meanLocation, double meanScale, double precShape, double precInvScale) + { + NormalGamma ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); + ng.MeanScale = 5.0; + AssertEx.AreEqual(meanLocation, ng.MeanLocation); + AssertEx.AreEqual(5.0, ng.MeanScale); + AssertEx.AreEqual(precShape, ng.PrecisionShape); + AssertEx.AreEqual(precInvScale, ng.PrecisionInverseScale); } } } \ No newline at end of file