Skip to content
Permalink
Browse files
adding missing test cases
  • Loading branch information
darkma773r committed Aug 13, 2021
1 parent 4430e82 commit ccb1cbea5fbb64e5fa03b1607a196e9a35918813
Showing 5 changed files with 178 additions and 3 deletions.
@@ -19,6 +19,7 @@
import java.util.List;

import org.apache.commons.geometry.core.GeometryTestUtils;
import org.apache.commons.geometry.core.RegionLocation;
import org.apache.commons.geometry.core.partitioning.Split;
import org.apache.commons.geometry.core.partitioning.SplitLocation;
import org.apache.commons.geometry.euclidean.EuclideanTestUtils;
@@ -508,6 +509,68 @@ void testTransform_reflection() {
checkFiniteSegment(transformedSegments.get(0), Vector2D.of(0, 2), Vector2D.of(-1, 2));
}

@Test
void testClosest() {
// arrange
final RegionBSPTree1D subRegion = RegionBSPTree1D.empty();
subRegion.add(Interval.of(0, 2, TEST_PRECISION));
subRegion.add(Interval.of(3, 4, TEST_PRECISION));

final Line line = Lines.fromPointAndAngle(Vector2D.of(0, 2), 0.0, TEST_PRECISION);
final EmbeddedTreeLineSubset subset = new EmbeddedTreeLineSubset(line, subRegion);

// act/assert
EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(0, 2), subset.closest(Vector2D.of(0, 1)), TEST_EPS);
EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(0, 2), subset.closest(Vector2D.of(0, 3)), TEST_EPS);

EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(1, 2), subset.closest(Vector2D.of(1, 1)), TEST_EPS);
EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(1, 2), subset.closest(Vector2D.of(1, 3)), TEST_EPS);

EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(2, 2), subset.closest(Vector2D.of(2, 1)), TEST_EPS);
EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(2, 2), subset.closest(Vector2D.of(2, 3)), TEST_EPS);

EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(2, 2), subset.closest(Vector2D.of(2.4, 1)), TEST_EPS);
EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(2, 2), subset.closest(Vector2D.of(2.4, 3)), TEST_EPS);

EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(3, 2), subset.closest(Vector2D.of(2.6, 1)), TEST_EPS);
EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(3, 2), subset.closest(Vector2D.of(2.6, 3)), TEST_EPS);

EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(4, 2), subset.closest(Vector2D.of(5, 1)), TEST_EPS);
EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(4, 2), subset.closest(Vector2D.of(5, 3)), TEST_EPS);
}

@Test
void testClosest_empty() {
// arrange
final Line line = Lines.fromPointAndAngle(Vector2D.ZERO, 0.0, TEST_PRECISION);
final EmbeddedTreeLineSubset subset = new EmbeddedTreeLineSubset(line, RegionBSPTree1D.empty());

// act/assert
Assertions.assertNull(subset.closest(Vector2D.ZERO));
}

@Test
void testClassify() {
// arrange
final RegionBSPTree1D subRegion = RegionBSPTree1D.empty();
subRegion.add(Interval.of(0, 2, TEST_PRECISION));
subRegion.add(Interval.of(3, 4, TEST_PRECISION));

final Line line = Lines.fromPointAndAngle(Vector2D.of(0, 2), 0.0, TEST_PRECISION);
final EmbeddedTreeLineSubset subset = new EmbeddedTreeLineSubset(line, subRegion);

// act/assert
EuclideanTestUtils.assertRegionLocation(subset, RegionLocation.INSIDE,
Vector2D.of(1, 2), Vector2D.of(3.5, 2));

EuclideanTestUtils.assertRegionLocation(subset, RegionLocation.BOUNDARY,
Vector2D.of(0, 2), Vector2D.of(2, 2), Vector2D.of(3, 2), Vector2D.of(4, 2));

EuclideanTestUtils.assertRegionLocation(subset, RegionLocation.OUTSIDE,
Vector2D.of(-1, 2), Vector2D.of(2.5, 2), Vector2D.of(5, 2),
Vector2D.of(1, 3), Vector2D.of(3.5, 1));
}

