Example usage for org.apache.commons.math.util MathUtils equals

List of usage examples for org.apache.commons.math.util MathUtils equals

Introduction

In this page you can find the example usage for org.apache.commons.math.util MathUtils equals.

Prototype

public static boolean equals(double x, double y, int maxUlps) 

Source Link

Document

Returns true if both arguments are equal or within the range of allowed error (inclusive).

Usage

From source file:edu.utah.further.core.math.misc.TolerantEqualsBuilder.java

/**
 * Append the tolerant equality of two doubles.
 * /*ww w  .  j a  va  2  s . co  m*/
 * @param lhs
 *            left-hand-side
 * @param rhs
 *            right-hand-side
 * @param maxUlps
 *            ULPS (roughly equivalent to unit round-off relative error)
 * @return this object, for method chaining
 */
public TolerantEqualsBuilder appendTolerantly(final double lhs, final double rhs, final int maxUlps) {
    return super.append(MathUtils.equals(lhs, rhs, maxUlps), true);
}

From source file:edu.umn.msi.tropix.proteomics.conversion.impl.MzXMLToMGFConverterStreamingImplTest.java

@Test(groups = "unit")
public void testMrr() throws Exception {
    convertResource("readw.mzXML", null);
    final Iterator<Scan> scanIter = loadConvertedScans();
    final List<Scan> num78Scans = Lists.newArrayList();
    Scan scan1993 = null;/*ww w  .  j a  v  a2 s .c  o m*/
    while (scanIter.hasNext()) {
        final Scan scan = scanIter.next();
        int scanNumber = scan.getNumber();
        if (scanNumber > 1993) {
            break;
        } else if (scanNumber == 78) {
            num78Scans.add(scan);
        } else if (scanNumber == 1993) {
            assert scan1993 == null; // Make sure it doesn't get set twice.
            scan1993 = scan;
        }
    }
    assert num78Scans.size() == 2 : num78Scans.size();
    final Scan scan1 = num78Scans.get(0), scan2 = num78Scans.get(1);
    assert scan1.getAlt() == 78;
    assert scan1.getMsLevel() == 2;
    assert MathUtils.equals(scan1.getPrecursorMz(), 592.810000f, 0.0001) : scan1.getPrecursorMz();
    assert MathUtils.equals(scan1.getPrecursorIntensity(), 1012.2700f, 0.0001) : scan1.getPrecursorIntensity();
    assert scan1.getPrecursorCharge() == 2;
    assert scan2.getPrecursorCharge() == 3;
    assert MathUtils.equals(scan1.getPeaks(), scan2.getPeaks());
    assert MathUtils.equals(scan1.getPeaks()[0], 355.107788d) : scan1.getPeaks()[0];
}

From source file:hoot.services.geo.BoundingBox.java

@Override
public boolean equals(Object obj) {
    BoundingBox objBounds = (BoundingBox) obj;
    //TODO: temp - allowing for a small amount of error until I figure out what's causing it
    //    return this.maxLat == objBounds.getMaxLat() && this.maxLon == objBounds.getMaxLon() &&
    //      this.minLat == objBounds.getMinLat() && this.minLon == objBounds.getMinLon();
    return MathUtils.equals(this.maxLat, objBounds.getMaxLat(), BOUNDS_ERROR)
            && MathUtils.equals(this.maxLon, objBounds.getMaxLon(), BOUNDS_ERROR)
            && MathUtils.equals(this.minLat, objBounds.getMinLat(), BOUNDS_ERROR)
            && MathUtils.equals(this.minLon, objBounds.getMinLon(), BOUNDS_ERROR);
}

From source file:org.apache.metron.indexing.dao.metaalert.lucene.AbstractLuceneMetaAlertUpdateDaoTest.java

private boolean metaAlertDocumentEquals(Document expected, Document actual) {
    if (!expected.getGuid().equals(actual.getGuid())) {
        return false;
    }//  ww  w.j ava 2  s.c  o m
    if (!expected.getSensorType().equals(actual.getSensorType())) {
        return false;
    }
    if (!expected.getTimestamp().equals(actual.getTimestamp())) {
        return false;
    }

    // The underlying documents have to be compared more thoroughly since it has floating point
    Map<String, Object> expectedDocument = expected.getDocument();
    Map<String, Object> actualDocument = actual.getDocument();

    if (expectedDocument.size() != actualDocument.size()) {
        return false;
    }

    for (Entry<String, Object> entry : expectedDocument.entrySet()) {
        Object value = entry.getValue();
        Object actualValue = actual.getDocument().get(entry.getKey());
        if (value instanceof Float) {
            if (!MathUtils.equals((Float) value, (Float) actualValue, EPS)) {
                return false;
            }
        } else if (value instanceof Double) {
            if (!MathUtils.equals((Double) value, (Double) actualValue, EPS)) {
                return false;
            }
        } else {
            if (!value.equals(actual.getDocument().get(entry.getKey()))) {
                return false;
            }
        }
    }

    return true;
}

From source file:org.apache.metron.profiler.integration.ProfilerIntegrationTest.java

/**
 * Tests the first example contained within the README.
 *//*from w w w.j  a  v  a  2s  .  co m*/
@Test
public void testExample1() throws Exception {

    setup(TEST_RESOURCES + "/config/zookeeper/readme-example-1");

    // start the topology and write test messages to kafka
    fluxComponent.submitTopology();
    kafkaComponent.writeMessages(inputTopic, input);

    // verify - ensure the profile is being persisted
    waitOrTimeout(() -> profilerTable.getPutLog().size() > 0, timeout(seconds(90)));

    // verify - only 10.0.0.2 sends 'HTTP', thus there should be only 1 value
    List<Double> actuals = read(profilerTable.getPutLog(), columnFamily,
            columnBuilder.getColumnQualifier("value"), Double.class);

    // verify - there are 5 'HTTP' each with 390 bytes
    Assert.assertTrue(actuals.stream().anyMatch(val -> MathUtils.equals(390.0 * 5, val, epsilon)));
}

