@Test
public void testEquals() {

    /*
     * Initialize an empty envelope. The new envelope is empty and null.
     */
    final GeneralEnvelope e1 = new GeneralEnvelope(4);
    assertTrue(e1.isEmpty());
    assertTrue(e1.isNull());
    assertEquals(e1.getLowerCorner(), e1.getUpperCorner());
    /*
     * Initialize with arbitrary coordinate values. Should not be empty anymore.
     */
    for (int i = e1.getDimension(); --i >= 0;) {
        e1.setRange(i, i * 5 + 2, i * 6 + 5);
    }
    assertFalse(e1.isNull());
    assertFalse(e1.isEmpty());
    assertFalse(e1.getLowerCorner().equals(e1.getUpperCorner()));
    /*
     * Creates a new envelope initialized with the same coordinate values. The two envelope
     * should be equals.
     */
    final GeneralEnvelope e2 = new GeneralEnvelope(e1);
    assertPositionEquals(e1.getLowerCorner(), e2.getLowerCorner());
    assertPositionEquals(e1.getUpperCorner(), e2.getUpperCorner());
    assertTrue(e1.contains(e2, true));
    assertFalse(e1.contains(e2, false));
    assertNotSame(e1, e2);
    assertEquals(e1, e2);
    assertTrue(e1.equals(e2, 1E-4, true));
    assertTrue(e1.equals(e2, 1E-4, false));
    assertEquals(e1.hashCode(), e2.hashCode());
    /*
     * Offset slightly one coordinate value. Should not be equals anymore, except when comparing
     * with a tolerance value.
     */
    e2.setRange(2, e2.getMinimum(2) + 3E-5, e2.getMaximum(2) - 3E-5);
    assertTrue(e1.contains(e2, true));
    assertFalse(e1.contains(e2, false));
    assertFalse(e1.equals(e2));
    assertTrue(e1.equals(e2, 1E-4, true));
    assertTrue(e1.equals(e2, 1E-4, false));
    assertFalse(e1.hashCode() == e2.hashCode());
    /*
     * Apply a greater offset. Should not be equals, even when comparing with a tolerance value.
     */
    e2.setRange(1, e2.getMinimum(1) + 3, e2.getMaximum(1) - 3);
    assertTrue(e1.contains(e2, true));
    assertFalse(e1.contains(e2, false));
    assertFalse(e1.equals(e2));
    assertFalse(e1.equals(e2, 1E-4, true));
    assertFalse(e1.equals(e2, 1E-4, false));
    assertFalse(e1.hashCode() == e2.hashCode());
}