5 require_once '../../lib/lib.php';
6 require_once '../../lib/ClassTypes.php';
8 class LibTest extends \PHPUnit_Framework_TestCase
10 public function testGetClassTypesWithImportance()
12 $aClasses = ClassTypes\getListWithImportance();
14 $this->assertGreaterThan(
23 'icon' => 'poi_boundary_administrative',
28 $aClasses['place:country']
33 public function testGetResultDiameter()
35 $aResult = array('class' => '', 'type' => '');
38 ClassTypes\getProperty($aResult, 'defdiameter', 0.0001)
41 $aResult = array('class' => 'place', 'type' => 'country');
44 ClassTypes\getProperty($aResult, 'defdiameter', 0.0001)
47 $aResult = array('class' => 'boundary', 'type' => 'administrative', 'admin_level' => 6);
50 ClassTypes\getProperty($aResult, 'defdiameter', 0.0001)
55 public function testAddQuotes()
57 // FIXME: not quoting existing quote signs is probably a bug
58 $this->assertSame("'St. John's'", addQuotes("St. John's"));
59 $this->assertSame("''", addQuotes(''));
63 public function testCreatePointsAroundCenter()
65 // you might say we're creating a circle
66 $aPoints = createPointsAroundCenter(0, 0, 2);
75 array('', 0.12558103905863, 1.9960534568565),
76 array('', 0.25066646712861, 1.984229402629)
78 array_splice($aPoints, 0, 3)
83 public function testGeometryText2Points()
89 geometryText2Points('', $fRadius)
93 $aPoints = geometryText2Points('POINT(10 20)', $fRadius);
101 array(10.062790519529, 20.998026728428),
102 array(10.125333233564, 20.992114701314)
104 array_splice($aPoints, 0, 3)
116 geometryText2Points('POLYGON((30 10, 40 40, 20 40, 10 20, 30 10))', $fRadius)
122 array('30', '20'), // first polygon only
127 geometryText2Points('MULTIPOLYGON(((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))', $fRadius)
131 public function testParseLatLon()
133 // no coordinates expected
134 $this->assertFalse(parseLatLon(''));
135 $this->assertFalse(parseLatLon('abc'));
136 $this->assertFalse(parseLatLon('12 34'));
138 // coordinates expected
139 $this->assertNotNull(parseLatLon('0.0 -0.0'));
141 $aRes = parseLatLon(' abc 12.456 -78.90 def ');
142 $this->assertEquals($aRes[1], 12.456);
143 $this->assertEquals($aRes[2], -78.90);
144 $this->assertEquals($aRes[0], ' 12.456 -78.90 ');
146 $aRes = parseLatLon(' [12.456,-78.90] ');
147 $this->assertEquals($aRes[1], 12.456);
148 $this->assertEquals($aRes[2], -78.90);
149 $this->assertEquals($aRes[0], ' [12.456,-78.90] ');
151 $aRes = parseLatLon(' -12.456,-78.90 ');
152 $this->assertEquals($aRes[1], -12.456);
153 $this->assertEquals($aRes[2], -78.90);
154 $this->assertEquals($aRes[0], ' -12.456,-78.90 ');
156 // http://en.wikipedia.org/wiki/Geographic_coordinate_conversion
157 // these all represent the same location
159 '40 26.767 N 79 58.933 W',
160 '40° 26.767′ N 79° 58.933′ W',
161 "40° 26.767' N 79° 58.933' W",
162 'N 40 26.767, W 79 58.933',
163 'N 40°26.767′, W 79°58.933′',
164 "N 40°26.767', W 79°58.933'",
166 '40 26 46 N 79 58 56 W',
167 '40° 26′ 46″ N 79° 58′ 56″ W',
168 '40° 26′ 46.00″ N 79° 58′ 56.00″ W',
169 '40°26′46″N 79°58′56″W',
170 'N 40 26 46 W 79 58 56',
171 'N 40° 26′ 46″, W 79° 58′ 56″',
172 'N 40° 26\' 46", W 79° 58\' 56"',
176 '40.446° N 79.982° W',
177 'N 40.446° W 79.982°',
180 ' 40.446 , -79.982 ',
184 foreach ($aQueries as $sQuery) {
185 $aRes = parseLatLon($sQuery);
186 $this->assertEquals(40.446, $aRes[1], 'degrees decimal ' . $sQuery, 0.01);
187 $this->assertEquals(-79.982, $aRes[2], 'degrees decimal ' . $sQuery, 0.01);
188 $this->assertEquals($sQuery, $aRes[0]);
192 private function closestHouseNumberEvenOddOther($startnumber, $endnumber, $fraction, $aExpected)
194 foreach (array('even', 'odd', 'other') as $itype) {
197 closestHouseNumber(array(
198 'startnumber' => $startnumber,
199 'endnumber' => $endnumber,
200 'fraction' => $fraction,
201 'interpolationtype' => $itype
203 "$startnumber => $endnumber, $fraction, $itype"
208 public function testClosestHouseNumber()
210 $this->closestHouseNumberEvenOddOther(50, 100, 0.5, array('even' => 76, 'odd' => 75, 'other' => 75));
212 $this->closestHouseNumberEvenOddOther(50, 100, 1.5, array('even' => 100, 'odd' => 100, 'other' => 100));
214 $this->closestHouseNumberEvenOddOther(50, 100, -0.5, array('even' => 50, 'odd' => 50, 'other' => 50));
216 $this->closestHouseNumberEvenOddOther(50, 100, 0, array('even' => 50, 'odd' => 51, 'other' => 50));
218 $this->closestHouseNumberEvenOddOther(50, 50, 0.5, array('even' => 50, 'odd' => 50, 'other' => 50));