From source file:org.apache.metron.profiler.integration.ProfilerIntegrationTest.java

/**
 * Tests the second example contained within the README.
 *///from  w w w.j a v  a2  s . c om
@Test
public void testExample2() throws Exception {

    setup(TEST_RESOURCES + "/config/zookeeper/readme-example-2");

    // start the topology and write test messages to kafka
    fluxComponent.submitTopology();
    kafkaComponent.writeMessages(inputTopic, input);

    // expect 2 values written by the profile; one for 10.0.0.2 and another for 10.0.0.3
    final int expected = 2;

    // verify - ensure the profile is being persisted
    waitOrTimeout(() -> profilerTable.getPutLog().size() >= expected, timeout(seconds(90)));

    // verify - expect 2 results as 2 hosts involved; 10.0.0.2 sends 'HTTP' and 10.0.0.3 send 'DNS'
    List<Double> actuals = read(profilerTable.getPutLog(), columnFamily,
            columnBuilder.getColumnQualifier("value"), Double.class);

    // verify - 10.0.0.3 -> 1/6
    Assert.assertTrue(
            "Could not find a value near 1/6. Actual values read are are: " + Joiner.on(",").join(actuals),
            actuals.stream().anyMatch(val -> MathUtils.equals(val, 1.0 / 6.0, epsilon)));

    // verify - 10.0.0.2 -> 6/1
    Assert.assertTrue(
            "Could not find a value near 6. Actual values read are are: " + Joiner.on(",").join(actuals),
            actuals.stream().anyMatch(val -> MathUtils.equals(val, 6.0 / 1.0, epsilon)));
}

From source file:org.apache.metron.profiler.integration.ProfilerIntegrationTest.java

/**
 * Tests the third example contained within the README.
 *///from  w ww.  jav  a 2 s .co  m
@Test
public void testExample3() throws Exception {

    setup(TEST_RESOURCES + "/config/zookeeper/readme-example-3");

    // start the topology and write test messages to kafka
    fluxComponent.submitTopology();
    kafkaComponent.writeMessages(inputTopic, input);

    // verify - ensure the profile is being persisted
    waitOrTimeout(() -> profilerTable.getPutLog().size() > 0, timeout(seconds(90)));

    // verify - only 10.0.0.2 sends 'HTTP', thus there should be only 1 value
    List<Double> actuals = read(profilerTable.getPutLog(), columnFamily,
            columnBuilder.getColumnQualifier("value"), Double.class);

    // verify - there are 5 'HTTP' messages each with a length of 20, thus the average should be 20
    Assert.assertTrue(
            "Could not find a value near 20. Actual values read are are: " + Joiner.on(",").join(actuals),
            actuals.stream().anyMatch(val -> MathUtils.equals(val, 20.0, epsilon)));
}

From source file:org.apache.metron.profiler.integration.ProfilerIntegrationTest.java

/**
 * Tests the fourth example contained within the README.
 *//*from   www  .  j ava 2 s.  c  o  m*/
@Test
public void testExample4() throws Exception {

    setup(TEST_RESOURCES + "/config/zookeeper/readme-example-4");

    // start the topology and write test messages to kafka
    fluxComponent.submitTopology();
    kafkaComponent.writeMessages(inputTopic, input);

    // verify - ensure the profile is being persisted
    waitOrTimeout(() -> profilerTable.getPutLog().size() > 0, timeout(seconds(90)));

    // verify - only 10.0.0.2 sends 'HTTP', thus there should be only 1 value
    byte[] column = columnBuilder.getColumnQualifier("value");
    List<OnlineStatisticsProvider> actuals = read(profilerTable.getPutLog(), columnFamily, column,
            OnlineStatisticsProvider.class);

    // verify - there are 5 'HTTP' messages each with a length of 20, thus the average should be 20
    Assert.assertTrue(
            "Could not find a value near 20. Actual values read are are: " + Joiner.on(",").join(actuals),
            actuals.stream().anyMatch(val -> MathUtils.equals(val.getMean(), 20.0, epsilon)));
}

From source file:org.apache.metron.profiler.integration.ProfilerIntegrationTest.java

@Test
public void testPercentiles() throws Exception {

    setup(TEST_RESOURCES + "/config/zookeeper/percentiles");

    // start the topology and write test messages to kafka
    fluxComponent.submitTopology();/*from ww  w  .ja v a2s .c o m*/
    kafkaComponent.writeMessages(inputTopic, input);

    // verify - ensure the profile is being persisted
    waitOrTimeout(() -> profilerTable.getPutLog().size() > 0, timeout(seconds(90)));

    List<Double> actuals = read(profilerTable.getPutLog(), columnFamily,
            columnBuilder.getColumnQualifier("value"), Double.class);

    // verify - the 70th percentile of 5 x 20s = 20.0
    Assert.assertTrue(
            "Could not find a value near 20. Actual values read are are: " + Joiner.on(",").join(actuals),
            actuals.stream().anyMatch(val -> MathUtils.equals(val, 20.0, epsilon)));
}

From source file:org.opensha.commons.geo.GriddedRegionTest.java

@Test
public final void testGetMinGridLat() {
    assertTrue(MathUtils.equals(octRegionML.getMinGridLat(), 25.0, TOLERANCE));
}