@@ -0,0 +1,180 @@
|
||||
import com.mapbox.mapboxsdk.geometry.BoundingBox;
|
||||
import com.mapbox.mapboxsdk.geometry.CoordinateSpan;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class BoundingBoxTest {
|
||||
|
||||
private BoundingBox mBoundingBox;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
mBoundingBox = new BoundingBox(20.0, 10.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
BoundingBox boundingBox = new BoundingBox(0.0, 0.0, 0.0, 0.0);
|
||||
assertNotNull("boundingBox should not be null", boundingBox);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultConstructor() {
|
||||
mBoundingBox = new BoundingBox(0, 0, 0, 0);
|
||||
assertEquals(mBoundingBox, new BoundingBox());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualityConstructors() {
|
||||
BoundingBox cornerBoundingBox = new BoundingBox(new LatLng(20.0, 10.0), new LatLng(0.0, 0.0));
|
||||
BoundingBox cloneBoundingBox = new BoundingBox(mBoundingBox);
|
||||
assertEquals("boundingBoxes should match", mBoundingBox, cornerBoundingBox);
|
||||
assertEquals("boundingBoxes should match", mBoundingBox, cloneBoundingBox);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidBox() {
|
||||
assertTrue(mBoundingBox.isValid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidLatitudeSpanBox() {
|
||||
mBoundingBox = new BoundingBox(0.0, 10.0, 10.0, 0.0);
|
||||
assertFalse(mBoundingBox.isValid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidLongitudeSpanBox() {
|
||||
mBoundingBox = new BoundingBox(10.0, 0.0, 0.0, 20.0);
|
||||
assertFalse(mBoundingBox.isValid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCenterCoordinate() {
|
||||
LatLng center = new LatLng(10.0, 5.0);
|
||||
assertEquals("boundingBox center should match", center, mBoundingBox.getCenter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnionSameBox() {
|
||||
assertEquals(mBoundingBox, mBoundingBox.union(mBoundingBox));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnionInnerBox() {
|
||||
BoundingBox innerBox = new BoundingBox(2.0, 2.0, 1.0, 1.0);
|
||||
assertEquals(mBoundingBox.union(innerBox), mBoundingBox);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnionOverlapBox() {
|
||||
BoundingBox resultBox = new BoundingBox(22.0, 12.0, 0.0, 0.0);
|
||||
BoundingBox overlapBox = new BoundingBox(22.0, 12.0, 1.0, 1.0);
|
||||
assertEquals(resultBox, mBoundingBox.union(overlapBox));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnionOuterBox() {
|
||||
BoundingBox resultBox = new BoundingBox(40.0, 40.0, 0.0, 0.0);
|
||||
BoundingBox outerBox = new BoundingBox(40.0, 40.0, 0.0, 0.0);
|
||||
assertEquals(resultBox, mBoundingBox.union(outerBox));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntersectSameBox() {
|
||||
assertEquals(mBoundingBox, mBoundingBox.intersect(mBoundingBox));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntersectInnerBox() {
|
||||
BoundingBox innerBox = new BoundingBox(2.0, 2.0, 1.0, 1.0);
|
||||
assertEquals(innerBox, mBoundingBox.intersect(innerBox));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntersectOuterBox() {
|
||||
BoundingBox outerBox = new BoundingBox(40.0, 40.0, 0.0, 0.0);
|
||||
assertEquals(mBoundingBox, mBoundingBox.intersect(outerBox));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntersectOverlapBox() {
|
||||
BoundingBox resultBox = new BoundingBox(20.0, 10.0, 1.0, 1.0);
|
||||
BoundingBox overlapBox = new BoundingBox(22.0, 12.0, 1.0, 1.0);
|
||||
assertEquals(resultBox, mBoundingBox.intersect(overlapBox));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntersectNoneBox() {
|
||||
BoundingBox outsideBox = new BoundingBox(100.0, 100.0, 50.0, 50.0);
|
||||
assertNull(mBoundingBox.intersect(outsideBox));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsCoordinate() {
|
||||
LatLng coordinate = new LatLng(1.0, 1.0);
|
||||
assertTrue(mBoundingBox.contains(coordinate));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsCoordinateOnBoundary() {
|
||||
LatLng coordinate = new LatLng(20.0, 9.0);
|
||||
assertFalse(mBoundingBox.contains(coordinate));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsNoCoordinate() {
|
||||
LatLng coordinate = new LatLng(100.0, 100.0);
|
||||
assertFalse(mBoundingBox.contains(coordinate));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpan() {
|
||||
CoordinateSpan span = new CoordinateSpan(20.0, 10.0);
|
||||
assertTrue(mBoundingBox.getSpan().equals(span));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeSpan() {
|
||||
double height = 20.0;
|
||||
assertTrue(mBoundingBox.getLatitudeSpan() == height);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeSpan() {
|
||||
double width = 10.0;
|
||||
assertTrue(mBoundingBox.getLongitudeSpan() == width);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptySpanEmptyNotEmptyBox(){
|
||||
assertFalse(mBoundingBox.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptySpanEmptyBox() {
|
||||
mBoundingBox = new BoundingBox();
|
||||
assertTrue(mBoundingBox.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptySpanEmptyLatitude() {
|
||||
mBoundingBox = new BoundingBox(1.0, 2.0, 0.0, 2.0);
|
||||
assertTrue(mBoundingBox.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptySpanEmptyLongitude(){
|
||||
mBoundingBox = new BoundingBox(0.0, 3.0, 0.0, 1.0);
|
||||
assertTrue(mBoundingBox.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import com.mapbox.mapboxsdk.geometry.CoordinateBounds;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class CoordinateBoundsTest {
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
CoordinateBounds coordinateBounds = new CoordinateBounds(null, null);
|
||||
assertNotNull("coordinateBounds should not be null", coordinateBounds);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSouthWestConstructor() {
|
||||
LatLng southWest = new LatLng(12, 12);
|
||||
CoordinateBounds coordinateBounds = new CoordinateBounds(southWest, null);
|
||||
assertEquals("southWest should match", southWest, coordinateBounds.getSouthWest());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNorthEastConstructor() {
|
||||
LatLng northEast = new LatLng(12, 12);
|
||||
CoordinateBounds coordinateBounds = new CoordinateBounds(null, northEast);
|
||||
assertEquals("northEast should match", northEast, coordinateBounds.getNorthEast());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
LatLng northEast = new LatLng(60, 60);
|
||||
LatLng southWest = new LatLng(43, 26);
|
||||
CoordinateBounds coordinateBounds = new CoordinateBounds(northEast, southWest);
|
||||
assertEquals("hash code should match", coordinateBounds.hashCode(), -1515487232);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
LatLng northEast = new LatLng(60, 60);
|
||||
LatLng southWest = new LatLng(43, 26);
|
||||
CoordinateBounds coordinateBounds = new CoordinateBounds(northEast, southWest);
|
||||
assertEquals("string should match",
|
||||
coordinateBounds.toString(),
|
||||
"CoordinateBounds [northEast[" + coordinateBounds.getNorthEast() + "], southWest[]" + coordinateBounds.getSouthWest() + "]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
LatLng northEast = new LatLng(60, 60);
|
||||
LatLng southWest = new LatLng(43, 26);
|
||||
CoordinateBounds firstBounds = new CoordinateBounds(northEast, southWest);
|
||||
CoordinateBounds sameBounds = new CoordinateBounds(northEast, southWest);
|
||||
assertTrue(firstBounds.equals(sameBounds));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import com.mapbox.mapboxsdk.geometry.CoordinateRegion;
|
||||
import com.mapbox.mapboxsdk.geometry.CoordinateSpan;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class CoordinateRegionTest {
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
LatLng center = new LatLng(1.2, 3.4, 5.6);
|
||||
CoordinateSpan span = new CoordinateSpan(9.8, 7.6);
|
||||
CoordinateRegion coordinateRegion = new CoordinateRegion(center, span);
|
||||
assertNotNull("coordinateRegion should not be null", coordinateRegion);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCenterConstructor() {
|
||||
LatLng center = new LatLng(1.2, 3.4, 5.6);
|
||||
CoordinateSpan span = new CoordinateSpan(9.8, 7.6);
|
||||
CoordinateRegion coordinateRegion = new CoordinateRegion(center, span);
|
||||
assertEquals("center should match", coordinateRegion.getCenter(), center);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpanConstructor() {
|
||||
LatLng center = new LatLng(1.2, 3.4, 5.6);
|
||||
CoordinateSpan span = new CoordinateSpan(9.8, 7.6);
|
||||
CoordinateRegion coordinateRegion = new CoordinateRegion(center, span);
|
||||
assertEquals("span should match", coordinateRegion.getSpan(), span);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCenterMethod() {
|
||||
LatLng center = new LatLng(1.2, 3.4, 5.6);
|
||||
CoordinateSpan span = new CoordinateSpan(9.8, 7.6);
|
||||
CoordinateRegion coordinateRegion = new CoordinateRegion(null, span);
|
||||
coordinateRegion.setCenter(center);
|
||||
assertEquals("center should match", coordinateRegion.getCenter(), center);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpanMethod() {
|
||||
LatLng center = new LatLng(1.2, 3.4, 5.6);
|
||||
CoordinateSpan span = new CoordinateSpan(9.8, 7.6);
|
||||
CoordinateRegion coordinateRegion = new CoordinateRegion(center, null);
|
||||
coordinateRegion.setSpan(span);
|
||||
assertEquals("span should match", coordinateRegion.getSpan(), span);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import com.mapbox.mapboxsdk.geometry.CoordinateSpan;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class CoordinateSpanTest {
|
||||
|
||||
private static final double DELTA = 1e-15;
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, 0.0);
|
||||
assertNotNull("coordinateSpan should not be null", coordinateSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeConstructor() {
|
||||
double latitude = 1.23;
|
||||
CoordinateSpan coordinateSpan = new CoordinateSpan(latitude, 0.0);
|
||||
assertEquals("latitude in constructor", coordinateSpan.getLatitudeSpan(), latitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeConstructor() {
|
||||
double longitude = 1.23;
|
||||
CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, longitude);
|
||||
assertEquals("latitude in constructor", coordinateSpan.getLongitudeSpan(), longitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeMethod() {
|
||||
double latitude = 1.23;
|
||||
CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, 0.0);
|
||||
coordinateSpan.setLatitudeSpan(latitude);
|
||||
assertEquals("latitude in constructor", coordinateSpan.getLatitudeSpan(), latitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeMethod() {
|
||||
double longitude = 1.23;
|
||||
CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, 0.0);
|
||||
coordinateSpan.setLongitudeSpan(longitude);
|
||||
assertEquals("latitude in constructor", coordinateSpan.getLongitudeSpan(), longitude, DELTA);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
import android.location.Location;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
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 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);
|
||||
}
|
||||
|
||||
/*
|
||||
* A sample test where Mockito is necessary
|
||||
*/
|
||||
|
||||
@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 [longitude=3.4, latitude=1.2, altitude=5.6]");
|
||||
}
|
||||
|
||||
@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),
|
||||
157425.53710839353, DELTA);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngZoom;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class LatLngZoomTest {
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
LatLngZoom latLngZoom = new LatLngZoom(0.0, 0.0, 0.0);
|
||||
assertNotNull("latLngZoom should not be null", latLngZoom);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class ProjectedMetersTest {
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
ProjectedMeters projectedMeters = new ProjectedMeters(0.0, 0.0);
|
||||
assertNotNull("projectedMeters should not be null", projectedMeters);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user