function test_methods in geoPHP 8
Same name and namespace in other branches
- 7 geoPHP/tests/test.php \test_methods()
File
- geoPHP/
tests/ test.php, line 185 - Uncomment to test.
Code
function test_methods($geometry) {
// Cannot test methods if GEOS is not intstalled.
if (!geoPHP::geosInstalled()) {
return;
}
$methods = [
// 'boundary', //@@TODO: Uncomment this and fix errors
// @@TODO: Testing reveales errors in this method -- POINT vs. POLYGON
'envelope',
'getBBox',
'x',
'y',
'startPoint',
'endPoint',
'isRing',
'isClosed',
'numPoints',
];
foreach ($methods as $method) {
// Turn GEOS on.
geoPHP::geosInstalled(TRUE);
$geos_result = $geometry
->{$method}();
// Turn GEOS off.
geoPHP::geosInstalled(FALSE);
$norm_result = $geometry
->{$method}();
// Turn GEOS back On.
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;
}
// Now check base on type.
if ($geos_type == 'object') {
$haus_dist = $geos_result
->hausdorffDistance(geoPHP::load($norm_result
->out('wkt'), 'wkt'));
// Get the length of the diagonal of the bbox - this is used to scale the haustorff distance
// Using Pythagorean theorem.
$bb = $geos_result
->getBBox();
$scale = sqrt(($bb['maxy'] - $bb['miny'] ^ 2) + ($bb['maxx'] - $bb['minx'] ^ 2));
// The difference in the output of GEOS and native-PHP methods should be less than 0.5 scaled haustorff units.
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;
}
}
// @@TODO: Run tests for output of types arrays and float
// @@TODO: centroid function is non-compliant for collections and strings
}
}