/**
* Copyright (c) 2009-2011, chunquedong(YangJiandong)
*
* This file is part of ChunMap project
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
*
* History:
* 2010-05-05 Jed Young Creation
*/
package chunmap.util.math;
import static org.junit.Assert.*;
import org.junit.Test;
import chunmap.model.coord.Coordinate2D;
import chunmap.model.coord.CPoint;
public class MyDoubleTest {
@Test
public void testApproximateEqualsDoubleDouble() {
CPoint coord1 = new Coordinate2D(10d, 20d);
CPoint coord2 = new Coordinate2D(10.00001d, 20d);
assertFalse(coord1.approximateEquals(coord2));
MyDouble.setThreshold(0.01);
assertTrue(coord1.approximateEquals(coord2));
}
@Test
public void testIsInfinity() {
assertTrue(MyDouble.isNegativeInfinity(Double.NEGATIVE_INFINITY));
assertTrue(MyDouble.isPositiveInfinity(Double.POSITIVE_INFINITY));
}
@Test
public void testApproximateCompare() {
MyDouble.setThreshold(0.000001);
assertTrue(MyDouble.approximateCompare(1.000000001, 1.0000000011) == 0);
assertTrue(MyDouble.approximateCompare(1.0001d, 1.0000000011d) == 1);
assertTrue(MyDouble.approximateCompare(1.000000001d, 1.0001d) == -1);
}
}