summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/VisibleRegionTest.java
blob: 83cfa378414e8bdfa63a215d3b651ce4467310bc (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
package com.mapbox.mapboxsdk.geometry;

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 [longitude=-12.0, latitude=52.0, altitude=0.0]], " +
                        "farRight [LatLng [longitude=26.0, latitude=52.0, altitude=0.0]], " +
                        "nearLeft [LatLng [longitude=-12.0, latitude=34.0, altitude=0.0]], " +
                        "nearRight [LatLng [longitude=26.0, latitude=34.0, altitude=0.0]], " +
                        "latLngBounds [N:52.0; E:26.0; S:34.0; W:-12.0]]"
                , region.toString());
    }

}