5 require_once(CONST_BasePath.'/lib/lib.php');
6 require_once(CONST_BasePath.'/lib/ClassTypes.php');
8 class LibTest extends \PHPUnit\Framework\TestCase
11 public function testAddQuotes()
13 // FIXME: not quoting existing quote signs is probably a bug
14 $this->assertSame("'St. John's'", addQuotes("St. John's"));
15 $this->assertSame("''", addQuotes(''));
19 public function testCreatePointsAroundCenter()
21 // you might say we're creating a circle
22 $aPoints = createPointsAroundCenter(0, 0, 2);
31 array('', 0.12558103905863, 1.9960534568565),
32 array('', 0.25066646712861, 1.984229402629)
34 array_splice($aPoints, 0, 3)
39 public function testGeometryText2Points()
45 geometryText2Points('', $fRadius)
49 $aPoints = geometryText2Points('POINT(10 20)', $fRadius);
57 array(10.062790519529, 20.998026728428),
58 array(10.125333233564, 20.992114701314)
60 array_splice($aPoints, 0, 3)
72 geometryText2Points('POLYGON((30 10, 40 40, 20 40, 10 20, 30 10))', $fRadius)
78 array('30', '20'), // first polygon only
83 geometryText2Points('MULTIPOLYGON(((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))', $fRadius)
87 public function testParseLatLon()
89 // no coordinates expected
90 $this->assertFalse(parseLatLon(''));
91 $this->assertFalse(parseLatLon('abc'));
92 $this->assertFalse(parseLatLon('12 34'));
94 // coordinates expected
95 $this->assertNotNull(parseLatLon('0.0 -0.0'));
97 $aRes = parseLatLon(' abc 12.456 -78.90 def ');
98 $this->assertEquals($aRes[1], 12.456);
99 $this->assertEquals($aRes[2], -78.90);
100 $this->assertEquals($aRes[0], ' 12.456 -78.90 ');
102 $aRes = parseLatLon(' [12.456,-78.90] ');
103 $this->assertEquals($aRes[1], 12.456);
104 $this->assertEquals($aRes[2], -78.90);
105 $this->assertEquals($aRes[0], ' [12.456,-78.90] ');
107 $aRes = parseLatLon(' -12.456,-78.90 ');
108 $this->assertEquals($aRes[1], -12.456);
109 $this->assertEquals($aRes[2], -78.90);
110 $this->assertEquals($aRes[0], ' -12.456,-78.90 ');
112 // http://en.wikipedia.org/wiki/Geographic_coordinate_conversion
113 // these all represent the same location
115 '40 26.767 N 79 58.933 W',
116 '40° 26.767′ N 79° 58.933′ W',
117 "40° 26.767' N 79° 58.933' W",
118 'N 40 26.767, W 79 58.933',
119 'N 40°26.767′, W 79°58.933′',
120 "N 40°26.767', W 79°58.933'",
122 '40 26 46 N 79 58 56 W',
123 '40° 26′ 46″ N 79° 58′ 56″ W',
124 '40° 26′ 46.00″ N 79° 58′ 56.00″ W',
125 '40°26′46″N 79°58′56″W',
126 'N 40 26 46 W 79 58 56',
127 'N 40° 26′ 46″, W 79° 58′ 56″',
128 'N 40° 26\' 46", W 79° 58\' 56"',
132 '40.446° N 79.982° W',
133 'N 40.446° W 79.982°',
136 ' 40.446 , -79.982 ',
140 foreach ($aQueries as $sQuery) {
141 $aRes = parseLatLon($sQuery);
142 $this->assertEquals(40.446, $aRes[1], 'degrees decimal ' . $sQuery, 0.01);
143 $this->assertEquals(-79.982, $aRes[2], 'degrees decimal ' . $sQuery, 0.01);
144 $this->assertEquals($sQuery, $aRes[0]);
148 private function closestHouseNumberEvenOddOther($startnumber, $endnumber, $fraction, $aExpected)
150 foreach (array('even', 'odd', 'other') as $itype) {
153 closestHouseNumber(array(
154 'startnumber' => $startnumber,
155 'endnumber' => $endnumber,
156 'fraction' => $fraction,
157 'interpolationtype' => $itype
159 "$startnumber => $endnumber, $fraction, $itype"
164 public function testClosestHouseNumber()
166 $this->closestHouseNumberEvenOddOther(50, 100, 0.5, array('even' => 76, 'odd' => 75, 'other' => 75));
168 $this->closestHouseNumberEvenOddOther(50, 100, 1.5, array('even' => 100, 'odd' => 100, 'other' => 100));
170 $this->closestHouseNumberEvenOddOther(50, 100, -0.5, array('even' => 50, 'odd' => 50, 'other' => 50));
172 $this->closestHouseNumberEvenOddOther(50, 100, 0, array('even' => 50, 'odd' => 51, 'other' => 50));
174 $this->closestHouseNumberEvenOddOther(50, 50, 0.5, array('even' => 50, 'odd' => 50, 'other' => 50));