/** * 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>. * 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 Matcher<Double> closeTo(double operand, double error) { return new IsCloseTo(operand, error); } }
/** * 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 */ @Factory public static Matcher<Double> closeTo(double operand, double error) { return new IsCloseTo(operand, error); } }
/** * 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>. * 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 Matcher<Double> closeTo(double operand, double error) { return new IsCloseTo(operand, error); } }
/** * 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>. * 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 Matcher<Double> closeTo(double operand, double error) { return new IsCloseTo(operand, error); } }
@Factory public static Matcher<Double> closeTo(double operand, double error) { return new IsCloseTo(operand, error); }
@SuppressWarnings({"rawtypes", "unchecked"}) public static Matcher<double[]> isArrayCloseTo(double[] expected) { final double DELTA = 1e-10; List<Matcher<Double>> matchers = new ArrayList<>(); for (double d : expected) matchers.add(new IsCloseTo(d, DELTA)); return new CustomTypeSafeMatcher<double[]>("array that is close to" + Arrays.toString(expected)) { @Override protected boolean matchesSafely(double[] actual) { return new IsArray<Double>(matchers.toArray(new Matcher[matchers.size()])) .matchesSafely(Arrays.stream(actual).boxed().toArray(Double[]::new)); } }; }