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 --- OpenSim/Tests/Common/DoubleToleranceConstraint.cs | 52 +++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 OpenSim/Tests/Common/DoubleToleranceConstraint.cs (limited to 'OpenSim/Tests/Common/DoubleToleranceConstraint.cs') diff --git a/OpenSim/Tests/Common/DoubleToleranceConstraint.cs b/OpenSim/Tests/Common/DoubleToleranceConstraint.cs new file mode 100644 index 0000000..f3da236 --- /dev/null +++ b/OpenSim/Tests/Common/DoubleToleranceConstraint.cs @@ -0,0 +1,52 @@ +using System; +using NUnit.Framework; +using NUnit.Framework.Constraints; +using OpenSim.Tests.Common; + +namespace OpenSim.Tests.Common +{ + public class DoubleToleranceConstraint : ANumericalToleranceConstraint + { + + private double _baseValue; + private double _valueToBeTested; + + public DoubleToleranceConstraint(double baseValue, double tolerance) : base(tolerance) + { + _baseValue = baseValue; + } + + /// + ///Test whether the constraint is satisfied by a given value + /// + ///The value to be tested + /// + ///True for success, false for failure + /// + public override bool Matches(object valueToBeTested) + { + if (valueToBeTested == null) + { + throw new ArgumentException("Constraint cannot be used upon null values."); + } + if( valueToBeTested.GetType() != typeof(double)) + { + throw new ArgumentException("Constraint cannot be used upon non double-values."); + } + + _valueToBeTested = (double)valueToBeTested; + + return IsWithinDoubleConstraint(_valueToBeTested, _baseValue ); + } + + public override void WriteDescriptionTo(MessageWriter writer) + { + writer.WriteExpectedValue(string.Format("A value {0} within tolerance of plus or minus {1}",_baseValue,_tolerance)); + } + + public override void WriteActualValueTo(MessageWriter writer) + { + writer.WriteActualValue(_valueToBeTested); + } + } +} -- cgit v1.1