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)
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",
69 'N 40 26.767, W 79 58.933',
70 'N 40°26.767′, W 79°58.933′',
71 "N 40°26.767', W 79°58.933'",
73 '40 26 46 N 79 58 56 W',
74 '40° 26′ 46″ N 79° 58′ 56″ W',
75 '40° 26′ 46.00″ N 79° 58′ 56.00″ W',
76 '40°26′46″N 79°58′56″W',
77 'N 40 26 46 W 79 58 56',
78 'N 40° 26′ 46″, W 79° 58′ 56″',
79 'N 40° 26\' 46", W 79° 58\' 56"',
83 '40.446° N 79.982° W',
84 'N 40.446° W 79.982°',
91 foreach ($aQueries as $sQuery) {
92 $aRes = parseLatLon($sQuery);
93 $this->assertEquals(40.446, $aRes[1], 'degrees decimal ' . $sQuery, 0.01);
94 $this->assertEquals(-79.982, $aRes[2], 'degrees decimal ' . $sQuery, 0.01);
95 $this->assertEquals($sQuery, $aRes[0]);
99 private function closestHouseNumberEvenOddOther($startnumber, $endnumber, $fraction, $aExpected)
101 foreach (array('even', 'odd', 'other') as $itype) {
104 closestHouseNumber(array(
105 'startnumber' => $startnumber,
106 'endnumber' => $endnumber,
107 'fraction' => $fraction,
108 'interpolationtype' => $itype
110 "$startnumber => $endnumber, $fraction, $itype"
115 public function testClosestHouseNumber()
117 $this->closestHouseNumberEvenOddOther(50, 100, 0.5, array('even' => 76, 'odd' => 75, 'other' => 75));
119 $this->closestHouseNumberEvenOddOther(50, 100, 1.5, array('even' => 100, 'odd' => 100, 'other' => 100));
121 $this->closestHouseNumberEvenOddOther(50, 100, -0.5, array('even' => 50, 'odd' => 50, 'other' => 50));
123 $this->closestHouseNumberEvenOddOther(50, 100, 0, array('even' => 50, 'odd' => 51, 'other' => 50));
125 $this->closestHouseNumberEvenOddOther(50, 50, 0.5, array('even' => 50, 'odd' => 50, 'other' => 50));
128 public function testGetSearchRankLabel()
130 $this->assertEquals('unknown', getSearchRankLabel(null));
131 $this->assertEquals('continent', getSearchRankLabel(0));
132 $this->assertEquals('continent', getSearchRankLabel(1));
133 $this->assertEquals('other: 30', getSearchRankLabel(30));