Example #1
0
        protected bool IsEqual(decimal x, decimal y, decimal tolerance, SideTolerance side)
        {
            //quick check
            if (x == y)
            {
                return(true);
            }

            //Stop checks if tolerance is set to 0
            if (tolerance == 0)
            {
                return(false);
            }

            //include some math[Time consumming] (Tolerance needed to validate)
            if (Math.Abs(x - y) <= Math.Abs(tolerance))
            {
                switch (side)
                {
                case SideTolerance.Both:
                    return(true);

                case SideTolerance.More:
                    return(x <= y);

                case SideTolerance.Less:
                    return(x >= y);

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(false);
        }
 public NumericPercentageTolerance(decimal value, SideTolerance side)
     : base(value, side)
 {
     Value = value;
     valueString = (100 * value).ToString(NumberFormatInfo.InvariantInfo);
     switch (side)
     {
         case SideTolerance.Both:
             break;
         case SideTolerance.More:
             valueString = string.Format("+{0}", valueString);
             break;
         case SideTolerance.Less:
             valueString = string.Format("-{0}", valueString);
             break;
         default:
             break;
     }
 }
Example #3
0
        public NumericPercentageTolerance(decimal value, SideTolerance side)
            : base(value, side)
        {
            Value       = value;
            valueString = (100 * value).ToString(NumberFormatInfo.InvariantInfo);
            switch (side)
            {
            case SideTolerance.Both:
                break;

            case SideTolerance.More:
                valueString = string.Format("+{0}", valueString);
                break;

            case SideTolerance.Less:
                valueString = string.Format("-{0}", valueString);
                break;

            default:
                break;
            }
        }
Example #4
0
 internal ComparerResult Compare(object x, object y, decimal tolerance, SideTolerance side)
 {
     return(base.Compare(x, y, new NumericAbsoluteTolerance(tolerance, side)));
 }
Example #5
0
 public NumericAbsoluteTolerance(decimal value, SideTolerance side)
     : base(value, side)
 {
     Value = value;
 }
Example #6
0
 public NumericTolerance(decimal value, SideTolerance side)
     : base(value.ToString(NumberFormatInfo.InvariantInfo))
 {
     Side  = side;
     Value = value;
 }
 public NumericAbsoluteTolerance(decimal value, SideTolerance side)
     : base(value, side)
 {
     Value = value;
 }
Example #8
0
 protected Tolerance(string value, SideTolerance side)
 {
     ValueString = value;
     this.Side = side;
 }
Example #9
0
 public NumericTolerance(decimal value, SideTolerance side)
     : base(value.ToString(NumberFormatInfo.InvariantInfo), side)
 {
     Value = value;
 }
Example #10
0
 internal ComparerResult Compare(object x, object y, decimal tolerance, SideTolerance side)
 {
     return base.Compare(x, y, new NumericAbsoluteTolerance(tolerance, side));
 }
Example #11
0
        protected bool IsEqual(decimal x, decimal y, decimal tolerance, SideTolerance side)
        {
            //quick check
            if (x == y)
                return true;

            //Stop checks if tolerance is set to 0
            if (tolerance == 0)
                return false;

            //include some math[Time consumming] (Tolerance needed to validate)
            if (Math.Abs(x - y) <= Math.Abs(tolerance))
            {
                switch (side)
                {
                    case SideTolerance.Both:
                        return true;
                    case SideTolerance.More:
                        return (x <= y);
                    case SideTolerance.Less:
                        return (x >= y);
                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }

            return false;
        }
Example #12
0
 protected Tolerance(string value, SideTolerance side)
 {
     ValueString = value;
     this.Side   = side;
 }