5 class LibTest extends \PHPUnit\Framework\TestCase
8 public function testAddQuotes()
10 // FIXME: not quoting existing quote signs is probably a bug
11 $this->assertSame("'St. John's'", addQuotes("St. John's"));
12 $this->assertSame("''", addQuotes(''));
16 public function testCreatePointsAroundCenter()
18 // you might say we're creating a circle
19 $aPoints = createPointsAroundCenter(0, 0, 2);
28 array('', 0.12558103905863, 1.9960534568565),
29 array('', 0.25066646712861, 1.984229402629)
31 array_splice($aPoints, 0, 3)
36 public function testGeometryText2Points()
42 geometryText2Points('', $fRadius)
46 $aPoints = geometryText2Points('POINT(10 20)', $fRadius);
54 array(10.062790519529, 20.998026728428),
55 array(10.125333233564, 20.992114701314)
57 array_splice($aPoints, 0, 3)
69 geometryText2Points('POLYGON((30 10, 40 40, 20 40, 10 20, 30 10))', $fRadius)
75 array('30', '20'), // first polygon only
80 geometryText2Points('MULTIPOLYGON(((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))', $fRadius)
84 public function testParseLatLon()
86 // no coordinates expected
87 $this->assertFalse(parseLatLon(''));
88 $this->assertFalse(parseLatLon('abc'));
89 $this->assertFalse(parseLatLon('12 34'));
91 // coordinates expected
92 $this->assertNotNull(parseLatLon('0.0 -0.0'));
94 $aRes = parseLatLon(' abc 12.456 -78.90 def ');
95 $this->assertEquals($aRes[1], 12.456);
96 $this->assertEquals($aRes[2], -78.90);
97 $this->assertEquals($aRes[0], ' 12.456 -78.90 ');
99 $aRes = parseLatLon(' [12.456,-78.90] ');
100 $this->assertEquals($aRes[1], 12.456);
101 $this->assertEquals($aRes[2], -78.90);
102 $this->assertEquals($aRes[0], ' [12.456,-78.90] ');
104 $aRes = parseLatLon(' -12.456,-78.90 ');
105 $this->assertEquals($aRes[1], -12.456);
106 $this->assertEquals($aRes[2], -78.90);
107 $this->assertEquals($aRes[0], ' -12.456,-78.90 ');
109 // http://en.wikipedia.org/wiki/Geographic_coordinate_conversion
110 // these all represent the same location
112 '40 26.767 N 79 58.933 W',
113 '40° 26.767′ N 79° 58.933′ W',
114 "40° 26.767' N 79° 58.933' W",
115 'N 40 26.767, W 79 58.933',
116 'N 40°26.767′, W 79°58.933′',
117 "N 40°26.767', W 79°58.933'",
119 '40 26 46 N 79 58 56 W',
120 '40° 26′ 46″ N 79° 58′ 56″ W',
121 '40° 26′ 46.00″ N 79° 58′ 56.00″ W',
122 '40°26′46″N 79°58′56″W',
123 'N 40 26 46 W 79 58 56',
124 'N 40° 26′ 46″, W 79° 58′ 56″',
125 'N 40° 26\' 46", W 79° 58\' 56"',
129 '40.446° N 79.982° W',
130 'N 40.446° W 79.982°',
133 ' 40.446 , -79.982 ',
137 foreach ($aQueries as $sQuery) {
138 $aRes = parseLatLon($sQuery);
139 $this->assertEquals(40.446, $aRes[1], 'degrees decimal ' . $sQuery, 0.01);
140 $this->assertEquals(-79.982, $aRes[2], 'degrees decimal ' . $sQuery, 0.01);
141 $this->assertEquals($sQuery, $aRes[0]);
145 private function closestHouseNumberEvenOddOther($startnumber, $endnumber, $fraction, $aExpected)
147 foreach (array('even', 'odd', 'other') as $itype) {
150 closestHouseNumber(array(
151 'startnumber' => $startnumber,
152 'endnumber' => $endnumber,
153 'fraction' => $fraction,
154 'interpolationtype' => $itype
156 "$startnumber => $endnumber, $fraction, $itype"
161 public function testClosestHouseNumber()
163 $this->closestHouseNumberEvenOddOther(50, 100, 0.5, array('even' => 76, 'odd' => 75, 'other' => 75));
165 $this->closestHouseNumberEvenOddOther(50, 100, 1.5, array('even' => 100, 'odd' => 100, 'other' => 100));
167 $this->closestHouseNumberEvenOddOther(50, 100, -0.5, array('even' => 50, 'odd' => 50, 'other' => 50));
169 $this->closestHouseNumberEvenOddOther(50, 100, 0, array('even' => 50, 'odd' => 51, 'other' => 50));
171 $this->closestHouseNumberEvenOddOther(50, 50, 0.5, array('even' => 50, 'odd' => 50, 'other' => 50));