5 require '../../lib/lib.php';
7 class NominatimTest extends \PHPUnit_Framework_TestCase
11 protected function setUp()
16 public function testGetClassTypesWithImportance()
18 $aClasses = getClassTypesWithImportance();
20 $this->assertGreaterThan(
29 'icon' => "poi_boundary_administrative",
34 $aClasses['place:country']
39 public function testGetResultDiameter()
44 getResultDiameter($aResult)
47 $aResult = array('class' => 'place', 'type' => 'country');
50 getResultDiameter($aResult)
53 $aResult = array('class' => 'boundary', 'type' => 'administrative', 'admin_level' => 6);
56 getResultDiameter($aResult)
61 public function testAddQuotes()
63 // FIXME: not quoting existing quote signs is probably a bug
64 $this->assertSame("'St. John's'", addQuotes("St. John's"));
65 $this->assertSame("''", addQuotes(''));
69 public function testGetWordSets()
71 // given an array of arrays like
72 // array( array('a','b'), array('c','d') )
73 // returns a summary as string: '(a|b),(c|d)'
76 function serializeSets($aSets)
79 foreach ($aSets as $aSet) {
80 $aParts[] = '(' . join('|', $aSet) . ')';
82 return join(',', $aParts);
87 getWordSets(array(), 0)
92 serializeSets(getWordSets(array("a"), 0))
97 serializeSets(getWordSets(array('a', 'b'), 0))
101 '(a b c),(a|b c),(a|b|c),(a b|c)',
102 serializeSets(getWordSets(array('a', 'b', 'c'), 0))
106 '(a b c d),(a|b c d),(a|b|c d),(a|b|c|d),(a|b c|d),(a b|c d),(a b|c|d),(a b c|d)',
107 serializeSets(getWordSets(array('a', 'b', 'c', 'd'), 0))
113 '(a b c),(c|a b),(c|b|a),(b c|a)',
114 serializeSets(getInverseWordSets(array('a', 'b', 'c'), 0))
118 // make sure we don't create too many sets
120 // 10 words => 511 sets
121 // 15 words => 12911 sets
122 // 18 words => 65536 sets
123 // 20 words => 169766 sets
124 // 22 words => 401930 sets
125 // 28 words => 3505699 sets (needs more than 4GB via 'phpunit -d memory_limit=' to run)
128 count(getWordSets(array_fill(0, 4, 'a'), 0))
134 count(getWordSets(array_fill(0, 18, 'a'), 0))
139 public function testCreatePointsAroundCenter()
141 // you might say we're creating a circle
142 $aPoints = createPointsAroundCenter(0, 0, 2);
151 ['', 0.12558103905863, 1.9960534568565],
152 ['', 0.25066646712861, 1.984229402629]
154 array_splice($aPoints, 0, 3)
159 public function testGeometryText2Points()
165 geometryText2Points('', $fRadius)
169 $aPoints = geometryText2Points('POINT(10 20)', $fRadius);
177 [10.062790519529, 20.998026728428],
178 [10.125333233564, 20.992114701314]
180 array_splice($aPoints, 0, 3)
192 geometryText2Points('POLYGON((30 10, 40 40, 20 40, 10 20, 30 10))', $fRadius)
198 ['30', '20'], // first polygon only
203 geometryText2Points('MULTIPOLYGON(((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))', $fRadius)