From 0477be835bd39e376e8d9a9ee9da25e4797d4d3a Mon Sep 17 00:00:00 2001 From: jvangael Date: Fri, 17 Jul 2009 16:06:33 +0800 Subject: [PATCH] Fix the message shown in the AssertHelpers.AlmostEqual function. Signed-off-by: Christoph Ruegg --- src/Managed.UnitTests/AssertHelpers.cs | 54 +++++++++++++++++++ .../Continuous/NormalTests.cs | 2 +- src/Native/Native.csproj | 3 ++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/Managed.UnitTests/AssertHelpers.cs diff --git a/src/Managed.UnitTests/AssertHelpers.cs b/src/Managed.UnitTests/AssertHelpers.cs new file mode 100644 index 00000000..8729e478 --- /dev/null +++ b/src/Managed.UnitTests/AssertHelpers.cs @@ -0,0 +1,54 @@ +// +// Math.NET Numerics, part of the Math.NET Project +// http://mathnet.opensourcedotnet.info +// +// Copyright (c) 2009 Math.NET +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// + +namespace MathNet.Numerics.UnitTests +{ + using MbUnit.Framework; + + /// + /// A class which includes some assertion helper methods particularly for numerical code. + /// + class AssertHelpers + { + /// + /// Asserts that the expected value and the actual value are equal up to a certain number of decimal places. + /// + /// The expected value. + /// The actual value. + /// The number of decimal places to agree on. + public static void AlmostEqual(double expected, double actual, int decimalPlaces) + { + bool pass = Precision.AlmostEqualInDecimalPlaces(expected, actual, decimalPlaces); + if (!pass) + { + //signals Gallio that the test failed. + Assert.Fail("Not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected, actual); + } + } + } +} diff --git a/src/Managed.UnitTests/DistributionTests/Continuous/NormalTests.cs b/src/Managed.UnitTests/DistributionTests/Continuous/NormalTests.cs index 782bda14..55e1d1a5 100644 --- a/src/Managed.UnitTests/DistributionTests/Continuous/NormalTests.cs +++ b/src/Managed.UnitTests/DistributionTests/Continuous/NormalTests.cs @@ -391,7 +391,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests public void ValidateInverseCumulativeDistribution(double x, double f) { var n = Normal.WithMeanStdDev(5.0, 2.0); - AssertHelpers.AlmostEqual(x, n.InverseCumulativeDistribution(f), 10); + AssertHelpers.AlmostEqual(x, n.InverseCumulativeDistribution(f), 15); } } } diff --git a/src/Native/Native.csproj b/src/Native/Native.csproj index 8dfd01a8..e9e068f9 100644 --- a/src/Native/Native.csproj +++ b/src/Native/Native.csproj @@ -65,6 +65,9 @@ Distributions\IDistribution.cs + + Precision.cs + Properties\Resources.Designer.cs