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(''));
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)
38 public function testParseLatLon()
40 // no coordinates expected
41 $this->assertFalse(parseLatLon(''));
42 $this->assertFalse(parseLatLon('abc'));
43 $this->assertFalse(parseLatLon('12 34'));
45 // coordinates expected
46 $this->assertNotNull(parseLatLon('0.0 -0.0'));
48 $aRes = parseLatLon(' abc 12.456 -78.90 def ');
49 $this->assertEquals($aRes[1], 12.456);
50 $this->assertEquals($aRes[2], -78.90);
51 $this->assertEquals($aRes[0], ' 12.456 -78.90 ');
53 $aRes = parseLatLon(' [12.456,-78.90] ');
54 $this->assertEquals($aRes[1], 12.456);
55 $this->assertEquals($aRes[2], -78.90);
56 $this->assertEquals($aRes[0], ' [12.456,-78.90] ');
58 $aRes = parseLatLon(' -12.456,-78.90 ');
59 $this->assertEquals($aRes[1], -12.456);
60 $this->assertEquals($aRes[2], -78.90);
61 $this->assertEquals($aRes[0], ' -12.456,-78.90 ');
63 // http://en.wikipedia.org/wiki/Geographic_coordinate_conversion
64 // these all represent the same location
66 '40 26.767 N 79 58.933 W',
67 '40° 26.767′ N 79° 58.933′ W',
68 "40° 26.767' N 79° 58.933' W",
71 'N 40 26.767, W 79 58.933',
72 'N 40°26.767′, W 79°58.933′',
73 ' N 40°26.767′, W 79°58.933′',
74 "N 40°26.767', W 79°58.933'",
76 '40 26 46 N 79 58 56 W',
77 '40° 26′ 46″ N 79° 58′ 56″ W',
78 '40° 26′ 46.00″ N 79° 58′ 56.00″ W',
79 '40°26′46″N 79°58′56″W',
80 'N 40 26 46 W 79 58 56',
81 'N 40° 26′ 46″, W 79° 58′ 56″',
82 'N 40° 26\' 46", W 79° 58\' 56"',
83 'N 40° 26\' 46", W 79° 58\' 56"',
87 '40.446° N 79.982° W',
88 'N 40.446° W 79.982°',
95 ' 40.446
\v, -79.982 ',
99 foreach ($aQueries as $sQuery) {
100 $aRes = parseLatLon($sQuery);
101 $this->assertEqualsWithDelta(40.446, $aRes[1], 0.01, 'degrees decimal ' . $sQuery);
102 $this->assertEqualsWithDelta(-79.982, $aRes[2], 0.01, 'degrees decimal ' . $sQuery);
103 $this->assertEquals($sQuery, $aRes[0]);
107 private function closestHouseNumberEvenOddOther($startnumber, $endnumber, $fraction, $aExpected)
109 foreach (array('even', 'odd', 'other') as $itype) {
112 closestHouseNumber(array(
113 'startnumber' => $startnumber,
114 'endnumber' => $endnumber,
115 'fraction' => $fraction,
116 'interpolationtype' => $itype
118 "$startnumber => $endnumber, $fraction, $itype"
123 public function testClosestHouseNumber()
125 $this->closestHouseNumberEvenOddOther(50, 100, 0.5, array('even' => 76, 'odd' => 75, 'other' => 75));
127 $this->closestHouseNumberEvenOddOther(50, 100, 1.5, array('even' => 100, 'odd' => 100, 'other' => 100));
129 $this->closestHouseNumberEvenOddOther(50, 100, -0.5, array('even' => 50, 'odd' => 50, 'other' => 50));
131 $this->closestHouseNumberEvenOddOther(50, 100, 0, array('even' => 50, 'odd' => 51, 'other' => 50));
133 $this->closestHouseNumberEvenOddOther(50, 50, 0.5, array('even' => 50, 'odd' => 50, 'other' => 50));
136 public function testGetSearchRankLabel()
138 $this->assertEquals('unknown', getSearchRankLabel(null));
139 $this->assertEquals('continent', getSearchRankLabel(0));
140 $this->assertEquals('continent', getSearchRankLabel(1));
141 $this->assertEquals('other: 30', getSearchRankLabel(30));