~ubuntu-branches/ubuntu/raring/libhamcrest1.2-java/raring

« back to all changes in this revision

Viewing changes to hamcrest-unit-test/src/main/java/org/hamcrest/number/IsCloseToTest.java

  • Committer: Package Import Robot
  • Author(s): Brian Thomason
  • Date: 2011-12-02 17:55:55 UTC
  • Revision ID: package-import@ubuntu.com-20111202175555-xuj86jbpi8mehr1o
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  Copyright (c) 2000-2006 hamcrest.org
 
2
 */
 
3
package org.hamcrest.number;
 
4
 
 
5
import org.hamcrest.AbstractMatcherTest;
 
6
import org.hamcrest.Matcher;
 
7
import static org.hamcrest.number.IsCloseTo.closeTo;
 
8
 
 
9
public class IsCloseToTest extends AbstractMatcherTest {
 
10
 
 
11
    @Override
 
12
    protected Matcher<?> createMatcher() {
 
13
        double irrelevant = 0.1;
 
14
        return closeTo(irrelevant, irrelevant);
 
15
    }
 
16
 
 
17
    public void testEvaluatesToTrueIfArgumentIsEqualToADoubleValueWithinSomeError() {
 
18
        Matcher<Double> p = closeTo(1.0, 0.5);
 
19
 
 
20
        assertTrue(p.matches(1.0));
 
21
        assertTrue(p.matches(0.5d));
 
22
        assertTrue(p.matches(1.5d));
 
23
 
 
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);
 
28
    }
 
29
 
 
30
}