Completed
Push — master ( ac41f4...7a5cb9 )
by Hannes
02:54
created

SRTM4ProviderTest::testMultipleElevationsInSydney()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Runalyze DEM Reader.
5
 *
6
 * (c) RUNALYZE <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Runalyze\DEM\Tests\Provider\GeoTIFF;
13
14
use Runalyze\DEM\Interpolation\BilinearInterpolation;
15
use Runalyze\DEM\Provider\GeoTIFF\SRTM4Provider;
16
17
class SRTM4ProviderTest extends \PHPUnit_Framework_TestCase
18
{
19
    /** @var string */
20
    const PATH_TO_FILES = '/../../../../tests/testfiles/';
21
22
    /**
23
     * @var SRTM4Provider
24
     */
25
    protected $Provider;
26
27
    public function setUp()
28
    {
29
        $this->Provider = new SRTM4Provider(__DIR__.self::PATH_TO_FILES);
30
        $this->Provider->setInterpolation(new BilinearInterpolation());
31
    }
32
33
    /**
34
     * @param string $filename
35
     */
36
    protected function checkFile($filename)
37
    {
38
        if (!file_exists(__DIR__.self::PATH_TO_FILES.$filename)) {
39
            $this->markTestSkipped('Required testfile "'.$filename.'" is not available.');
40
        }
41
    }
42
43
    public function testThatLocationOutOfBoundsIsRecognized()
44
    {
45
        $this->assertFalse($this->Provider->hasDataFor([
46
            [90.0, 0.1],
47
        ]));
48
    }
49
50
    public function testInvalidLocation()
51
    {
52
        $this->assertFalse($this->Provider->getElevation(0.0, 0.0));
53
    }
54
55
    public function testThatAvailableFileIsRecognized()
56
    {
57
        $this->checkFile('srtm_38_03.tif');
58
59
        $this->assertTrue($this->Provider->hasDataFor([
60
            [49.4, 7.7],
61
            [49.5, 7.6],
62
        ]));
63
    }
64
65
    public function testSingleElevationInGermany()
66
    {
67
        $this->checkFile('srtm_38_03.tif');
68
69
        $this->assertEquals(238, $this->Provider->getElevation(49.444722, 7.768889));
70
    }
71
72
    public function testThatUnknownElevationInSydneyIsGuessedBySurroundingValues()
73
    {
74
        $this->checkFile('srtm_67_19.tif');
75
76
        $this->assertEquals(3, $this->Provider->getElevation(-33.8705667, 151.1486337));
77
    }
78
79
    public function testMultipleElevationsInSydney()
80
    {
81
        $this->checkFile('srtm_67_19.tif');
82
83
        $this->assertEquals(
84
            [3, 3, 2],
85
            $this->Provider->getElevations(
86
                [-33.8706555, -33.8705667, -33.8704860],
87
                [151.1486918, 151.1486337, 151.1485585]
88
            )
89
        );
90
    }
91
92
    public function testLocationsInLondonLondon()
93
    {
94
        $this->checkFile('srtm_36_02.tif');
95
96
        $this->assertEquals(
97
            [18, 18, 21],
98
            $this->Provider->getElevations(
99
                [51.5073509, 51.5074509, 51.5075509],
100
                [-0.1277583, -0.1278583, -0.1279583]
101
            )
102
        );
103
    }
104
105
    public function testLocationsInWindhoek()
106
    {
107
        $this->checkFile('srtm_40_17.tif');
108
109
        $this->assertEquals(
110
            [1666, 1669, 1671],
111
            $this->Provider->getElevations(
112
                [-22.5700, -22.5705, -22.5710],
113
                [17.0836,  17.0841,  17.0846]
114
            )
115
        );
116
    }
117
118
    public function testNewYork()
119
    {
120
        $this->checkFile('srtm_22_04.tif');
121
122
        $this->assertEquals(
123
            [22, 25, 41],
124
            $this->Provider->getElevations(
125
                [40.7127,  40.7132,  40.7137],
126
                [-74.0059, -74.0064, -74.0069]
127
            )
128
        );
129
    }
130
}
131