📄 iscloseto.java
字号:
/* Copyright (c) 2000-2004 jMock.org
*/
package org.jmock.core.constraint;
import org.jmock.core.Constraint;
/**
* Is the value a number equal to a value within some range of
* acceptable error?
*/
public class IsCloseTo implements Constraint
{
private double error;
private double value;
public IsCloseTo( double value, double error ) {
this.error = error;
this.value = value;
}
public boolean eval( Object arg ) {
double argValue = ((Number)arg).doubleValue();
return Math.abs((argValue - value)) <= error;
}
public StringBuffer describeTo( StringBuffer buffer ) {
return buffer.append("a numeric value within ")
.append(error)
.append(" of ")
.append(value);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -