5 require_once '../../lib/lib.php';
7 class LibTest extends \PHPUnit_Framework_TestCase
9 public function testGetClassTypesWithImportance()
11 $aClasses = getClassTypesWithImportance();
13 $this->assertGreaterThan(
22 'icon' => 'poi_boundary_administrative',
27 $aClasses['place:country']
32 public function testGetResultDiameter()
37 getResultDiameter($aResult)
40 $aResult = array('class' => 'place', 'type' => 'country');
43 getResultDiameter($aResult)
46 $aResult = array('class' => 'boundary', 'type' => 'administrative', 'admin_level' => 6);
49 getResultDiameter($aResult)
54 public function testAddQuotes()
56 // FIXME: not quoting existing quote signs is probably a bug
57 $this->assertSame("'St. John's'", addQuotes("St. John's"));
58 $this->assertSame("''", addQuotes(''));
62 public function testCreatePointsAroundCenter()
64 // you might say we're creating a circle
65 $aPoints = createPointsAroundCenter(0, 0, 2);
74 ['', 0.12558103905863, 1.9960534568565],
75 ['', 0.25066646712861, 1.984229402629]
77 array_splice($aPoints, 0, 3)
82 public function testGeometryText2Points()
88 geometryText2Points('', $fRadius)
92 $aPoints = geometryText2Points('POINT(10 20)', $fRadius);
100 [10.062790519529, 20.998026728428],
101 [10.125333233564, 20.992114701314]
103 array_splice($aPoints, 0, 3)
115 geometryText2Points('POLYGON((30 10, 40 40, 20 40, 10 20, 30 10))', $fRadius)
121 ['30', '20'], // first polygon only
126 geometryText2Points('MULTIPOLYGON(((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))', $fRadius)
130 public function testParseLatLon()
132 // no coordinates expected
133 $this->assertFalse(parseLatLon(''));
134 $this->assertFalse(parseLatLon('abc'));
135 $this->assertFalse(parseLatLon('12 34'));
137 // coordinates expected
138 $this->assertNotNull(parseLatLon('0.0 -0.0'));
140 $aRes = parseLatLon(' abc 12.456 -78.90 def ');
141 $this->assertEquals($aRes[1], 12.456);
142 $this->assertEquals($aRes[2], -78.90);
143 $this->assertEquals($aRes[0], ' 12.456 -78.90 ');
145 $aRes = parseLatLon(' [12.456,-78.90] ');
146 $this->assertEquals($aRes[1], 12.456);
147 $this->assertEquals($aRes[2], -78.90);
148 $this->assertEquals($aRes[0], ' [12.456,-78.90] ');
150 $aRes = parseLatLon(' -12.456,-78.90 ');
151 $this->assertEquals($aRes[1], -12.456);
152 $this->assertEquals($aRes[2], -78.90);
153 $this->assertEquals($aRes[0], ' -12.456,-78.90 ');
155 // http://en.wikipedia.org/wiki/Geographic_coordinate_conversion
156 // these all represent the same location
158 '40 26.767 N 79 58.933 W',
159 '40° 26.767′ N 79° 58.933′ W',
160 "40° 26.767' N 79° 58.933' W",
161 'N 40 26.767, W 79 58.933',
162 'N 40°26.767′, W 79°58.933′',
163 "N 40°26.767', W 79°58.933'",
165 '40 26 46 N 79 58 56 W',
166 '40° 26′ 46″ N 79° 58′ 56″ W',
167 '40° 26′ 46.00″ N 79° 58′ 56.00″ W',
168 '40°26′46″N 79°58′56″W',
169 'N 40 26 46 W 79 58 56',
170 'N 40° 26′ 46″, W 79° 58′ 56″',
171 'N 40° 26\' 46", W 79° 58\' 56"',
175 '40.446° N 79.982° W',
176 'N 40.446° W 79.982°',
179 ' 40.446 , -79.982 ',
183 foreach ($aQueries as $sQuery) {
184 $aRes = parseLatLon($sQuery);
185 $this->assertEquals(40.446, $aRes[1], 'degrees decimal ' . $sQuery, 0.01);
186 $this->assertEquals(-79.982, $aRes[2], 'degrees decimal ' . $sQuery, 0.01);
187 $this->assertEquals($sQuery, $aRes[0]);
191 private function closestHouseNumberEvenOddOther($startnumber, $endnumber, $fraction, $aExpected)
193 foreach (['even', 'odd', 'other'] as $itype) {
197 'startnumber' => $startnumber,
198 'endnumber' => $endnumber,
199 'fraction' => $fraction,
200 'interpolationtype' => $itype
202 "$startnumber => $endnumber, $fraction, $itype"
207 public function testClosestHouseNumber()
209 $this->closestHouseNumberEvenOddOther(50, 100, 0.5, ['even' => 76, 'odd' => 75, 'other' => 75]);
211 $this->closestHouseNumberEvenOddOther(50, 100, 1.5, ['even' => 100, 'odd' => 100, 'other' => 100]);
213 $this->closestHouseNumberEvenOddOther(50, 100, -0.5, ['even' => 50, 'odd' => 50, 'other' => 50]);
215 $this->closestHouseNumberEvenOddOther(50, 100, 0, ['even' => 50, 'odd' => 51, 'other' => 50]);
217 $this->closestHouseNumberEvenOddOther(50, 50, 0.5, ['even' => 50, 'odd' => 50, 'other' => 50]);