function test_methods in geoPHP 7
Same name and namespace in other branches
- 8 geoPHP/tests/test.php \test_methods()
1 call to test_methods()
- run_test in geoPHP/tests/test.php
File
- geoPHP/tests/test.php, line 175
Code
function test_methods($geometry) {
if (!geoPHP::geosInstalled()) {
return;
}
$methods = array(
'envelope',
'getBBox',
'x',
'y',
'startPoint',
'endPoint',
'isRing',
'isClosed',
'numPoints',
);
foreach ($methods as $method) {
geoPHP::geosInstalled(TRUE);
$geos_result = $geometry
->{$method}();
geoPHP::geosInstalled(FALSE);
$norm_result = $geometry
->{$method}();
geoPHP::geosInstalled(TRUE);
$geos_type = gettype($geos_result);
$norm_type = gettype($norm_result);
if ($geos_type != $norm_type) {
print 'Type mismatch on ' . $method . "\n";
continue;
}
if ($geos_type == 'object') {
$haus_dist = $geos_result
->hausdorffDistance(geoPHP::load($norm_result
->out('wkt'), 'wkt'));
$bb = $geos_result
->getBBox();
$scale = sqrt(($bb['maxy'] - $bb['miny'] ^ 2) + ($bb['maxx'] - $bb['minx'] ^ 2));
if ($haus_dist / $scale > 0.5) {
print 'Output mismatch on ' . $method . ":\n";
print 'GEOS : ' . $geos_result
->out('wkt') . "\n";
print 'NORM : ' . $norm_result
->out('wkt') . "\n";
continue;
}
}
if ($geos_type == 'boolean' || $geos_type == 'string') {
if ($geos_result !== $norm_result) {
print 'Output mismatch on ' . $method . ":\n";
print 'GEOS : ' . (string) $geos_result . "\n";
print 'NORM : ' . (string) $norm_result . "\n";
continue;
}
}
}
}