5 require '../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 testLooksLikeLatLonPair()
71 // no coordinates expected
72 $this->assertNull(looksLikeLatLonPair(''));
73 $this->assertNull(looksLikeLatLonPair('abc'));
74 $this->assertNull(looksLikeLatLonPair('12 34'));
75 $this->assertNull(looksLikeLatLonPair('200.1 89.9')); // because latitude > 180
77 // coordinates expected
78 $this->assertNotNull(looksLikeLatLonPair('0.0 -0.0'));
81 array( 'lat' => 12.456, 'lon' => -78.90, 'query' => 'abc def'),
82 looksLikeLatLonPair(' abc 12.456 -78.90 def ')
86 array( 'lat' => 12.456, 'lon' => -78.90, 'query' => ''),
87 looksLikeLatLonPair(' [12.456,-78.90] ')
90 // http://en.wikipedia.org/wiki/Geographic_coordinate_conversion
91 // these all represent the same location
93 '40 26.767 N 79 58.933 W',
94 '40° 26.767′ N 79° 58.933′ W',
95 "40° 26.767' N 79° 58.933' W",
96 'N 40 26.767, W 79 58.933',
97 'N 40°26.767′, W 79°58.933′',
98 "N 40°26.767', W 79°58.933'",
100 '40 26 46 N 79 58 56 W',
101 '40° 26′ 46″ N 79° 58′ 56″ W',
102 'N 40 26 46 W 79 58 56',
103 'N 40° 26′ 46″, W 79° 58′ 56″',
104 'N 40° 26\' 46", W 79° 58\' 56"',
108 '40.446° N 79.982° W',
109 'N 40.446° W 79.982°',
112 ' 40.446 , -79.982 ',
116 foreach ($aQueries as $sQuery) {
117 $aRes = looksLikeLatLonPair($sQuery);
118 $this->assertEquals(40.446, $aRes['lat'], 'degrees decimal ' . $sQuery, 0.01);
119 $this->assertEquals(-79.982, $aRes['lon'], 'degrees decimal ' . $sQuery, 0.01);
125 public function testGetWordSets()
127 // given an array of arrays like
128 // array( array('a','b'), array('c','d') )
129 // returns a summary as string: '(a|b),(c|d)'
132 function serializeSets($aSets)
135 foreach ($aSets as $aSet) {
136 $aParts[] = '(' . join('|', $aSet) . ')';
138 return join(',', $aParts);
143 getWordSets(array(), 0)
148 serializeSets(getWordSets(array("a"), 0))
153 serializeSets(getWordSets(array('a', 'b'), 0))
157 '(a b c),(a|b c),(a|b|c),(a b|c)',
158 serializeSets(getWordSets(array('a', 'b', 'c'), 0))
162 '(a b c d),(a|b c d),(a|b|c d),(a|b|c|d),(a|b c|d),(a b|c d),(a b|c|d),(a b c|d)',
163 serializeSets(getWordSets(array('a', 'b', 'c', 'd'), 0))
169 '(a b c),(c|a b),(c|b|a),(b c|a)',
170 serializeSets(getInverseWordSets(array('a', 'b', 'c'), 0))
174 // make sure we don't create too many sets
176 // 10 words => 511 sets
177 // 15 words => 12911 sets
178 // 18 words => 65536 sets
179 // 20 words => 169766 sets
180 // 22 words => 401930 sets
181 // 28 words => 3505699 sets (needs more than 4GB via 'phpunit -d memory_limit=' to run)
184 count(getWordSets(array_fill(0, 4, 'a'), 0))
190 count(getWordSets(array_fill(0, 18, 'a'), 0))
195 public function testCreatePointsAroundCenter()
197 // you might say we're creating a circle
198 $aPoints = createPointsAroundCenter(0, 0, 2);
207 ['', 0.12558103905863, 1.9960534568565],
208 ['', 0.25066646712861, 1.984229402629]
210 array_splice($aPoints, 0, 3)
215 public function testGeometryText2Points()
221 geometryText2Points('', $fRadius)
225 $aPoints = geometryText2Points('POINT(10 20)', $fRadius);
233 [10.062790519529, 20.998026728428],
234 [10.125333233564, 20.992114701314]
236 array_splice($aPoints, 0, 3)
248 geometryText2Points('POLYGON((30 10, 40 40, 20 40, 10 20, 30 10))', $fRadius)
254 ['30', '20'], // first polygon only
259 geometryText2Points('MULTIPOLYGON(((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))', $fRadius)