aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java
blob: 63924abd65278b89660adeaf528263066f5a3b79 (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
package cgeo.geocaching.connector.gc;

import static org.assertj.core.api.Assertions.assertThat;

import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.Viewport;

import java.util.Set;

import junit.framework.TestCase;

public class AutoZoomTest extends TestCase {

    public static void testZoom1() {
        final Geopoint bottomLeft = new Geopoint(49.3, 8.3);
        final Geopoint topRight = new Geopoint(49.4, 8.4);

        int zoom = Tile.calcZoomLat(bottomLeft, topRight, 2);

        assertThat(Math.abs(new Tile(bottomLeft, zoom).getY() - new Tile(topRight, zoom).getY()) == 1).isTrue();
        assertThat(Math.abs(new Tile(bottomLeft, zoom + 1).getY() - new Tile(topRight, zoom + 1).getY()) > 1).isTrue();

        zoom = Tile.calcZoomLon(bottomLeft, topRight, 2);

        assertThat(new Tile(bottomLeft, zoom).getX() + 1 == new Tile(topRight, zoom).getX()).isTrue();
        assertThat(new Tile(bottomLeft, zoom + 1).getX() + 1 < new Tile(topRight, zoom + 1).getX()).isTrue();

    }

    public static void testZoom2() {
        final Geopoint bottomLeft = new Geopoint(49.3, 8.3);
        final Geopoint topRight = new Geopoint(49.4, 8.4);

        int zoom = Tile.calcZoomLat(bottomLeft, topRight, 3);

        assertThat(Math.abs(new Tile(bottomLeft, zoom).getY() - new Tile(topRight, zoom).getY()) >= 2).isTrue();
        assertThat(Math.abs(new Tile(bottomLeft, zoom + 1).getY() - new Tile(topRight, zoom + 1).getY()) > 2).isTrue();

        zoom = Tile.calcZoomLon(bottomLeft, topRight, 3);

        assertThat(Math.abs(new Tile(bottomLeft, zoom).getX() - new Tile(topRight, zoom).getX()) >= 2).isTrue();
        assertThat(Math.abs(new Tile(bottomLeft, zoom + 1).getX() - new Tile(topRight, zoom + 1).getX()) > 2).isTrue();

    }

    public static void testTiles1x2() {
        final Geopoint bottomLeft = new Geopoint(49.3, 8.3);
        final Geopoint topRight = new Geopoint(49.4, 8.4);

        final Set<Tile> tiles = Tile.getTilesForViewport(new Viewport(bottomLeft, topRight));

        assertThat(tiles).hasSize(2);
    }

    public static void testTiles2x3() {
        final Geopoint bottomLeft = new Geopoint(49.3, 8.3);
        final Geopoint topRight = new Geopoint(49.4, 8.4);

        final Set<Tile> tiles = Tile.getTilesForViewport(new Viewport(bottomLeft, topRight), 3, Tile.ZOOMLEVEL_MIN);

        assertThat(tiles).hasSize(6);
    }

    public static void testTilesZoom13() {
        final Geopoint bottomLeft = new Geopoint(49.3, 8.3);
        final Geopoint topRight = new Geopoint(49.4, 8.4);

        final Set<Tile> tiles = Tile.getTilesForViewport(new Viewport(bottomLeft, topRight), 3, 13);

        assertThat(tiles).hasSize(16);
    }
}