1
/* Copyright (c) 2000-2006 hamcrest.org
3
package org.hamcrest.number;
5
import org.hamcrest.AbstractMatcherTest;
6
import org.hamcrest.Matcher;
7
import static org.hamcrest.number.IsCloseTo.closeTo;
9
public class IsCloseToTest extends AbstractMatcherTest {
12
protected Matcher<?> createMatcher() {
13
double irrelevant = 0.1;
14
return closeTo(irrelevant, irrelevant);
17
public void testEvaluatesToTrueIfArgumentIsEqualToADoubleValueWithinSomeError() {
18
Matcher<Double> p = closeTo(1.0, 0.5);
20
assertTrue(p.matches(1.0));
21
assertTrue(p.matches(0.5d));
22
assertTrue(p.matches(1.5d));
24
assertDoesNotMatch("too large", p, 2.0);
25
assertMismatchDescription("<2.0> differed by <0.5>", p, 2.0);
26
assertDoesNotMatch("number too small", p, 0.0);
27
assertMismatchDescription("<0.0> differed by <0.5>", p, 0.0);