|
| 1 | +package io.github.mrmaxguns.freepapermaps.projections; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Test; |
| 4 | + |
| 5 | +import static org.junit.jupiter.api.Assertions.*; |
| 6 | + |
| 7 | +// TODO: Add @Overrides everywhere |
| 8 | + |
| 9 | + |
| 10 | +public class CoordinateTest { |
| 11 | + @Test |
| 12 | + public void testConstructor() { |
| 13 | + double x = 9.1, y = 8.2; |
| 14 | + TestCoordinate coordinate = new TestCoordinate(x, y); |
| 15 | + assertAll(() -> assertEquals(x, coordinate.getX(), 0.0001, "Coordinate constructor should initialize x"), |
| 16 | + () -> assertEquals(x, coordinate.getLon(), 0.0001, |
| 17 | + "Coordinate constructor should initialize longitude"), |
| 18 | + () -> assertEquals(y, coordinate.getY(), 0.0001, "Coordinate constructor should initialize y"), |
| 19 | + () -> assertEquals(y, coordinate.getLat(), 0.0001, |
| 20 | + "Coordinate constructor should initialize latitude")); |
| 21 | + } |
| 22 | + |
| 23 | + @Test |
| 24 | + void testAdd() { |
| 25 | + TestCoordinate a = new TestCoordinate(11.23, 12.42); |
| 26 | + TestCoordinate b = new TestCoordinate(22.30, -11.22); |
| 27 | + TestCoordinate result = a.add(b); |
| 28 | + assertAll(() -> assertEquals(33.53, result.getLon(), 0.0001, "add() should add componentwise"), |
| 29 | + () -> assertEquals(1.2, result.getLat(), 0.0001, "add() should add componentwise")); |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + void testSubtract() { |
| 34 | + TestCoordinate a = new TestCoordinate(-12.04, 66.99); |
| 35 | + TestCoordinate b = new TestCoordinate(-9.98, -0.01); |
| 36 | + TestCoordinate result = a.subtract(b); |
| 37 | + assertAll(() -> assertEquals(-2.06, result.getLon(), 0.0001, "subtract() should subtract componentwise"), |
| 38 | + () -> assertEquals(67, result.getLat(), 0.0001, "subtract() should subtract componentwise")); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + void testScale() { |
| 43 | + TestCoordinate c = new TestCoordinate(-120, 15); |
| 44 | + TestCoordinate result = c.scale(0.5); |
| 45 | + assertAll(() -> assertEquals(-60, result.getX(), 0.0001, "scale() should scale each component"), |
| 46 | + () -> assertEquals(7.5, result.getY(), 0.0001, "scale() should scale each component")); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + void testEqualsTrue() { |
| 51 | + assertTrue(new TestCoordinate(10.1, 12.4).equals(new TestCoordinate(10.1, 12.4)), |
| 52 | + "equals() should check exact equality between components"); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + void testEqualsFalse() { |
| 57 | + assertFalse(new TestCoordinate(10, 15).equals(new TestCoordinate(10, -20)), |
| 58 | + "equals() should check exact equality between components"); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + void testEqualsWithEpsilonTrue() { |
| 63 | + assertTrue(new TestCoordinate(12.573, -13.981).equals(new TestCoordinate(12.575, -13.971), 0.01), |
| 64 | + "equals(other, epsilon) should use the epsilon as a bound"); |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + void testEqualsWithEpsilonFalse() { |
| 69 | + assertFalse(new TestCoordinate(8765.1, -5757.3).equals(new TestCoordinate(8765.0, -5758.4), 1), |
| 70 | + "equals(other, epsilon) should use the epsilon as a bound"); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + void testEqualsWithEpsilonXYTrue() { |
| 75 | + assertTrue(new TestCoordinate(0.5737, 14838).equals(new TestCoordinate(0.5740, 14836), 0.0005, 3), |
| 76 | + "equals(other, epsilonX, epsilonY) should use the respective epsilons as bounds"); |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + void testEqualsWithEpsilonXYFalse() { |
| 81 | + assertFalse(new TestCoordinate(-9494, 11.23).equals(new TestCoordinate(-9490, 11.24), 20, 0.0001), |
| 82 | + "equals(other, epsilonX, epsilonY) should use the respective epsilons as bounds"); |
| 83 | + } |
| 84 | + |
| 85 | + |
| 86 | + static class TestCoordinate extends Coordinate<TestCoordinate> { |
| 87 | + public TestCoordinate(double x, double y) { |
| 88 | + super(x, y); |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + protected TestCoordinate createInstance(double x, double y) { |
| 93 | + return new TestCoordinate(x, y); |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + public String getCoordinateType() { |
| 98 | + return "TestCoordinate"; |
| 99 | + } |
| 100 | + |
| 101 | + @Override |
| 102 | + public String getCoordinateUnit() { |
| 103 | + return "?"; |
| 104 | + } |
| 105 | + } |
| 106 | +} |
0 commit comments