Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
maesenka committed Jan 28, 2023
1 parent 048a860 commit 8c09e92
Showing 1 changed file with 36 additions and 39 deletions.
75 changes: 36 additions & 39 deletions geom/src/test/java/org/geolatte/geom/PackedPointSequenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@

package org.geolatte.geom;

import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.CoordinateSequence;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.util.Arrays;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.CoordinateSequence;

import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.*;
Expand All @@ -37,11 +35,11 @@
*/
public class PackedPointSequenceTest {

private static PositionFactory <C2D> des2D = Positions.getFactoryFor(C2D.class);
private final static PositionFactory<C2D> des2D = Positions.getFactoryFor(C2D.class);

private static PositionFactory <C3D> des3D = Positions.getFactoryFor(C3D.class);
private static PositionFactory <C2DM> des2DM = Positions.getFactoryFor(C2DM.class);
private static PositionFactory <C3DM> des3DM = Positions.getFactoryFor(C3DM.class);
private final static PositionFactory<C3D> des3D = Positions.getFactoryFor(C3D.class);
private final static PositionFactory<C2DM> des2DM = Positions.getFactoryFor(C2DM.class);
private final static PositionFactory<C3DM> des3DM = Positions.getFactoryFor(C3DM.class);

PackedPositionSequence<C2D> testSeq2D;
PackedPositionSequence<C3D> testSeq3D;
Expand All @@ -52,46 +50,46 @@ public class PackedPointSequenceTest {

@Before
public void setUp() {
testSeq2D = new PackedPositionSequence<C2D>(des2D, new double[]{0, 0, 1, -1, 2, -2});
testSeq3D = new PackedPositionSequence<C3D>(des3D, new double[]{0, 0, 0, 1, -1, 1, 2, -2, 2});
testSeq2DM = new PackedPositionSequence<C2DM>(des2DM, new double[]{0, 0, 0, 1, -1, 1, 2, -2, 2});
testSeq3DM = new PackedPositionSequence<C3DM>(des3DM, new double[]{0, 0, 0, 1, 1, -1, 1, 2, 2, -2, 2, 3});
testEmpty = new PackedPositionSequence<C2D>(des2D, new double[0]);
testSeq2D = new PackedPositionSequence<>(des2D, new double[]{0, 0, 1, -1, 2, -2});
testSeq3D = new PackedPositionSequence<>(des3D, new double[]{0, 0, 0, 1, -1, 1, 2, -2, 2});
testSeq2DM = new PackedPositionSequence<>(des2DM, new double[]{0, 0, 0, 1, -1, 1, 2, -2, 2});
testSeq3DM = new PackedPositionSequence<>(des3DM, new double[]{0, 0, 0, 1, 1, -1, 1, 2, 2, -2, 2, 3});
testEmpty = new PackedPositionSequence<>(des2D, new double[0]);
}


@Test
public void testConstructorThrowsIllegalArgumentOnWrongNumberOfCoordinates() {
try {
new PackedPositionSequence<C2D>(des2D, new double[]{0, 0, 1, 1, 3});
new PackedPositionSequence<>(des2D, new double[]{0, 0, 1, 1, 3});
fail();
} catch (IllegalArgumentException e) {
}

try {
new PackedPositionSequence<C3D>(des3D, new double[]{0, 0, 0, 1, 1, 1, 1});
new PackedPositionSequence<>(des3D, new double[]{0, 0, 0, 1, 1, 1, 1});
fail();
} catch (IllegalArgumentException e) {
}

try {
new PackedPositionSequence<C3D>(des3D, new double[]{0, 0, 0, 1, 1, 1, 1, 1});
new PackedPositionSequence<>(des3D, new double[]{0, 0, 0, 1, 1, 1, 1, 1});
fail();
} catch (IllegalArgumentException e) {
}
}


@Test
public void testGetDimension() throws Exception {
public void testGetDimension() {
assertEquals(2, testSeq2D.getCoordinateDimension());
assertEquals(3, testSeq3D.getCoordinateDimension());
assertEquals(3, testSeq2DM.getCoordinateDimension());
assertEquals(4, testSeq3DM.getCoordinateDimension());
}

@Test
public void testGetCoordinate() throws Exception {
public void testGetCoordinate() {
// test2D
assertEquals(new Coordinate(0, 0), testSeq2D.getCoordinate(0));
assertEquals(new Coordinate(1, -1), testSeq2D.getCoordinate(1));
Expand Down Expand Up @@ -141,35 +139,35 @@ public void testGetCoordinates() throws Exception {
double[] result;
result = new double[2];
testSeq2D.getCoordinates(0, result);
assertTrue(Arrays.equals(new double[]{0, 0}, result));
assertArrayEquals(new double[]{0, 0}, result, 0.0);
testSeq2D.getCoordinates(1, result);
assertTrue(Arrays.equals(new double[]{1, -1}, result));
assertArrayEquals(new double[]{1, -1}, result, 0.0);
testSeq2D.getCoordinates(2, result);
assertTrue(Arrays.equals(new double[]{2, -2}, result));
assertArrayEquals(new double[]{2, -2}, result, 0.0);

result = new double[3];
testSeq3D.getCoordinates(0, result);
assertTrue(Arrays.equals(new double[]{0, 0, 0}, result));
assertArrayEquals(new double[]{0, 0, 0}, result, 0.0);
testSeq3D.getCoordinates(1, result);
assertTrue(Arrays.equals(new double[]{1, -1, 1}, result));
assertArrayEquals(new double[]{1, -1, 1}, result, 0.0);
testSeq3D.getCoordinates(2, result);
assertTrue(Arrays.equals(new double[]{2, -2, 2}, result));
assertArrayEquals(new double[]{2, -2, 2}, result, 0.0);


testSeq2DM.getCoordinates(0, result);
assertTrue(Arrays.equals(new double[]{0, 0, 0}, result));
assertArrayEquals(new double[]{0, 0, 0}, result, 0.0);
testSeq2DM.getCoordinates(1, result);
assertTrue(Arrays.equals(new double[]{1, -1, 1}, result));
assertArrayEquals(new double[]{1, -1, 1}, result, 0.0);
testSeq2DM.getCoordinates(2, result);
assertTrue(Arrays.equals(new double[]{2, -2, 2}, result));
assertArrayEquals(new double[]{2, -2, 2}, result, 0.0);

result = new double[4];
testSeq3DM.getCoordinates(0, result);
assertTrue(Arrays.equals(new double[]{0, 0, 0, 1}, result));
assertArrayEquals(new double[]{0, 0, 0, 1}, result, 0.0);
testSeq3DM.getCoordinates(1, result);
assertTrue(Arrays.equals(new double[]{1, -1, 1, 2}, result));
assertArrayEquals(new double[]{1, -1, 1, 2}, result, 0.0);
testSeq3DM.getCoordinates(2, result);
assertTrue(Arrays.equals(new double[]{2, -2, 2, 3}, result));
assertArrayEquals(new double[]{2, -2, 2, 3}, result, 0.0);

try {
testSeq2D.getCoordinates(3, result);
Expand Down Expand Up @@ -369,12 +367,11 @@ public void testGetOrdinate() {

@Test
public void testEquals() {
assertEquals(testSeq2D, new PackedPositionSequence<C2D>(des2D, new double[]{0, 0, 1, -1, 2, -2}));
assertEquals(testSeq3D, new PackedPositionSequence<C3D>(des3D, new double[]{0, 0, 0, 1, -1, 1, 2, -2, 2}));
assertEquals(testSeq2DM, new PackedPositionSequence<C2DM>(des2DM, new double[]{0, 0, 0, 1, -1, 1, 2, -2, 2}));
assertEquals(testSeq3DM, new PackedPositionSequence<C3DM>(des3DM, new double[]{0, 0, 0, 1, 1, -1, 1, 2, 2, -2, 2, 3}));
assertFalse(testSeq2DM.equals(testSeq3D));
assertFalse(testSeq2D.equals(new PackedPositionSequence<C2D>(des2D, new double[]{0, 1, 1, -1, 2, -2})));
assertEquals(testSeq2D, new PackedPositionSequence<>(des2D, new double[]{0, 0, 1, -1, 2, -2}));
assertEquals(testSeq3D, new PackedPositionSequence<>(des3D, new double[]{0, 0, 0, 1, -1, 1, 2, -2, 2}));
assertEquals(testSeq2DM, new PackedPositionSequence<>(des2DM, new double[]{0, 0, 0, 1, -1, 1, 2, -2, 2}));
assertEquals(testSeq3DM, new PackedPositionSequence<>(des3DM, new double[]{0, 0, 0, 1, 1, -1, 1, 2, 2, -2, 2, 3}));
assertNotEquals(testSeq2D, new PackedPositionSequence<>(des2D, new double[]{0, 1, 1, -1, 2, -2}));

}

Expand All @@ -389,9 +386,9 @@ public void testClone() {

@Test
public void testCloneReturnsIndependentCopy() {
PositionSequence clone = testSeq2D.clone();
((CoordinateSequence)testSeq2D).setOrdinate(0, 0, 3);
Assert.assertFalse(testSeq2D.equals(clone));
PositionSequence<?> clone = testSeq2D.clone();
((CoordinateSequence) testSeq2D).setOrdinate(0, 0, 3);
assertNotEquals(testSeq2D, clone);
}


Expand Down

0 comments on commit 8c09e92

Please sign in to comment.