]> git.openstreetmap.org Git - nominatim.git/blob - test/php/Nominatim/NearPointTest.php
adapt unit tests for new NearPoint type
[nominatim.git] / test / php / Nominatim / NearPointTest.php
1 <?php
2
3 namespace Nominatim;
4
5 require '../../lib/NearPoint.php';
6
7 class NearPointTest extends \PHPUnit_Framework_TestCase
8 {
9     protected function setUp()
10     {
11     }
12
13     public function testExtractFromQuery()
14     {
15         // no coordinates expected
16         $this->assertFalse(NearPoint::extractFromQuery(''));
17         $this->assertFalse(NearPoint::extractFromQuery('abc'));
18         $this->assertFalse(NearPoint::extractFromQuery('12 34'));
19         $this->assertFalse(NearPoint::extractFromQuery('200.1 89.9')); // because latitude > 180
20
21         // coordinates expected
22         $this->assertNotNull(NearPoint::extractFromQuery('0.0 -0.0'));
23
24         $aRes = NearPoint::extractFromQuery(' abc 12.456 -78.90 def ');
25         $this->assertEquals($aRes['pt']->lat(), 12.456);
26         $this->assertEquals($aRes['pt']->lon(), -78.90);
27         $this->assertEquals($aRes['pt']->radius(), 0.1);
28         $this->assertEquals($aRes['query'], 'abc   def');
29
30         $aRes = NearPoint::extractFromQuery(' [12.456,-78.90] ');
31         $this->assertEquals($aRes['pt']->lat(), 12.456);
32         $this->assertEquals($aRes['pt']->lon(), -78.90);
33         $this->assertEquals($aRes['pt']->radius(), 0.1);
34         $this->assertEquals($aRes['query'], '');
35
36         // http://en.wikipedia.org/wiki/Geographic_coordinate_conversion
37         // these all represent the same location
38         $aQueries = array(
39                      '40 26.767 N 79 58.933 W',
40                      '40° 26.767′ N 79° 58.933′ W',
41                      "40° 26.767' N 79° 58.933' W",
42                      'N 40 26.767, W 79 58.933',
43                      'N 40°26.767′, W 79°58.933′',
44                      "N 40°26.767', W 79°58.933'",
45  
46                      '40 26 46 N 79 58 56 W',
47                      '40° 26′ 46″ N 79° 58′ 56″ W',
48                      'N 40 26 46 W 79 58 56',
49                      'N 40° 26′ 46″, W 79° 58′ 56″',
50                      'N 40° 26\' 46", W 79° 58\' 56"',
51  
52                      '40.446 -79.982',
53                      '40.446,-79.982',
54                      '40.446° N 79.982° W',
55                      'N 40.446° W 79.982°',
56  
57                      '[40.446 -79.982]',
58                      '       40.446  ,   -79.982     ',
59                     );
60
61
62         foreach ($aQueries as $sQuery) {
63             $aRes = NearPoint::extractFromQuery($sQuery);
64             $this->assertEquals(40.446, $aRes['pt']->lat(), 'degrees decimal ' . $sQuery, 0.01);
65             $this->assertEquals(-79.982, $aRes['pt']->lon(), 'degrees decimal ' . $sQuery, 0.01);
66         }
67     }
68 }