org.hamcrest.number
Class IsCloseTo
java.lang.Object
org.hamcrest.BaseMatcher<T>
org.hamcrest.TypeSafeMatcher<java.lang.Double>
org.hamcrest.number.IsCloseTo
- All Implemented Interfaces:
- org.hamcrest.Matcher<java.lang.Double>, org.hamcrest.SelfDescribing
public class IsCloseTo
- extends org.hamcrest.TypeSafeMatcher<java.lang.Double>
Is the value a number equal to a value within some range of
acceptable error?
Constructor Summary |
IsCloseTo(double value,
double error)
|
Method Summary |
static org.hamcrest.Matcher<java.lang.Double> |
closeTo(double operand,
double error)
Creates a matcher of Double s that matches when an examined double is equal
to the specified operand , within a range of +/- error . |
void |
describeMismatchSafely(java.lang.Double item,
org.hamcrest.Description mismatchDescription)
|
void |
describeTo(org.hamcrest.Description description)
|
boolean |
matchesSafely(java.lang.Double item)
|
Methods inherited from class org.hamcrest.TypeSafeMatcher |
describeMismatch, matches |
Methods inherited from class org.hamcrest.BaseMatcher |
_dont_implement_Matcher___instead_extend_BaseMatcher_, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
IsCloseTo
public IsCloseTo(double value,
double error)
matchesSafely
public boolean matchesSafely(java.lang.Double item)
- Specified by:
matchesSafely
in class org.hamcrest.TypeSafeMatcher<java.lang.Double>
describeMismatchSafely
public void describeMismatchSafely(java.lang.Double item,
org.hamcrest.Description mismatchDescription)
- Overrides:
describeMismatchSafely
in class org.hamcrest.TypeSafeMatcher<java.lang.Double>
describeTo
public void describeTo(org.hamcrest.Description description)
closeTo
public static org.hamcrest.Matcher<java.lang.Double> closeTo(double operand,
double error)
- Creates a matcher of
Double
s that matches when an examined double is equal
to the specified operand
, within a range of +/- error
.
For example:
assertThat(1.03, is(closeTo(1.0, 0.03)))
- Parameters:
operand
- the expected value of matching doubleserror
- the delta (+/-) within which matches will be allowed