Top Description Fields Constructors Methods
org.hamcrest.number

public Class IsCloseTo

extends TypeSafeMatcher<Double>
Class Inheritance
Imports
org.hamcrest.Description, .Matcher, .Factory, .TypeSafeMatcher

Is the value a number equal to a value within some range of acceptable error?

Field Summary

Modifier and TypeField and Description
private final double
private final double

Constructor Summary

AccessConstructor and Description
public
IsCloseTo(double value, double error)

Method Summary

Modifier and TypeMethod and Description
private double
public static Matcher<Double>
closeTo(double
the expected value of matching doubles
operand
,
double
the delta (+/-) within which matches will be allowed
error
)

Creates a matcher of Doubles that matches when an examined double is equal to the specified operand, within a range of +/- error.

public void
describeMismatchSafely(Double item, Description mismatchDescription)

Overrides org.hamcrest.TypeSafeMatcher.describeMismatchSafely.

Subclasses should override this.
public void
describeTo(Description
The description to be built or appended to.
description
)

Implements org.hamcrest.SelfDescribing.describeTo.

Generates a description of the object.
public boolean
matchesSafely(Double item)

Implements abstract org.hamcrest.TypeSafeMatcher.matchesSafely.

Subclasses should implement this.
Inherited from org.hamcrest.TypeSafeMatcher:
describeMismatchmatches

Field Detail

deltaback to summary
private final double delta
valueback to summary
private final double value

Constructor Detail

IsCloseToback to summary
public IsCloseTo(double value, double error)

Method Detail

actualDeltaback to summary
private double actualDelta(Double item)
closeToback to summary
public static Matcher<Double> closeTo(double operand, double error)

Creates a matcher of Doubles 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:double

the expected value of matching doubles

error:double

the delta (+/-) within which matches will be allowed

Annotations
@Factory
describeMismatchSafelyback to summary
public void describeMismatchSafely(Double item, Description mismatchDescription)

Overrides org.hamcrest.TypeSafeMatcher.describeMismatchSafely.

Doc from org.hamcrest.TypeSafeMatcher.describeMismatchSafely.

Subclasses should override this. The item will already have been checked for the specific type and will never be null.

Annotations
@Override
describeToback to summary
public void describeTo(Description description)

Implements org.hamcrest.SelfDescribing.describeTo.

Doc from org.hamcrest.SelfDescribing.describeTo.

Generates a description of the object. The description may be part of a a description of a larger object of which this is just a component, so it should be worded appropriately.

Parameters
description:Description

The description to be built or appended to.

Annotations
@Override
matchesSafelyback to summary
public boolean matchesSafely(Double item)

Implements abstract org.hamcrest.TypeSafeMatcher.matchesSafely.

Doc from org.hamcrest.TypeSafeMatcher.matchesSafely.

Subclasses should implement this. The item will already have been checked for the specific type and will never be null.

Annotations
@Override