1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
package com.mapbox.mapboxsdk.geometry;
import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class LatLngBoundsTest {
private static final double DELTA = 1e-15;
private LatLngBounds mLatLngBounds;
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() {
mLatLngBounds = 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 testNoLatLngs() {
new LatLngBounds.Builder().build();
}
@Test(expected = InvalidLatLngBoundsException.class)
public void testOneLatLngs() {
new LatLngBounds.Builder().include(LAT_LNG_NULL_ISLAND).build();
}
@Test
public void testLatitiudeSpan() {
assertEquals("Span should be the same", 2, mLatLngBounds.getLatitudeSpan(), DELTA);
}
@Test
public void testLongitudeSpan() {
assertEquals("Span should be the same", 2, mLatLngBounds.getLongitudeSpan(), DELTA);
}
@Test
public void testCoordinateSpan() {
LatLngSpan latLngSpan = mLatLngBounds.getSpan();
assertEquals("LatLngSpan should be the same", new LatLngSpan(2, 2), latLngSpan);
}
@Test
public void testCenter() {
LatLng center = mLatLngBounds.getCenter();
assertEquals("Center should match", new LatLng(1, 1), center);
}
@Test
public void testEmptySpan() {
mLatLngBounds = new LatLngBounds.Builder()
.include(LAT_LNG_NOT_NULL_ISLAND)
.include(LAT_LNG_NOT_NULL_ISLAND)
.build();
assertTrue("Should be empty", mLatLngBounds.isEmptySpan());
}
@Test
public void testNotEmptySpan() {
mLatLngBounds = new LatLngBounds.Builder()
.include(LAT_LNG_NOT_NULL_ISLAND)
.include(LAT_LNG_NULL_ISLAND)
.build();
assertFalse("Should not be empty", mLatLngBounds.isEmptySpan());
}
@Test
public void testToLatLngs() {
mLatLngBounds = 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},
mLatLngBounds.toLatLngs());
}
@Test
public void testIncluding() {
assertTrue("LatLng should be included", mLatLngBounds.contains(new LatLng(1, 1)));
}
@Test
public void testNoIncluding() {
assertFalse("LatLng should not be included", mLatLngBounds.contains(new LatLng(3, 1)));
}
@Test
public void testHashCode() {
assertEquals(2147483647, mLatLngBounds.hashCode(), -1946419200);
}
@Test
public void testEquality() {
LatLngBounds latLngBounds = new LatLngBounds.Builder()
.include(LAT_LNG_NULL_ISLAND)
.include(LAT_LNG_NOT_NULL_ISLAND)
.build();
assertEquals("equality should match", mLatLngBounds, latLngBounds);
assertEquals("not equal to a different object type", mLatLngBounds.equals(LAT_LNG_NOT_NULL_ISLAND), false);
}
@Test
public void testToString() {
assertEquals(mLatLngBounds.toString(), "N:2.0; E:2.0; S:0.0; W:0.0");
}
@Test
public void testIntersect() {
LatLngBounds latLngBounds = new LatLngBounds.Builder()
.include(new LatLng(1, 1))
.include(LAT_LNG_NULL_ISLAND)
.build();
assertEquals("intersect should match", latLngBounds, latLngBounds.intersect(mLatLngBounds.getLatNorth(), mLatLngBounds.getLonEast(), mLatLngBounds.getLatSouth(), mLatLngBounds.getLonWest()));
}
@Test
public void testNoIntersect() {
LatLngBounds latLngBounds = new LatLngBounds.Builder()
.include(new LatLng(10, 10))
.include(new LatLng(9, 8))
.build();
assertNull(latLngBounds.intersect(mLatLngBounds));
}
@Test
public void testInnerUnion() {
LatLngBounds latLngBounds = new LatLngBounds.Builder()
.include(new LatLng(1, 1))
.include(LAT_LNG_NULL_ISLAND)
.build();
assertEquals("union should match", latLngBounds, latLngBounds.intersect(mLatLngBounds));
}
@Test
public void testOuterUnion() {
LatLngBounds latLngBounds = new LatLngBounds.Builder()
.include(new LatLng(10, 10))
.include(new LatLng(9, 8))
.build();
assertEquals("outer union should match",
latLngBounds.union(mLatLngBounds),
new LatLngBounds.Builder()
.include(new LatLng(10, 10))
.include(LAT_LNG_NULL_ISLAND)
.build());
}
}
|