|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
IsCloseTo.java | - | 80% | 66.7% | 75% |
|
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 | 2 |
public IsCloseTo(double value, double error) { |
15 | 2 |
_error = error; |
16 | 2 |
_value = value; |
17 |
} |
|
18 |
|
|
19 | 16 |
public boolean eval(Object arg) { |
20 | 16 |
double arg_value = ((Number) arg).doubleValue();
|
21 | 14 |
return Math.abs((arg_value - _value)) <= _error;
|
22 |
} |
|
23 |
|
|
24 | 0 |
public String toString() {
|
25 | 0 |
return "a numeric value within " + _error + " of " + _value; |
26 |
} |
|
27 |
} |
|
28 |
|
|