@Override public boolean matchesSafely(Double item) { return actualDelta(item) <= 0.0; }
/** * Creates a matcher of {@link Comparable} object that matches when the examined object is * equal to the specified value, as reported by the <code>compareTo</code> method of the * <b>examined</b> object. * <p/> * For example: * <pre>assertThat(1, comparesEqualTo(1))</pre> * * @param value * the value which, when passed to the compareTo method of the examined object, should return zero */ public static <T extends java.lang.Comparable<T>> org.hamcrest.Matcher<T> comparesEqualTo(T value) { return org.hamcrest.number.OrderingComparison.<T>comparesEqualTo(value); }
/** * Creates a matcher of {@link Comparable} object that matches when the examined object is * greater than the specified value, as reported by the <code>compareTo</code> method of the * <b>examined</b> object. * <p/> * For example: * <pre>assertThat(2, greaterThan(1))</pre> * * @param value * the value which, when passed to the compareTo method of the examined object, should return greater * than zero */ public static <T extends java.lang.Comparable<T>> org.hamcrest.Matcher<T> greaterThan(T value) { return org.hamcrest.number.OrderingComparison.<T>greaterThan(value); }
public void testDescription() { assertDescription("a value greater than <1>", greaterThan(1)); assertDescription("a value equal to or greater than <1>", greaterThanOrEqualTo(1)); assertDescription("a value equal to <1>", comparesEqualTo(1)); assertDescription("a value less than or equal to <1>", lessThanOrEqualTo(1)); assertDescription("a value less than <1>", lessThan(1)); }
public void testMismatchDescriptions() { assertMismatchDescription("<0> was less than <1>", greaterThan(1), 0); assertMismatchDescription("<1> was equal to <1>", greaterThan(1), 1); assertMismatchDescription("<1> was greater than <0>", lessThan(0), 1); assertMismatchDescription("<2> was equal to <2>", lessThan(2), 2); }
/** * Creates a matcher of {@link Double}s that matches when an examined double is equal * to the specified <code>operand</code>, within a range of +/- <code>error</code>. * <p/> * For example: * <pre>assertThat(1.03, is(closeTo(1.0, 0.03)))</pre> * * @param operand * the expected value of matching doubles * @param error * the delta (+/-) within which matches will be allowed */ public static org.hamcrest.Matcher<java.lang.Double> closeTo(double operand, double error) { return org.hamcrest.number.IsCloseTo.closeTo(operand, error); }
/** * Creates a matcher of {@link Comparable} object that matches when the examined object is * less than the specified value, as reported by the <code>compareTo</code> method of the * <b>examined</b> object. * <p/> * For example: * <pre>assertThat(1, lessThan(2))</pre> * * @param value * the value which, when passed to the compareTo method of the examined object, should return less * than zero */ public static <T extends java.lang.Comparable<T>> org.hamcrest.Matcher<T> lessThan(T value) { return org.hamcrest.number.OrderingComparison.<T>lessThan(value); }
/** * Creates a matcher of {@link Comparable} object that matches when the examined object is * greater than or equal to the specified value, as reported by the <code>compareTo</code> method * of the <b>examined</b> object. * <p/> * For example: * <pre>assertThat(1, greaterThanOrEqualTo(1))</pre> * * @param value * the value which, when passed to the compareTo method of the examined object, should return greater * than or equal to zero */ public static <T extends java.lang.Comparable<T>> org.hamcrest.Matcher<T> greaterThanOrEqualTo(T value) { return org.hamcrest.number.OrderingComparison.<T>greaterThanOrEqualTo(value); }
/** * Creates a matcher of {@link Comparable} object that matches when the examined object is * less than or equal to the specified value, as reported by the <code>compareTo</code> method * of the <b>examined</b> object. * <p/> * For example: * <pre>assertThat(1, lessThanOrEqualTo(1))</pre> * * @param value * the value which, when passed to the compareTo method of the examined object, should return less * than or equal to zero */ public static <T extends java.lang.Comparable<T>> org.hamcrest.Matcher<T> lessThanOrEqualTo(T value) { return org.hamcrest.number.OrderingComparison.<T>lessThanOrEqualTo(value); }
/** * Creates a matcher of {@link java.math.BigDecimal}s that matches when an examined BigDecimal is equal * to the specified <code>operand</code>, within a range of +/- <code>error</code>. The comparison for equality * is done by BigDecimals {@link java.math.BigDecimal#compareTo(java.math.BigDecimal)} method. * <p/> * For example: * <pre>assertThat(new BigDecimal("1.03"), is(closeTo(new BigDecimal("1.0"), new BigDecimal("0.03"))))</pre> * * @param operand * the expected value of matching BigDecimals * @param error * the delta (+/-) within which matches will be allowed */ public static org.hamcrest.Matcher<java.math.BigDecimal> closeTo(java.math.BigDecimal operand, java.math.BigDecimal error) { return org.hamcrest.number.BigDecimalCloseTo.closeTo(operand, error); }
/** * Creates a matcher of {@link Double}s that matches when an examined double is not a number. * For example: * <pre>assertThat(Double.NaN, is(notANumber()))</pre> */ public static org.hamcrest.Matcher<java.lang.Double> notANumber() { return org.hamcrest.number.IsNaN.notANumber(); }
/** * Creates a matcher of {@link Double}s that matches when an examined double is not a number. * For example: * <pre>assertThat(Double.NaN, is(notANumber()))</pre> */ public static Matcher<Double> notANumber() { return new IsNaN(); } }
public void test_matchesIfArgumentIsEqualToADoubleValueWithinSomeError() { assertMatches("1.0", matcher, 1.0); assertMatches("0.5d", matcher, 0.5d); assertMatches("1.5d", matcher, 1.5d); assertDoesNotMatch("too large", matcher, 2.0); assertMismatchDescription("<3.0> differed by <1.5> more than delta <0.5>", matcher, 3.0d); assertDoesNotMatch("number too small", matcher, 0.0); assertMismatchDescription("<0.1> differed by <0.4> more than delta <0.5>", matcher, 0.1); }
@Override protected Matcher<?> createMatcher() { final double irrelevant = 0.1; return closeTo(irrelevant, irrelevant); }
/** * Creates a matcher of {@link Comparable} object that matches when the examined object is * greater than the specified value, as reported by the <code>compareTo</code> method of the * <b>examined</b> object. * For example: * <pre>assertThat(2, greaterThan(1))</pre> * * @param value the value which, when passed to the compareTo method of the examined object, should return greater * than zero */ public static <T extends java.lang.Comparable<T>> org.hamcrest.Matcher<T> greaterThan(T value) { return org.hamcrest.number.OrderingComparison.greaterThan(value); }
/** * Creates a matcher of {@link Comparable} object that matches when the examined object is * less than the specified value, as reported by the <code>compareTo</code> method of the * <b>examined</b> object. * For example: * <pre>assertThat(1, lessThan(2))</pre> * * @param value the value which, when passed to the compareTo method of the examined object, should return less * than zero */ public static <T extends java.lang.Comparable<T>> org.hamcrest.Matcher<T> lessThan(T value) { return org.hamcrest.number.OrderingComparison.lessThan(value); }
/** * Creates a matcher of {@link Comparable} object that matches when the examined object is * greater than or equal to the specified value, as reported by the <code>compareTo</code> method * of the <b>examined</b> object. * For example: * <pre>assertThat(1, greaterThanOrEqualTo(1))</pre> * * @param value the value which, when passed to the compareTo method of the examined object, should return greater * than or equal to zero */ public static <T extends java.lang.Comparable<T>> org.hamcrest.Matcher<T> greaterThanOrEqualTo(T value) { return org.hamcrest.number.OrderingComparison.greaterThanOrEqualTo(value); }
/** * Creates a matcher of {@link Comparable} object that matches when the examined object is * equal to the specified value, as reported by the <code>compareTo</code> method of the * <b>examined</b> object. * For example: * <pre>assertThat(1, comparesEqualTo(1))</pre> * * @param value the value which, when passed to the compareTo method of the examined object, should return zero */ public static <T extends java.lang.Comparable<T>> org.hamcrest.Matcher<T> comparesEqualTo(T value) { return org.hamcrest.number.OrderingComparison.comparesEqualTo(value); }
@Override public boolean matchesSafely(Double item) { return actualDelta(item) <= 0.0; }
@Override public void describeMismatchSafely(Double item, Description mismatchDescription) { mismatchDescription.appendValue(item) .appendText(" differed by ") .appendValue(actualDelta(item)); }