1 3 package org.jmock.core.constraint; 4 5 import org.jmock.core.Constraint; 6 7 8 12 public class IsCloseTo implements Constraint 13 { 14 private double error; 15 private double value; 16 17 public IsCloseTo( double value, double error ) { 18 this.error = error; 19 this.value = value; 20 } 21 22 public boolean eval( Object arg ) { 23 double argValue = ((Number )arg).doubleValue(); 24 return Math.abs((argValue - value)) <= error; 25 } 26 27 public StringBuffer describeTo( StringBuffer buffer ) { 28 return buffer.append("a numeric value within ") 29 .append(error) 30 .append(" of ") 31 .append(value); 32 } 33 } 34 | Popular Tags |