From a1625a54104da7872c15618db9e68656c6f6ec2a Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Fri, 8 Feb 2008 17:54:30 +0000 Subject: * Applying mantis 339 patches round 2 -- Thanks daedius --- .../Tests/Common/ANumericalToleranceConstraint.cs | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 OpenSim/Tests/Common/ANumericalToleranceConstraint.cs (limited to 'OpenSim/Tests/Common/ANumericalToleranceConstraint.cs') diff --git a/OpenSim/Tests/Common/ANumericalToleranceConstraint.cs b/OpenSim/Tests/Common/ANumericalToleranceConstraint.cs new file mode 100644 index 0000000..289e4bb --- /dev/null +++ b/OpenSim/Tests/Common/ANumericalToleranceConstraint.cs @@ -0,0 +1,30 @@ +using System; +using NUnit.Framework.Constraints; + +namespace OpenSim.Tests.Common +{ + public abstract class ANumericalToleranceConstraint : Constraint + { + protected double _tolerance; + + public ANumericalToleranceConstraint(double tolerance) + { + if (tolerance < 0) + { + throw new ArgumentException("Tolerance cannot be negative."); + } + _tolerance = tolerance; + } + + + protected bool IsWithinDoubleConstraint(double doubleValue, double baseValue) + { + if (doubleValue >= baseValue - _tolerance && doubleValue <= baseValue + _tolerance) + { + return true; + } + + return false; + } + } +} -- cgit v1.1