public function testDistance() { $location1 = new Location(42.7186, -84.46846600000001); // Michigan State University $location2 = new Location(42.274919, -83.740672); // University of Michigan $distance = $location1->distance($location2, 'yee'); $this->assertTrue(is_float($distance)); // Because these are very long numbers we round to mm. $this->assertEquals(77390.178, round($distance, 3)); }
public function testGoogle() { $google = new Location(37.422045, -122.084347); // Google HQ $sf = new Location(37.77493, -122.419416); // San Fransisco, CA $ef = new Location(48.8582, 2.294407); // Eiffel Tower $opera = new Location(-33.856553, 151.214696); // Sydney Opera House $this->assertEquals(49087.066, round($google->distance($sf, 'vincenty'), 3)); $this->assertEquals(8989724.399, round($google->distance($ef, 'vincenty'), 3)); $this->assertEquals(11939773.64, round($google->distance($opera, 'vincenty'), 3)); }
public function testExceptions() { $location = new Location(42.7186, -84.46846600000001); $location2 = new Location(42.274919, -83.740672); try { $distance = $location->distance($location2, 'foo'); $this->fail(); } catch (Exception $e) { $this->assertEquals('Distance method not registered.', $e->getMessage()); } $location->registerDistanceMethod('bar', '\\Lootils\\Geo\\DoesNotExist'); try { $distance = $location->distance($location2, 'bar'); $this->fail(); } catch (Exception $e) { $this->assertEquals('The class associated with the name does not exist.', $e->getMessage()); } }