5 require_once(CONST_LibDir.'/lib.php');
6 require_once(CONST_LibDir.'/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(''));
18 public function testParseLatLon()
20 // no coordinates expected
21 $this->assertFalse(parseLatLon(''));
22 $this->assertFalse(parseLatLon('abc'));
23 $this->assertFalse(parseLatLon('12 34'));
25 // coordinates expected
26 $this->assertNotNull(parseLatLon('0.0 -0.0'));
28 $aRes = parseLatLon(' abc 12.456 -78.90 def ');
29 $this->assertEquals($aRes[1], 12.456);
30 $this->assertEquals($aRes[2], -78.90);
31 $this->assertEquals($aRes[0], ' 12.456 -78.90 ');
33 $aRes = parseLatLon(' [12.456,-78.90] ');
34 $this->assertEquals($aRes[1], 12.456);
35 $this->assertEquals($aRes[2], -78.90);
36 $this->assertEquals($aRes[0], ' [12.456,-78.90] ');
38 $aRes = parseLatLon(' -12.456,-78.90 ');
39 $this->assertEquals($aRes[1], -12.456);
40 $this->assertEquals($aRes[2], -78.90);
41 $this->assertEquals($aRes[0], ' -12.456,-78.90 ');
43 // http://en.wikipedia.org/wiki/Geographic_coordinate_conversion
44 // these all represent the same location
46 '40 26.767 N 79 58.933 W',
47 '40° 26.767′ N 79° 58.933′ W',
48 "40° 26.767' N 79° 58.933' W",
51 'N 40 26.767, W 79 58.933',
52 'N 40°26.767′, W 79°58.933′',
53 ' N 40°26.767′, W 79°58.933′',
54 "N 40°26.767', W 79°58.933'",
56 '40 26 46 N 79 58 56 W',
57 '40° 26′ 46″ N 79° 58′ 56″ W',
58 '40° 26′ 46.00″ N 79° 58′ 56.00″ W',
59 '40°26′46″N 79°58′56″W',
60 'N 40 26 46 W 79 58 56',
61 'N 40° 26′ 46″, W 79° 58′ 56″',
62 'N 40° 26\' 46", W 79° 58\' 56"',
63 'N 40° 26\' 46", W 79° 58\' 56"',
67 '40.446° N 79.982° W',
68 'N 40.446° W 79.982°',
75 ' 40.446
\v, -79.982 ',
79 foreach ($aQueries as $sQuery) {
80 $aRes = parseLatLon($sQuery);
81 $this->assertEqualsWithDelta(40.446, $aRes[1], 0.01, 'degrees decimal ' . $sQuery);
82 $this->assertEqualsWithDelta(-79.982, $aRes[2], 0.01, 'degrees decimal ' . $sQuery);
83 $this->assertEquals($sQuery, $aRes[0]);
87 private function closestHouseNumberEvenOddOther($startnumber, $endnumber, $fraction, $aExpected)
89 foreach (array('even', 'odd', 'other') as $itype) {
92 closestHouseNumber(array(
93 'startnumber' => $startnumber,
94 'endnumber' => $endnumber,
95 'fraction' => $fraction,
96 'interpolationtype' => $itype
98 "$startnumber => $endnumber, $fraction, $itype"
103 public function testClosestHouseNumber()
105 $this->closestHouseNumberEvenOddOther(50, 100, 0.5, array('even' => 76, 'odd' => 75, 'other' => 75));
107 $this->closestHouseNumberEvenOddOther(50, 100, 1.5, array('even' => 100, 'odd' => 100, 'other' => 100));
109 $this->closestHouseNumberEvenOddOther(50, 100, -0.5, array('even' => 50, 'odd' => 50, 'other' => 50));
111 $this->closestHouseNumberEvenOddOther(50, 100, 0, array('even' => 50, 'odd' => 51, 'other' => 50));
113 $this->closestHouseNumberEvenOddOther(50, 50, 0.5, array('even' => 50, 'odd' => 50, 'other' => 50));