1 /* Copyright (c) 2000-2003, jMock.org. See bundled LICENSE.txt */
2 package org.jmock.constraint;
3
4 import org.jmock.Constraint;
5
6 /***
7 * Is the value a number equal to a value within some range of
8 * acceptable error?
9 */
10 public class IsCloseTo implements Constraint {
11 private double _error;
12 private double _value;
13
14 public IsCloseTo(double value, double error) {
15 _error = error;
16 _value = value;
17 }
18
19 public boolean eval(Object arg) {
20 double arg_value = ((Number) arg).doubleValue();
21 return Math.abs((arg_value - _value)) <= _error;
22 }
23
24 public String toString() {
25 return "a numeric value within " + _error + " of " + _value;
26 }
27 }
This page was automatically generated by Maven