@Test
void testToString() {
// arrange
@@ -1097,7 +1097,7 @@ void testBuilder_prependAndAppend_addingToInfinitePath() {

// act/assert
Assertions.assertThrows(IllegalStateException.class, () -> builder.prepend(p));
Assertions.assertThrows(IllegalStateException.class, () -> builder.prepend(p));
Assertions.assertThrows(IllegalStateException.class, () -> builder.append(p));
}

@Test
@@ -22,6 +22,7 @@

import org.apache.commons.geometry.euclidean.threed.Vector3D;
import org.apache.commons.geometry.spherical.SphericalTestUtils;
import org.apache.commons.geometry.spherical.twod.AbstractGreatArcConnector.ConnectableGreatArc;
import org.apache.commons.numbers.angle.Angle;
import org.apache.commons.numbers.core.Precision;
import org.junit.jupiter.api.Assertions;
@@ -259,6 +260,46 @@ void testConnect() {
assertPathPoints(b, Point2S.PLUS_J, Point2S.PLUS_K);
}

@Test
void testConnectableSegment_hashCode() {
// arrange
final GreatArc arcA = GreatCircles.arcFromPoints(Point2S.PLUS_I, Point2S.PLUS_J, TEST_PRECISION);
final GreatArc arcB = GreatCircles.arcFromPoints(Point2S.PLUS_J, Point2S.MINUS_I, TEST_PRECISION);

final ConnectableGreatArc a = new ConnectableGreatArc(arcA);

// act
final int hash = a.hashCode();

// assert
Assertions.assertEquals(hash, a.hashCode());

Assertions.assertNotEquals(hash, new ConnectableGreatArc(arcB).hashCode());
Assertions.assertNotEquals(hash, new ConnectableGreatArc(Point2S.MINUS_I).hashCode());

Assertions.assertEquals(hash, new ConnectableGreatArc(arcA).hashCode());
}

@Test
void testConnectableSegment_equals() {
// arrange
final GreatArc arcA = GreatCircles.arcFromPoints(Point2S.PLUS_I, Point2S.PLUS_J, TEST_PRECISION);
final GreatArc arcB = GreatCircles.arcFromPoints(Point2S.PLUS_J, Point2S.MINUS_I, TEST_PRECISION);

final ConnectableGreatArc a = new ConnectableGreatArc(arcA);

// act/assert
Assertions.assertEquals(a, a);

Assertions.assertFalse(a.equals(null));
Assertions.assertFalse(a.equals(new Object()));

Assertions.assertNotEquals(a, new ConnectableGreatArc(arcB));
Assertions.assertNotEquals(a, new ConnectableGreatArc(Point2S.MINUS_I));

Assertions.assertEquals(a, new ConnectableGreatArc(arcA));
}

@Test
void testConnectorCanBeReused() {
// arrange
@@ -26,14 +26,14 @@
import org.apache.commons.geometry.euclidean.threed.Vector3D;
import org.apache.commons.geometry.spherical.SphericalTestUtils;
import org.apache.commons.geometry.spherical.oned.AngularInterval;
import org.apache.commons.geometry.spherical.oned.Point1S;
import org.apache.commons.geometry.spherical.oned.RegionBSPTree1S;
import org.apache.commons.numbers.angle.Angle;
import org.apache.commons.numbers.core.Precision;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;


class EmbeddedTreeSubGreatCircleTest {
class EmbeddedTreeSubGreatCircleTest {

private static final double TEST_EPS = 1e-10;

@@ -49,6 +49,8 @@ void testCtor_default() {
final EmbeddedTreeGreatCircleSubset sub = new EmbeddedTreeGreatCircleSubset(XY_CIRCLE);

// assert
Assertions.assertSame(XY_CIRCLE, sub.getHyperplane());
Assertions.assertSame(TEST_PRECISION, sub.getPrecision());
Assertions.assertFalse(sub.isFull());
Assertions.assertTrue(sub.isEmpty());
Assertions.assertTrue(sub.isFinite());
@@ -136,6 +138,53 @@ void testCtor_tree() {
Point2S.of(1.5, 1), Point2S.of(1.5, Math.PI - 1));
}

@Test
void testToSubspace() {
// arrange
final EmbeddedTreeGreatCircleSubset sub = new EmbeddedTreeGreatCircleSubset(XY_CIRCLE);

// act/assert
SphericalTestUtils.assertPointsEqual(Point1S.of(1), sub.toSubspace(Point2S.of(1, 0.5)), TEST_EPS);
SphericalTestUtils.assertPointsEqual(Point1S.of(1), sub.toSubspace(Point2S.of(1, 0.75)), TEST_EPS);
}

@Test
void testToSpace() {
// arrange
final EmbeddedTreeGreatCircleSubset sub = new EmbeddedTreeGreatCircleSubset(XY_CIRCLE);

// act/assert
SphericalTestUtils.assertPointsEqual(Point2S.of(0, 0.5 * Math.PI), sub.toSpace(Point1S.of(0)), TEST_EPS);
SphericalTestUtils.assertPointsEqual(Point2S.of(1, 0.5 * Math.PI), sub.toSpace(Point1S.of(1)), TEST_EPS);
}

@Test
void testClosest() {
// arrange
final RegionBSPTree1S tree = RegionBSPTree1S.fromInterval(AngularInterval.of(1, 2, TEST_PRECISION));
final EmbeddedTreeGreatCircleSubset sub = new EmbeddedTreeGreatCircleSubset(XY_CIRCLE, tree);

final double halfPi = 0.5 * Math.PI;
final double above = halfPi - 0.1;
final double below = halfPi + 0.1;

// act/assert
SphericalTestUtils.assertPointsEq(Point2S.of(1, halfPi), sub.closest(Point2S.of(0, above)), TEST_EPS);
SphericalTestUtils.assertPointsEq(Point2S.of(1, halfPi), sub.closest(Point2S.of(0, below)), TEST_EPS);

SphericalTestUtils.assertPointsEq(Point2S.of(1, halfPi), sub.closest(Point2S.of(1, above)), TEST_EPS);
SphericalTestUtils.assertPointsEq(Point2S.of(1, halfPi), sub.closest(Point2S.of(1, below)), TEST_EPS);

SphericalTestUtils.assertPointsEq(Point2S.of(1.5, halfPi), sub.closest(Point2S.of(1.5, above)), TEST_EPS);
SphericalTestUtils.assertPointsEq(Point2S.of(1.5, halfPi), sub.closest(Point2S.of(1.5, below)), TEST_EPS);

SphericalTestUtils.assertPointsEq(Point2S.of(2, halfPi), sub.closest(Point2S.of(2, above)), TEST_EPS);
SphericalTestUtils.assertPointsEq(Point2S.of(2, halfPi), sub.closest(Point2S.of(2, below)), TEST_EPS);

SphericalTestUtils.assertPointsEq(Point2S.of(2, halfPi), sub.closest(Point2S.of(3, above)), TEST_EPS);
SphericalTestUtils.assertPointsEq(Point2S.of(2, halfPi), sub.closest(Point2S.of(3, below)), TEST_EPS);
}

@Test
void testTransform() {
// arrange
@@ -171,6 +171,28 @@ void testToConvex() {
Assertions.assertSame(arc, result.get(0));
}

@Test
void testGetMidPoint() {
// arrange
final GreatArc arc = GreatCircles.arcFromInterval(
GreatCircles.fromPoints(Point2S.PLUS_I, Point2S.PLUS_J, TEST_PRECISION),
AngularInterval.Convex.of(0.8 * Math.PI, 0.9 * Math.PI, TEST_PRECISION));

// act/assert
SphericalTestUtils.assertPointsEqual(Point2S.of(0.85 * Math.PI, 0.5 * Math.PI), arc.getMidPoint(), TEST_EPS);
}

@Test
void testGetMidPoint_full() {
// arrange
final GreatArc arc = GreatCircles.arcFromInterval(
GreatCircles.fromPoints(Point2S.PLUS_I, Point2S.PLUS_J, TEST_PRECISION),
AngularInterval.full());

// act/assert
Assertions.assertNull(arc.getMidPoint());
}

@Test
void testReverse_full() {
// arrange

0 comments on commit ccb1cbe

Please sign in to comment.