diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry')
5 files changed, 0 insertions, 1325 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java deleted file mode 100644 index 6c44c29e3b..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java +++ /dev/null @@ -1,813 +0,0 @@ -package com.mapbox.mapboxsdk.geometry; - -import android.os.Parcelable; -import com.mapbox.mapboxsdk.constants.GeometryConstants; -import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException; -import com.mapbox.mapboxsdk.utils.MockParcel; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import java.util.ArrayList; -import java.util.List; - -import static junit.framework.Assert.assertNotNull; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -public class LatLngBoundsTest { - - private static final double DELTA = 1e-15; - - private LatLngBounds latLngBounds; - private static final LatLng LAT_LNG_NULL_ISLAND = new LatLng(0, 0); - private static final LatLng LAT_LNG_NOT_NULL_ISLAND = new LatLng(2, 2); - - @Before - public void beforeTest() { - latLngBounds = new LatLngBounds.Builder() - .include(LAT_LNG_NULL_ISLAND) - .include(LAT_LNG_NOT_NULL_ISLAND) - .build(); - } - - @Test - public void testSanity() { - LatLngBounds.Builder latLngBoundsBuilder = new LatLngBounds.Builder(); - latLngBoundsBuilder.include(LAT_LNG_NULL_ISLAND).include(LAT_LNG_NOT_NULL_ISLAND); - assertNotNull("latLng should not be null", latLngBoundsBuilder.build()); - } - - @Test(expected = InvalidLatLngBoundsException.class) - public void noLatLngs() { - new LatLngBounds.Builder().build(); - } - - @Test(expected = InvalidLatLngBoundsException.class) - public void oneLatLngs() { - new LatLngBounds.Builder().include(LAT_LNG_NULL_ISLAND).build(); - } - - @Test - public void latitiudeSpan() { - assertEquals("Span should be the same", 2, latLngBounds.getLatitudeSpan(), DELTA); - } - - @Test - public void longitudeSpan() { - assertEquals("Span should be the same", 2, latLngBounds.getLongitudeSpan(), DELTA); - } - - @Test - public void coordinateSpan() { - LatLngSpan latLngSpan = latLngBounds.getSpan(); - assertEquals("LatLngSpan should be the same", new LatLngSpan(2, 2), latLngSpan); - } - - @Test - public void dateLineSpanBuilder1() { - latLngBounds = new LatLngBounds.Builder() - .include(new LatLng(10, -170)) - .include(new LatLng(-10, 170)) - .build(); - - LatLngSpan latLngSpan = latLngBounds.getSpan(); - assertEquals("LatLngSpan should be the same", new LatLngSpan(20, 340), - latLngSpan); - } - - @Test - public void dateLineSpanBuilder2() { - latLngBounds = new LatLngBounds.Builder() - .include(new LatLng(-10, -170)) - .include(new LatLng(10, 170)) - .build(); - - LatLngSpan latLngSpan = latLngBounds.getSpan(); - assertEquals("LatLngSpan should be the same", new LatLngSpan(20, 340), - latLngSpan); - } - - @Test - public void dateLineSpanFrom1() { - latLngBounds = LatLngBounds.from(10, -170, -10, -190); - LatLngSpan latLngSpan = latLngBounds.getSpan(); - assertEquals("LatLngSpan should be the same", new LatLngSpan(20, 20), - latLngSpan); - } - - @Test - public void dateLineSpanFrom2() { - latLngBounds = LatLngBounds.from(10, 170, -10, -170); - LatLngSpan latLngSpan = latLngBounds.getSpan(); - assertEquals("LatLngSpan should be the same", new LatLngSpan(20, 340), - latLngSpan); - } - - @Test - public void zeroLongitudeSpan() { - latLngBounds = LatLngBounds.from(10, 10, -10, 10); - LatLngSpan latLngSpan = latLngBounds.getSpan(); - assertEquals("LatLngSpan should be shortest distance", new LatLngSpan(20, 0), - latLngSpan); - } - - @Test - public void nearDateLineCenter1() { - latLngBounds = LatLngBounds.from(10, -175, -10, -195); - LatLng center = latLngBounds.getCenter(); - assertEquals("Center should match", new LatLng(0, -185), center); - } - - @Test - public void nearDateLineCenter2() { - latLngBounds = LatLngBounds.from(10, 195, -10, 175); - LatLng center = latLngBounds.getCenter(); - assertEquals("Center should match", new LatLng(0, 185), center); - } - - @Test - public void nearDateLineCenter3() { - latLngBounds = LatLngBounds.from(10, -170, -10, -190); - LatLng center = latLngBounds.getCenter(); - assertEquals("Center should match", new LatLng(0, -180), center); - } - - @Test - public void nearDateLineCenter4() { - latLngBounds = LatLngBounds.from(10, 180, -10, 0); - LatLng center = latLngBounds.getCenter(); - assertEquals("Center should match", new LatLng(0, 90), center); - } - - @Test - public void nearDateLineCenter5() { - latLngBounds = LatLngBounds.from(10, 180, -10, 0); - LatLng center = latLngBounds.getCenter(); - assertEquals("Center should match", new LatLng(0, 90), center); - } - - @Test - public void centerForBoundsWithSameLongitude() { - latLngBounds = LatLngBounds.from(10, 10, -10, 10); - LatLng center = latLngBounds.getCenter(); - assertEquals("Center should match", new LatLng(0, 10), center); - } - - @Test - public void centerForBoundsWithSameLatitude() { - latLngBounds = LatLngBounds.from(10, 10, 10, -10); - LatLng center = latLngBounds.getCenter(); - assertEquals("Center should match", new LatLng(10, 0), center); - } - - @Test - public void center() { - LatLng center = latLngBounds.getCenter(); - assertEquals("Center should match", new LatLng(1, 1), center); - } - - @Test - public void notEmptySpan() { - latLngBounds = new LatLngBounds.Builder() - .include(LAT_LNG_NOT_NULL_ISLAND) - .include(LAT_LNG_NULL_ISLAND) - .build(); - assertFalse("Should not be empty", latLngBounds.isEmptySpan()); - } - - @Test - public void includeSameLatLngs() { - latLngBounds = new LatLngBounds.Builder() - .include(LAT_LNG_NOT_NULL_ISLAND) - .include(LAT_LNG_NOT_NULL_ISLAND) - .include(LAT_LNG_NULL_ISLAND) - .include(LAT_LNG_NULL_ISLAND) - .build(); - assertEquals(latLngBounds.getNorthEast(), LAT_LNG_NOT_NULL_ISLAND); - assertEquals(latLngBounds.getSouthWest(), LAT_LNG_NULL_ISLAND); - } - - @Test - public void toLatLngs() { - latLngBounds = new LatLngBounds.Builder() - .include(LAT_LNG_NOT_NULL_ISLAND) - .include(LAT_LNG_NULL_ISLAND) - .build(); - - assertArrayEquals("LatLngs should match", - new LatLng[] {LAT_LNG_NOT_NULL_ISLAND, LAT_LNG_NULL_ISLAND}, - latLngBounds.toLatLngs()); - } - - @Test - public void include() { - assertTrue("LatLng should be included", latLngBounds.contains(new LatLng(1, 1))); - } - - @Test - public void includes() { - List<LatLng> points = new ArrayList<>(); - points.add(LAT_LNG_NULL_ISLAND); - points.add(LAT_LNG_NOT_NULL_ISLAND); - - LatLngBounds latLngBounds1 = new LatLngBounds.Builder() - .includes(points) - .build(); - - LatLngBounds latLngBounds2 = new LatLngBounds.Builder() - .include(LAT_LNG_NULL_ISLAND) - .include(LAT_LNG_NOT_NULL_ISLAND) - .build(); - - assertEquals("LatLngBounds should match", latLngBounds1, latLngBounds2); - } - - @Test - public void includesOrderDoesNotMatter() { - LatLngBounds sameLongitudeFirst = new LatLngBounds.Builder() - .include(new LatLng(50, 10)) // southWest - .include(new LatLng(60, 10)) - .include(new LatLng(60, 20)) // northEast - .include(new LatLng(50, 20)) - .include(new LatLng(50, 10)) // southWest again - .build(); - - LatLngBounds sameLatitudeFirst = new LatLngBounds.Builder() - .include(new LatLng(50, 20)) - .include(new LatLng(50, 10)) // southWest - .include(new LatLng(60, 10)) - .include(new LatLng(60, 20)) // northEast - .include(new LatLng(50, 20)) - .build(); - - assertEquals(sameLatitudeFirst, sameLongitudeFirst); - } - - @Test - public void includesOverDateline1() { - - LatLngBounds latLngBounds = new LatLngBounds.Builder() - .include(new LatLng(10, -170)) - .include(new LatLng(-10, -175)) - .include(new LatLng(0, -190)) - .build(); - - LatLngSpan latLngSpan = latLngBounds.getSpan(); - assertEquals("LatLngSpan should be the same", - new LatLngSpan(20, 20), latLngSpan); - } - - @Test - public void includesOverDateline2() { - - LatLngBounds latLngBounds = new LatLngBounds.Builder() - .include(new LatLng(10, 170)) - .include(new LatLng(-10, 175)) - .include(new LatLng(0, 190)) - .build(); - - assertEquals("LatLngSpan should be the same", - new LatLngSpan(20, 20), latLngBounds.getSpan()); - } - - @Test - public void includesOverDateline3() { - - LatLngBounds latLngBounds = new LatLngBounds.Builder() - .include(new LatLng(10, -190)) - .include(new LatLng(-10, -170)) - .include(new LatLng(0, -180)) - .include(new LatLng(5, -180)) - .build(); - - assertEquals("LatLngSpan should be the same", - new LatLngSpan(20, 20), latLngBounds.getSpan()); - } - - @Test - public void containsNot() { - assertFalse("LatLng should not be included", - latLngBounds.contains(new LatLng(3, 1))); - } - - @Test - public void containsBoundsInWorld() { - assertTrue("LatLngBounds should be contained in the world", - LatLngBounds.world().contains(latLngBounds)); - } - - @Test - public void worldSpan() { - assertEquals("LatLngBounds world span should be 180, 360", - GeometryConstants.LATITUDE_SPAN, LatLngBounds.world().getLatitudeSpan(), DELTA); - assertEquals("LatLngBounds world span should be 180, 360", - GeometryConstants.LONGITUDE_SPAN, LatLngBounds.world().getLongitudeSpan(), DELTA); - } - - @Test - public void emptySpan() { - LatLngBounds latLngBounds = LatLngBounds.from( - GeometryConstants.MIN_LATITUDE, GeometryConstants.MAX_LONGITUDE, - GeometryConstants.MIN_LATITUDE, GeometryConstants.MAX_LONGITUDE); - assertTrue("LatLngBounds empty span", latLngBounds.isEmptySpan()); - } - - @Test - public void containsBounds() { - LatLngBounds inner = new LatLngBounds.Builder() - .include(new LatLng(-5, -5)) - .include(new LatLng(5, 5)) - .build(); - LatLngBounds outer = new LatLngBounds.Builder() - .include(new LatLng(-10, -10)) - .include(new LatLng(10, 10)) - .build(); - assertTrue(outer.contains(inner)); - assertFalse(inner.contains(outer)); - } - - @Test - public void testHashCode() { - assertEquals(2147483647, latLngBounds.hashCode(), -1946419200); - } - - @Test - public void equality() { - LatLngBounds latLngBounds = new LatLngBounds.Builder() - .include(LAT_LNG_NULL_ISLAND) - .include(LAT_LNG_NOT_NULL_ISLAND) - .build(); - assertEquals("equality should match", this.latLngBounds, latLngBounds); - assertEquals("not equal to a different object type", - this.latLngBounds.equals(LAT_LNG_NOT_NULL_ISLAND), false); - } - - @Test - public void testToString() { - assertEquals(latLngBounds.toString(), "N:2.0; E:2.0; S:0.0; W:0.0"); - } - - @Test - public void intersect() { - LatLngBounds latLngBounds = new LatLngBounds.Builder() - .include(new LatLng(1, 1)) - .include(LAT_LNG_NULL_ISLAND) - .build(); - assertEquals("intersect should match", latLngBounds, - latLngBounds.intersect(this.latLngBounds.getLatNorth(), - this.latLngBounds.getLonEast(), - this.latLngBounds.getLatSouth(), - this.latLngBounds.getLonWest())); - } - - @Test - public void intersectNot() { - LatLngBounds latLngBounds = new LatLngBounds.Builder() - .include(new LatLng(10, 10)) - .include(new LatLng(9, 8)) - .build(); - assertNull(latLngBounds.intersect(this.latLngBounds)); - } - - @Test - public void intersectNorthCheck() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("latitude must be between -90 and 90"); - LatLngBounds intersectLatLngBounds = - LatLngBounds.from(10, 10, 0, 0) - .intersect(200, 200, 0, 0); - } - - @Test - public void intersectSouthCheck() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("latitude must be between -90 and 90"); - LatLngBounds intersectLatLngBounds = - LatLngBounds.from(0, 0, -10, -10) - .intersect(0, 0, -200, -200); - } - - @Test - public void intersectSouthLessThanNorthCheck() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("latNorth cannot be less than latSouth"); - LatLngBounds intersectLatLngBounds = - LatLngBounds.from(10, 10, 0, 0) - .intersect(0, 200, 20, 0); - } - - @Test - public void intersectEastLessThanWestCheck() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("lonEast cannot be less than lonWest"); - LatLngBounds intersectLatLngBounds = - LatLngBounds.from(10, -10, 0, 0) - .intersect(0, 200, 20, 0); - } - - public void intersectEastDoesNotWrapCheck() { - - LatLngBounds latLngBounds1 = LatLngBounds.from(10, 210, 0, 0); - LatLngBounds latLngBounds2 = LatLngBounds.from(90, 200, 0, 0); - - LatLngBounds intersectLatLngBounds = LatLngBounds.from(10, 200, 0, 0); - - assertEquals(latLngBounds1.intersect(latLngBounds2), intersectLatLngBounds); - assertEquals(latLngBounds2.intersect(latLngBounds1), intersectLatLngBounds); - } - - @Test - public void intersectDoesNotWestWrapCheck() { - LatLngBounds latLngBounds1 = LatLngBounds.from(0, 0, -10, -210); - LatLngBounds latLngBounds2 = LatLngBounds.from(0, 0, -90, -200); - - LatLngBounds intersectLatLngBounds = LatLngBounds.from(0, 0, -10, -200); - - assertEquals(latLngBounds1.intersect(latLngBounds2), intersectLatLngBounds); - assertEquals(latLngBounds2.intersect(latLngBounds1), intersectLatLngBounds); - } - - @Test - public void innerUnion() { - LatLngBounds latLngBounds = new LatLngBounds.Builder() - .include(new LatLng(1, 1)) - .include(LAT_LNG_NULL_ISLAND) - .build(); - assertEquals("union should match", latLngBounds, latLngBounds.intersect(this.latLngBounds)); - } - - @Test - public void outerUnion() { - LatLngBounds latLngBounds = new LatLngBounds.Builder() - .include(new LatLng(10, 10)) - .include(new LatLng(9, 8)) - .build(); - assertEquals("outer union should match", - latLngBounds.union(this.latLngBounds), - new LatLngBounds.Builder() - .include(new LatLng(10, 10)) - .include(LAT_LNG_NULL_ISLAND) - .build()); - } - - @Test - public void unionOverDateLine() { - LatLngBounds latLngBounds1 = new LatLngBounds.Builder() - .include(new LatLng(10, 170)) - .include(new LatLng(0, 160)) - .build(); - - LatLngBounds latLngBounds2 = new LatLngBounds.Builder() - .include(new LatLng(0, 190)) - .include(new LatLng(-10, 200)) - .build(); - - LatLngBounds union1 = latLngBounds1.union(latLngBounds2); - LatLngBounds union2 = latLngBounds2.union(latLngBounds1); - - assertEquals(union1, - new LatLngBounds.Builder() - .include(new LatLng(10, 160)) - .include(new LatLng(-10, 200)) - .build()); - - assertEquals(union1, union2); - } - - @Test - public void unionOverDateLine2() { - LatLngBounds latLngBounds1 = new LatLngBounds.Builder() - .include(new LatLng(10, 170)) - .include(new LatLng(0, 160)) - .build(); - - LatLngBounds latLngBounds2 = new LatLngBounds.Builder() - .include(new LatLng(0, 165)) - .include(new LatLng(-10, 200)) - .build(); - - LatLngBounds union1 = latLngBounds1.union(latLngBounds2); - LatLngBounds union2 = latLngBounds2.union(latLngBounds1); - - assertEquals(union1, - new LatLngBounds.Builder() - .include(new LatLng(10, 160)) - .include(new LatLng(-10, 200)) - .build()); - - assertEquals(union1, union2); - } - - @Test - public void unionOverDateLine3() { - LatLngBounds latLngBounds1 = new LatLngBounds.Builder() - .include(new LatLng(10, 195)) - .include(new LatLng(0, 160)) - .build(); - - LatLngBounds latLngBounds2 = new LatLngBounds.Builder() - .include(new LatLng(0, 190)) - .include(new LatLng(-10, 200)) - .build(); - - LatLngBounds union1 = latLngBounds1.union(latLngBounds2); - LatLngBounds union2 = latLngBounds2.union(latLngBounds1); - - assertEquals(union1, - new LatLngBounds.Builder() - .include(new LatLng(10, 160)) - .include(new LatLng(-10, 200)) - .build()); - - assertEquals(union1, union2); - } - - @Test - public void unionOverDateLine4() { - LatLngBounds latLngBounds1 = new LatLngBounds.Builder() - .include(new LatLng(10, -160)) - .include(new LatLng(0, -200)) - .build(); - - LatLngBounds latLngBounds2 = new LatLngBounds.Builder() - .include(new LatLng(0, -170)) - .include(new LatLng(-10, -175)) - .build(); - - LatLngBounds union1 = latLngBounds1.union(latLngBounds2); - LatLngBounds union2 = latLngBounds2.union(latLngBounds1); - - assertEquals(union1, - new LatLngBounds.Builder() - .include(new LatLng(10, -200)) - .include(new LatLng(-10, -160)) - .build()); - - assertEquals(union1, union2); - } - - @Test - public void unionOverDateLine5() { - LatLngBounds latLngBounds1 = new LatLngBounds.Builder() - .include(new LatLng(10, 200)) - .include(new LatLng(0, 160)) - .build(); - - LatLngBounds latLngBounds2 = new LatLngBounds.Builder() - .include(new LatLng(0, 170)) - .include(new LatLng(-10, 175)) - .build(); - - LatLngBounds union1 = latLngBounds1.union(latLngBounds2); - LatLngBounds union2 = latLngBounds2.union(latLngBounds1); - - assertEquals(union1, - new LatLngBounds.Builder() - .include(new LatLng(10, 160)) - .include(new LatLng(-10, 200)) - .build()); - - assertEquals(union1, union2); - } - - @Test - public void unionOverDateLineReturnLongerThanWorldLonSpan() { - LatLngBounds latLngBounds1 = LatLngBounds.from(10, 200, -10, -10); - LatLngBounds latLngBounds2 = LatLngBounds.from(10, 10, -10, -200); - - LatLngBounds union1 = latLngBounds1.union(latLngBounds2); - LatLngBounds union2 = latLngBounds2.union(latLngBounds1); - - assertEquals(union1, union2); - assertEquals(union1, LatLngBounds.from(10, 200, -10, -200)); - } - - @Test - public void unionNorthCheck() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("latitude must be between -90 and 90"); - LatLngBounds unionLatLngBounds = - LatLngBounds.from(10, 10, 0, 0) - .union(200, 200, 0, 0); - } - - @Test - public void unionSouthCheck() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("latitude must be between -90 and 90"); - LatLngBounds unionLatLngBounds = - LatLngBounds.from(0, 0, -10, -10) - .union(0, 0, -200, -200); - } - - @Test - public void unionSouthLessThanNorthCheck() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("latNorth cannot be less than latSouth"); - - LatLngBounds unionLatLngBounds = - LatLngBounds.from(10, 10, 0, 0) - .union(0, 200, 20, 0); - } - - - @Test - public void unionEastDoesNotWrapCheck() { - - LatLngBounds latLngBounds1 = LatLngBounds.from(10, 10, 0, 0); - LatLngBounds latLngBounds2 = LatLngBounds.from(90, 200, 0, 0); - LatLngBounds unionLatLngBounds = LatLngBounds.from(90, 200, 0, 0); - - assertEquals(latLngBounds1.union(latLngBounds2), unionLatLngBounds); - assertEquals(latLngBounds2.union(latLngBounds1), unionLatLngBounds); - } - - @Test - public void unionWestDoesNotWrapCheck() { - LatLngBounds latLngBounds1 = LatLngBounds.from(0, 0, -10, -10); - LatLngBounds latLngBounds2 = LatLngBounds.from(0, 0, -90, -200); - - LatLngBounds unionLatLngBounds = LatLngBounds.from(0, 0, -90, -200); - - assertEquals(latLngBounds1.union(latLngBounds2), unionLatLngBounds); - assertEquals(latLngBounds2.union(latLngBounds1), unionLatLngBounds); - } - - @Test - public void northWest() { - double minLat = 5; - double minLon = 6; - double maxLat = 20; - double maxLon = 21; - - LatLngBounds latLngBounds = new LatLngBounds.Builder() - .include(new LatLng(minLat, minLon)) - .include(new LatLng(maxLat, maxLon)) - .build(); - - assertEquals("NorthWest should match", latLngBounds.getNorthWest(), new LatLng(maxLat, minLon)); - } - - @Test - public void southWest() { - double minLat = 5; - double minLon = 6; - double maxLat = 20; - double maxLon = 21; - - LatLngBounds latLngBounds = new LatLngBounds.Builder() - .include(new LatLng(minLat, minLon)) - .include(new LatLng(maxLat, maxLon)) - .build(); - - assertEquals("SouthWest should match", latLngBounds.getSouthWest(), new LatLng(minLat, minLon)); - } - - @Test - public void northEast() { - double minLat = 5; - double minLon = 6; - double maxLat = 20; - double maxLon = 21; - - LatLngBounds latLngBounds = new LatLngBounds.Builder() - .include(new LatLng(minLat, minLon)) - .include(new LatLng(maxLat, maxLon)) - .build(); - - assertEquals("NorthEast should match", latLngBounds.getNorthEast(), new LatLng(maxLat, maxLon)); - } - - @Test - public void southEast() { - double minLat = 5; - double minLon = 6; - double maxLat = 20; - double maxLon = 21; - - LatLngBounds latLngBounds = new LatLngBounds.Builder() - .include(new LatLng(minLat, minLon)) - .include(new LatLng(maxLat, maxLon)) - .build(); - - assertEquals("SouthEast should match", latLngBounds.getSouthEast(), new LatLng(minLat, maxLon)); - } - - @Test - public void testParcelable() { - LatLngBounds latLngBounds = new LatLngBounds.Builder() - .include(new LatLng(10, 10)) - .include(new LatLng(9, 8)) - .build(); - Parcelable parcel = MockParcel.obtain(latLngBounds); - assertEquals("Parcel should match original object", parcel, latLngBounds); - } - - @Test - public void fromTileID() { - LatLngBounds bounds = LatLngBounds.from(0, 0, 0); - assertEquals(GeometryConstants.MIN_WRAP_LONGITUDE, bounds.getLonWest(), DELTA); - assertEquals(GeometryConstants.MIN_MERCATOR_LATITUDE, bounds.getLatSouth(), DELTA); - assertEquals(GeometryConstants.MAX_WRAP_LONGITUDE, bounds.getLonEast(), DELTA); - assertEquals(GeometryConstants.MAX_MERCATOR_LATITUDE, bounds.getLatNorth(), DELTA); - - bounds = LatLngBounds.from(10, 288, 385); - assertEquals(-78.75, bounds.getLonWest(), DELTA); - assertEquals(40.446947059600497, bounds.getLatSouth(), DELTA); - assertEquals(-78.3984375, bounds.getLonEast(), DELTA); - assertEquals(40.713955826286039, bounds.getLatNorth(), DELTA); - - } - - @Rule - public final ExpectedException exception = ExpectedException.none(); - - @Test - public void testConstructorChecksNorthLatitudeNaN() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("latitude must not be NaN"); - LatLngBounds.from(Double.NaN, 0, -20, -20); - } - - @Test - public void testConstructorChecksEastLongitudeNaN() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("longitude must not be NaN"); - LatLngBounds.from(0, Double.NaN, -20, -20); - } - - @Test - public void testConstructorChecksNorthLatitudeGreaterThan90() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("latitude must be between -90 and 90"); - LatLngBounds.from(95, 0, -20, -20); - } - - @Test - public void testConstructorChecksNorthLatitudeLessThanThanNegative90() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("latitude must be between -90 and 90"); - LatLngBounds.from(-95, 0, -20, -20); - } - - @Test - public void testConstructorChecksEastLongitudeInfinity() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("longitude must not be infinite"); - LatLngBounds.from(0, Double.POSITIVE_INFINITY, -20, -20); - } - - @Test - public void testConstructorChecksSouthLatitudeNaN() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("latitude must not be NaN"); - LatLngBounds.from(20, 20, Double.NaN, 0); - } - - @Test - public void testConstructorChecksWesttLongitudeNaN() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("longitude must not be NaN"); - LatLngBounds.from(20, 20, 0, Double.NaN); - } - - @Test - public void testConstructorChecksSouthLatitudeGreaterThan90() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("latitude must be between -90 and 90"); - LatLngBounds.from(20, 20, 95, 0); - } - - @Test - public void testConstructorChecksSouthLatitudeLessThanThanNegative90() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("latitude must be between -90 and 90"); - LatLngBounds.from(20, 20, -95, 0); - } - - @Test - public void testConstructorChecksWestLongitudeInfinity() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("longitude must not be infinite"); - LatLngBounds.from(20, 20, 0, Double.POSITIVE_INFINITY); - } - - @Test - public void testConstructorCheckLatSouthGreaterLatNorth() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("latNorth cannot be less than latSouth"); - LatLngBounds.from(0, 20, 20, 0); - } - - @Test - public void testConstructorCheckLonWestGreaterLonEast() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("lonEast cannot be less than lonWest"); - LatLngBounds.from(20, 0, 0, 20); - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngSpanTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngSpanTest.java deleted file mode 100644 index 12297247cf..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngSpanTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.mapbox.mapboxsdk.geometry; - -import android.os.Parcelable; - -import com.mapbox.mapboxsdk.utils.MockParcel; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -public class LatLngSpanTest { - - private static final double DELTA = 1e-15; - private static final LatLng LAT_LNG_NULL_ISLAND = new LatLng(0, 0); - - @Test - public void testSanity() { - LatLngSpan latLngSpan = new LatLngSpan(0.0, 0.0); - assertNotNull("latLngSpan should not be null", latLngSpan); - } - - @Test - public void testEquality() { - LatLngSpan latLngSpan = new LatLngSpan(0.0, 0.0); - assertEquals("latLngSpan is not equal to a LatLng", latLngSpan.equals(LAT_LNG_NULL_ISLAND), false); - } - - @Test - public void testLatitudeConstructor() { - double latitude = 1.23; - LatLngSpan latLngSpan = new LatLngSpan(latitude, 0.0); - assertEquals("latitude in constructor", latLngSpan.getLatitudeSpan(), latitude, DELTA); - } - - @Test - public void testLongitudeConstructor() { - double longitude = 1.23; - LatLngSpan latLngSpan = new LatLngSpan(0.0, longitude); - assertEquals("latitude in constructor", latLngSpan.getLongitudeSpan(), longitude, DELTA); - } - - @Test - public void testLatitudeMethod() { - double latitude = 1.23; - LatLngSpan latLngSpan = new LatLngSpan(0.0, 0.0); - latLngSpan.setLatitudeSpan(latitude); - assertEquals("latitude in constructor", latLngSpan.getLatitudeSpan(), latitude, DELTA); - } - - @Test - public void testLongitudeMethod() { - double longitude = 1.23; - LatLngSpan latLngSpan = new LatLngSpan(0.0, 0.0); - latLngSpan.setLongitudeSpan(longitude); - assertEquals("latitude in constructor", latLngSpan.getLongitudeSpan(), longitude, DELTA); - } - - @Test - public void testParcelable() { - LatLngSpan object = new LatLngSpan(1, 2); - Parcelable parcel = MockParcel.obtain(object); - assertEquals("parcel should match initial object", object, parcel); - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngTest.java deleted file mode 100644 index 862c56a526..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngTest.java +++ /dev/null @@ -1,286 +0,0 @@ -package com.mapbox.mapboxsdk.geometry; - -import android.location.Location; -import android.os.Parcelable; - -import com.mapbox.mapboxsdk.utils.MockParcel; - -import org.junit.Test; -import org.junit.Rule; -import org.junit.rules.ExpectedException; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class LatLngTest { - - private static final double DELTA = 1e-15; - - @Test - public void testSanity() { - LatLng latLng = new LatLng(0.0, 0.0); - assertNotNull("latLng should not be null", latLng); - } - - @Test - public void testLatitudeEmptyConstructor() { - LatLng latLng = new LatLng(); - assertEquals("latitude default value", latLng.getLatitude(), 0, DELTA); - } - - @Test - public void testLongitudeEmptyConstructor() { - LatLng latLng = new LatLng(); - assertEquals("longitude default value", latLng.getLongitude(), 0, DELTA); - } - - @Test - public void testAltitudeEmptyConstructor() { - LatLng latLng1 = new LatLng(); - assertEquals("altitude default value", latLng1.getAltitude(), 0.0, DELTA); - } - - @Test - public void testLatitudeConstructor() { - double latitude = 1.2; - LatLng latLng = new LatLng(latitude, 3.4); - assertEquals("latitude should match", latLng.getLatitude(), latitude, DELTA); - } - - @Test - public void testLongitudeConstructor() { - double longitude = 3.4; - LatLng latLng = new LatLng(1.2, longitude); - assertEquals("longitude should match", latLng.getLongitude(), longitude, DELTA); - } - - @Test - public void testAltitudeConstructor() { - LatLng latLng1 = new LatLng(1.2, 3.4); - assertEquals("altitude default value", latLng1.getAltitude(), 0.0, DELTA); - - double altitude = 5.6; - LatLng latLng2 = new LatLng(1.2, 3.4, altitude); - assertEquals("altitude default value", latLng2.getAltitude(), altitude, DELTA); - } - - @Test - public void testLatitudeSetter() { - LatLng latLng = new LatLng(1.2, 3.4); - latLng.setLatitude(3); - assertEquals("latitude should match", 3, latLng.getLatitude(), DELTA); - } - - @Test - public void testLongitudeSetter() { - LatLng latLng = new LatLng(1.2, 3.4); - latLng.setLongitude(3); - assertEquals("longitude should match", 3, latLng.getLongitude(), DELTA); - } - - @Rule - public final ExpectedException exception = ExpectedException.none(); - - @Test - public void testConstructorChecksLatitudeNaN() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("latitude must not be NaN"); - new LatLng(Double.NaN, 0); - } - - @Test - public void testConstructorChecksLongitudeNaN() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("longitude must not be NaN"); - new LatLng(0, Double.NaN); - } - - @Test - public void testConstructorChecksLatitudeGreaterThan90() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("latitude must be between -90 and 90"); - new LatLng(95, 0); - } - - @Test - public void testConstructorChecksLatitudeLessThanThanNegative90() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("latitude must be between -90 and 90"); - new LatLng(-95, 0); - } - - @Test - public void testConstructorChecksLongitudeInfinity() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("longitude must not be infinite"); - new LatLng(0, Double.POSITIVE_INFINITY); - } - - @Test - public void testLatitudeSetterChecksNaN() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("latitude must not be NaN"); - new LatLng().setLatitude(Double.NaN); - } - - @Test - public void testLongitudeSetterChecksNaN() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("longitude must not be NaN"); - new LatLng().setLongitude(Double.NaN); - } - - @Test - public void testLatitudeSetterChecksGreaterThan90() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("latitude must be between -90 and 90"); - new LatLng().setLatitude(95); - } - - @Test - public void testLatitudeSetterChecksLessThanThanNegative90() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("latitude must be between -90 and 90"); - new LatLng().setLatitude(-95); - } - - @Test - public void testLongitudeSetterChecksInfinity() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("longitude must not be infinite"); - new LatLng().setLongitude(Double.NEGATIVE_INFINITY); - } - - @Test - public void testAltitudeSetter() { - LatLng latLng = new LatLng(1.2, 3.4); - latLng.setAltitude(3); - assertEquals("altitude should match", 3, latLng.getAltitude(), DELTA); - } - - @Test - public void testLatLngConstructor() { - LatLng latLng1 = new LatLng(1.2, 3.4); - LatLng latLng2 = new LatLng(latLng1); - assertEquals("latLng should match", latLng1, latLng2); - } - - @Test - public void testDistanceTo() { - LatLng latLng1 = new LatLng(0.0, 0.0); - LatLng latLng2 = new LatLng(1.0, 1.0); - assertEquals("distances should match", - latLng1.distanceTo(latLng2), - 157298.7453847275, DELTA); - } - - @Test - public void testDistanceToSamePoint() { - LatLng latLng1 = new LatLng(40.71199035644531, -74.0081); - LatLng latLng2 = new LatLng(40.71199035644531, -74.0081); - double distance = latLng1.distanceTo(latLng2); - assertEquals("distance should match", 0.0, distance, DELTA); - } - - // Regression test for #14216 - @Test - public void testDistanceToClosePointNotNaN() { - LatLng latLng = new LatLng(40.00599, -105.29261); - LatLng other = new LatLng(40.005990000000025, -105.29260999999997); - double distance = latLng.distanceTo(other); - assertNotEquals(distance, Double.NaN); - } - - @Test - public void testLocationProvider() { - double latitude = 1.2; - double longitude = 3.4; - double altitude = 5.6; - - // Mock the location class - Location locationMocked = mock(Location.class); - when(locationMocked.getLatitude()).thenReturn(latitude); - when(locationMocked.getLongitude()).thenReturn(longitude); - when(locationMocked.getAltitude()).thenReturn(altitude); - - // Test the constructor - LatLng latLng = new LatLng(locationMocked); - assertEquals("latitude should match", latLng.getLatitude(), latitude, DELTA); - assertEquals("longitude should match", latLng.getLongitude(), longitude, DELTA); - assertEquals("altitude should match", latLng.getAltitude(), altitude, DELTA); - } - - @Test - public void testHashCode() { - double latitude = 1.2; - double longitude = 3.4; - double altitude = 5.6; - LatLng latLng = new LatLng(latitude, longitude, altitude); - assertEquals("hash code should match", latLng.hashCode(), -151519232); - } - - @Test - public void testToString() { - double latitude = 1.2; - double longitude = 3.4; - double altitude = 5.6; - LatLng latLng = new LatLng(latitude, longitude, altitude); - assertEquals("string should match", - latLng.toString(), - "LatLng [latitude=1.2, longitude=3.4, altitude=5.6]"); - } - - @Test - public void testEqualsOther() { - double latitude = 1.2; - double longitude = 3.4; - double altitude = 5.6; - LatLng latLng1 = new LatLng(latitude, longitude, altitude); - LatLng latLng2 = new LatLng(latitude, longitude, altitude); - assertEquals("LatLng should match", latLng1, latLng2); - } - - @Test - public void testEqualsItself() { - LatLng latLng = new LatLng(1, 2, 3); - assertEquals("LatLng should match", latLng, latLng); - } - - @Test - public void testNotEquals() { - LatLng latLng = new LatLng(1, 2); - assertNotEquals("LatLng should match", latLng, new Object()); - } - - @Test - public void testParcelable() { - LatLng latLng = new LatLng(45.0, -185.0); - Parcelable parcel = MockParcel.obtain(latLng); - assertEquals("parcel should match initial object", latLng, parcel); - } - - @Test - public void testWrapped() { - LatLng originalLatLng = new LatLng(45.0, -185.0); - LatLng newLatlng = originalLatLng.wrap(); - assertNotSame(" new wrapped LatLng is created", originalLatLng, newLatlng); - assertEquals("longitude wrapped value", originalLatLng.getLongitude(), -185.0, DELTA); - assertEquals("longitude wrapped value", newLatlng.getLongitude(), 175.0, DELTA); - - newLatlng = new LatLng(45.0, 180.0).wrap(); - assertEquals("longitude wrapped max value", newLatlng.getLongitude(), 180.0, DELTA); - - newLatlng = new LatLng(45.0, -180.0).wrap(); - assertEquals("longitude wrapped min value", newLatlng.getLongitude(), -180.0, DELTA); - } - - @Test - public void testUnnecessaryWrapped() { - LatLng latLng = new LatLng(45.0, 50.0).wrap(); - assertEquals("longitude wrapped value", latLng.getLongitude(), 50.0, DELTA); - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/ProjectedMetersTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/ProjectedMetersTest.java deleted file mode 100644 index 00fd125a1a..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/ProjectedMetersTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.mapbox.mapboxsdk.geometry; - -import android.os.Parcelable; - -import com.mapbox.mapboxsdk.utils.MockParcel; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -public class ProjectedMetersTest { - - private static final LatLng LAT_LNG_NULL_ISLAND = new LatLng(0, 0); - - @Test - public void testSanity() { - ProjectedMeters projectedMeters = new ProjectedMeters(0.0, 0.0); - assertNotNull("projectedMeters should not be null", projectedMeters); - } - - @Test - public void testEquality() { - ProjectedMeters projectedMeters = new ProjectedMeters(0.0, 0.0); - assertEquals("projectedMeters is not equal to a LatLng", projectedMeters.equals(LAT_LNG_NULL_ISLAND), false); - assertEquals("projectedMeters is equal to itself", projectedMeters.equals(projectedMeters), true); - } - - @Test - public void testNorthing() { - ProjectedMeters projectedMeters = new ProjectedMeters(1.0, 0.0); - assertEquals("northing should be 1", 1, projectedMeters.getNorthing(), 0); - } - - @Test - public void testEasting() { - ProjectedMeters projectedMeters = new ProjectedMeters(0.0, 1.0); - assertEquals("easting should be 1", 1, projectedMeters.getEasting(), 0); - } - - @Test - public void testConstructor() { - ProjectedMeters projectedMeters1 = new ProjectedMeters(1, 2); - ProjectedMeters projectedMeters2 = new ProjectedMeters(projectedMeters1); - assertEquals("projectedmeters should match", projectedMeters1, projectedMeters2); - } - - @Test - public void testHashcode() { - ProjectedMeters meters = new ProjectedMeters(1, 2); - assertEquals("hashcode should match", -1048576, meters.hashCode()); - } - - @Test - public void testToString() { - ProjectedMeters meters = new ProjectedMeters(1, 1); - assertEquals("toString should match", "ProjectedMeters [northing=1.0, easting=1.0]", meters.toString()); - } - - @Test - public void testParcelable() { - ProjectedMeters meters = new ProjectedMeters(1, 1); - Parcelable parcel = MockParcel.obtain(meters); - assertEquals("parcel should match initial object", meters, parcel); - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/VisibleRegionTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/VisibleRegionTest.java deleted file mode 100644 index 12b779de5d..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/VisibleRegionTest.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.mapbox.mapboxsdk.geometry; - -import android.os.Parcelable; - -import com.mapbox.mapboxsdk.utils.MockParcel; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -public class VisibleRegionTest { - - private static final LatLng FAR_LEFT = new LatLng(52, -12); - private static final LatLng NEAR_LEFT = new LatLng(34, -12); - private static final LatLng FAR_RIGHT = new LatLng(52, 26); - private static final LatLng NEAR_RIGHT = new LatLng(34, 26); - private static final LatLngBounds BOUNDS = - new LatLngBounds.Builder().include(FAR_LEFT).include(FAR_RIGHT).include(NEAR_LEFT).include(NEAR_RIGHT).build(); - - @Test - public void testSanity() { - VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS); - assertNotNull("region should not be null", region); - } - - @Test - public void testEquality() { - VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS); - assertEquals("visibleRegion is not equal to a LatLng", region.equals(FAR_LEFT), false); - assertEquals("visibleRegion is equal to itself", region.equals(region), true); - } - - @Test - public void testFarLeftConstructor() { - VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS); - assertEquals("LatLng should match", region.farLeft, FAR_LEFT); - } - - @Test - public void testNearLeftConstructor() { - VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS); - assertEquals("LatLng should match", region.nearLeft, NEAR_LEFT); - } - - @Test - public void testFarRightConstructor() { - VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS); - assertEquals("LatLng should match", region.farRight, FAR_RIGHT); - } - - @Test - public void testNearRightConstructor() { - VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS); - assertEquals("LatLng should match", region.nearRight, NEAR_RIGHT); - } - - @Test - public void testLatLngBoundsConstructor() { - VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS); - assertEquals("LatLngBounds should match", region.latLngBounds, BOUNDS); - } - - @Test - public void testEquals() { - VisibleRegion regionLeft = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS); - VisibleRegion regionRight = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS); - assertEquals("VisibleRegions should match", regionLeft, regionRight); - } - - @Test - public void testHashcode() { - VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS); - assertEquals("hashcode should match", -923534102, region.hashCode()); - } - - @Test - public void testToString() { - VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS); - assertEquals("string should match", - "[farLeft [LatLng [latitude=52.0, longitude=-12.0, altitude=0.0]], " - + "farRight [LatLng [latitude=52.0, longitude=26.0, altitude=0.0]], " - + "nearLeft [LatLng [latitude=34.0, longitude=-12.0, altitude=0.0]], " - + "nearRight [LatLng [latitude=34.0, longitude=26.0, altitude=0.0]], " - + "latLngBounds [N:52.0; E:26.0; S:34.0; W:-12.0]]", - region.toString()); - } - - @Test - public void testParcelable() { - VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS); - Parcelable parcel = MockParcel.obtain(region); - assertEquals("parcel should match initial object", region, parcel); - } -} |