aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tests/Common/ANumericalToleranceConstraint.cs
blob: 2a6993d46a4aa4595927b591916d265634c5d665 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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;
        }
    }
}