
Mark Schrer - 2011-09-28 12:12:56 -
In reply to message 1 from Mick89
i just wrote a test case for the class (suits as example as well)
to ensure it works correctly
in case anyone is interested:
App::import('Lib', 'Tools.GeoLib');
/**
* GeoLib based on GeoToolsClass
* 2011-09-28 ms
*/
class GeoLibCase extends CakeTestCase {
function startTest() {
$this->Geo = new GeoLib();
}
function testDistanceBetweenCoords() {
$munich = array('lat'=>48.1, 'lng'=>11.6);
$berlin = array('lat'=>52.5, 'lng'=>13.4);
$is = $this->Geo->distanceBetweenCoords($munich['lat'], $munich['lng'], $berlin['lat'], $berlin['lng']);
pr($is);
$this->assertTrue($is > 500000 && $is < 510000);
}
function testBearingBetweenCoords() {
$munich = array('lat'=>48.1, 'lng'=>11.6);
$berlin = array('lat'=>52.5, 'lng'=>13.4);
$is = $this->Geo->bearingBetweenCoords($munich['lat'], $munich['lng'], $berlin['lat'], $berlin['lng']);
pr($is);
$this->assertIdentical($is, 14);
}
function testMirrerBearing() {
$is = $this->Geo->mirrorBearing(14);
pr($is);
$this->assertIdentical($is, 346);
$is = $this->Geo->mirrorBearing(14, 'x');
pr($is);
$this->assertIdentical($is, 166);
}
function testCalcLatLong() {
$munich = array('lat'=>48.1, 'lng'=>11.6);
$berlin = array('lat'=>52.5, 'lng'=>13.4);
$is = $this->Geo->calcLatLong($munich['lat'], $munich['lng'], $this->Geo->distanceBetweenCoords($munich['lat'], $munich['lng'], $berlin['lat'], $berlin['lng']), $this->Geo->bearingBetweenCoords($munich['lat'], $munich['lng'], $berlin['lat'], $berlin['lng']));
pr($is);
$this->assertEqual((int)$is['lat'], (int)$berlin['lat']);
$this->assertEqual((int)$is['lng'], (int)$berlin['lng']);
}