org.hamcrest.number.IsCloseTo Java Examples

The following examples show how to use org.hamcrest.number.IsCloseTo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetricBase.java    From jpeek with MIT License 6 votes vote down vote up
/**
 * Asserts the main metric value.
 * @param value Expected value of the metric
 * @param error Rounding tolerance since the metric is float number
 * @throws IOException String format exception
 */
public void assertValue(final double value, final double error)
    throws IOException {
    new Assertion<>(
        "The metric value is not calculated properly",
        Double.parseDouble(
            this.xml.xpath(
                new FormattedText(
                    "//class[@id='%s']/@value",
                    this.name
                ).asString()
            ).get(0)
        ),
        new IsCloseTo(
            value,
            error
        )
    ).affirm();
}
 
Example #2
Source File: ModeAggregatorTest.java    From mrgeo with Apache License 2.0 5 votes vote down vote up
@Test
@Category(UnitTest.class)
public void testDouble()
{
  double[] values = {0.21, 0.32, 0.32, 0.54};
  double nodata = Double.NaN;
  double result;
  Aggregator agg = new ModeAggregator();

  //Test normal case
  result = agg.aggregate(values, nodata);
  assertEquals(0.32, result, epsilon);

  //Test nodata cases
  values[0] = nodata;
  result = agg.aggregate(values, nodata);
  assertEquals(0.32, result, epsilon);

  values[1] = nodata;
  result = agg.aggregate(values, nodata);
  assertThat((double) result, AnyOf.anyOf(IsCloseTo.closeTo(0.32f, epsilon), IsCloseTo.closeTo(0.54f, epsilon)));

  values[2] = nodata;
  result = agg.aggregate(values, nodata);
  assertEquals(0.54, result, epsilon);

  values[3] = nodata;
  result = agg.aggregate(values, nodata);
  assertEquals(nodata, result, epsilon);

}
 
Example #3
Source File: ModeAggregatorTest.java    From mrgeo with Apache License 2.0 5 votes vote down vote up
@Test
@Category(UnitTest.class)
public void testFloat()
{
  float[] values = {0.21f, 0.32f, 0.32f, 0.54f};
  float nodata = -9999.0f;
  float result;
  Aggregator agg = new ModeAggregator();

  //Test normal case
  result = agg.aggregate(values, nodata);
  assertEquals(0.32, result, epsilon);

  //Test nodata cases
  values[0] = nodata;
  result = agg.aggregate(values, nodata);
  assertEquals(0.32, result, epsilon);

  values[1] = nodata;
  result = agg.aggregate(values, nodata);
  //assertEquals(0.54, result, epsilon);
  assertThat((double) result, AnyOf.anyOf(IsCloseTo.closeTo(0.32f, epsilon), IsCloseTo.closeTo(0.54f, epsilon)));

  values[2] = nodata;
  result = agg.aggregate(values, nodata);
  assertEquals(0.54, result, epsilon);

  values[3] = nodata;
  result = agg.aggregate(values, nodata);
  assertEquals(nodata, result, epsilon);

}
 
Example #4
Source File: AbstractScrollIT.java    From flow with Apache License 2.0 4 votes vote down vote up
protected void checkPageScroll(int x, int y, int delta) {
    assertThat("Unexpected x scroll position", (double) getScrollX(),
            IsCloseTo.closeTo(x, delta));
    assertThat("Unexpected y scroll position", (double) getScrollY(),
            IsCloseTo.closeTo(y, delta));
}
 
Example #5
Source File: IsNumberCloseTo.java    From es6draft with MIT License 4 votes vote down vote up
public IsNumberCloseTo(double value, double error) {
    this.closeTo = new IsCloseTo(value, error);
}