summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/BoundingBoxTest.java
blob: 43492e1451260c183fd3f2d337c5d9b74153a363 (plain)
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
package com.mapbox.mapboxsdk.maps;

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.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 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 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 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());
    }

}