5 require_once '../../lib/lib.php';
7 class NominatimTest extends \PHPUnit_Framework_TestCase
11 protected function setUp()
16 public function testGetClassTypesWithImportance()
18 $aClasses = getClassTypesWithImportance();
20 $this->assertGreaterThan(
29 'icon' => 'poi_boundary_administrative',
34 $aClasses['place:country']
39 public function testGetResultDiameter()
44 getResultDiameter($aResult)
47 $aResult = array('class' => 'place', 'type' => 'country');
50 getResultDiameter($aResult)
53 $aResult = array('class' => 'boundary', 'type' => 'administrative', 'admin_level' => 6);
56 getResultDiameter($aResult)
61 public function testAddQuotes()
63 // FIXME: not quoting existing quote signs is probably a bug
64 $this->assertSame("'St. John's'", addQuotes("St. John's"));
65 $this->assertSame("''", addQuotes(''));
69 public function testCreatePointsAroundCenter()
71 // you might say we're creating a circle
72 $aPoints = createPointsAroundCenter(0, 0, 2);
81 ['', 0.12558103905863, 1.9960534568565],
82 ['', 0.25066646712861, 1.984229402629]
84 array_splice($aPoints, 0, 3)
89 public function testGeometryText2Points()
95 geometryText2Points('', $fRadius)
99 $aPoints = geometryText2Points('POINT(10 20)', $fRadius);
107 [10.062790519529, 20.998026728428],
108 [10.125333233564, 20.992114701314]
110 array_splice($aPoints, 0, 3)
122 geometryText2Points('POLYGON((30 10, 40 40, 20 40, 10 20, 30 10))', $fRadius)
128 ['30', '20'], // first polygon only
133 geometryText2Points('MULTIPOLYGON(((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))', $fRadius)
137 public function testParseLatLon()
139 // no coordinates expected
140 $this->assertFalse(parseLatLon(''));
141 $this->assertFalse(parseLatLon('abc'));
142 $this->assertFalse(parseLatLon('12 34'));
144 // coordinates expected
145 $this->assertNotNull(parseLatLon('0.0 -0.0'));
147 $aRes = parseLatLon(' abc 12.456 -78.90 def ');
148 $this->assertEquals($aRes[1], 12.456);
149 $this->assertEquals($aRes[2], -78.90);
150 $this->assertEquals($aRes[0], ' 12.456 -78.90 ');
152 $aRes = parseLatLon(' [12.456,-78.90] ');
153 $this->assertEquals($aRes[1], 12.456);
154 $this->assertEquals($aRes[2], -78.90);
155 $this->assertEquals($aRes[0], ' [12.456,-78.90] ');
157 $aRes = parseLatLon(' -12.456,-78.90 ');
158 $this->assertEquals($aRes[1], -12.456);
159 $this->assertEquals($aRes[2], -78.90);
160 $this->assertEquals($aRes[0], ' -12.456,-78.90 ');
162 // http://en.wikipedia.org/wiki/Geographic_coordinate_conversion
163 // these all represent the same location
165 '40 26.767 N 79 58.933 W',
166 '40° 26.767′ N 79° 58.933′ W',
167 "40° 26.767' N 79° 58.933' W",
168 'N 40 26.767, W 79 58.933',
169 'N 40°26.767′, W 79°58.933′',
170 "N 40°26.767', W 79°58.933'",
172 '40 26 46 N 79 58 56 W',
173 '40° 26′ 46″ N 79° 58′ 56″ W',
174 '40° 26′ 46.00″ N 79° 58′ 56.00″ W',
175 '40°26′46″N 79°58′56″W',
176 'N 40 26 46 W 79 58 56',
177 'N 40° 26′ 46″, W 79° 58′ 56″',
178 'N 40° 26\' 46", W 79° 58\' 56"',
182 '40.446° N 79.982° W',
183 'N 40.446° W 79.982°',
186 ' 40.446 , -79.982 ',
190 foreach ($aQueries as $sQuery) {
191 $aRes = parseLatLon($sQuery);
192 $this->assertEquals(40.446, $aRes[1], 'degrees decimal ' . $sQuery, 0.01);
193 $this->assertEquals(-79.982, $aRes[2], 'degrees decimal ' . $sQuery, 0.01);
194 $this->assertEquals($sQuery, $aRes[0]);
198 private function closestHouseNumberEvenOddOther($startnumber, $endnumber, $fraction, $aExpected)
200 foreach (['even', 'odd', 'other'] as $itype) {
204 'startnumber' => $startnumber,
205 'endnumber' => $endnumber,
206 'fraction' => $fraction,
207 'interpolationtype' => $itype
209 "$startnumber => $endnumber, $fraction, $itype"
214 public function testClosestHouseNumber()
216 $this->closestHouseNumberEvenOddOther(50, 100, 0.5, ['even' => 76, 'odd' => 75, 'other' => 75]);
218 $this->closestHouseNumberEvenOddOther(50, 100, 1.5, ['even' => 100, 'odd' => 100, 'other' => 100]);
220 $this->closestHouseNumberEvenOddOther(50, 100, -0.5, ['even' => 50, 'odd' => 50, 'other' => 50]);
222 $this->closestHouseNumberEvenOddOther(50, 100, 0, ['even' => 50, 'odd' => 51, 'other' => 50]);
224 $this->closestHouseNumberEvenOddOther(50, 50, 0.5, ['even' => 50, 'odd' => 50, 'other' => 50]);