PHP Classes

File: tests/distance/DistanceTest.php

Recommend this page to a friend!
  Classes of Joseluis Laso   jlaso GPS   tests/distance/DistanceTest.php   Download  
File: tests/distance/DistanceTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: jlaso GPS
Calculate the distance between geographic points
Author: By
Last change: Update of tests/distance/DistanceTest.php
Date: 9 months ago
Size: 871 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);

use
JLaso\Gps\Tools;
use
JLaso\Gps\Point;


class
DistanceTest extends PHPUnit_Framework_TestCase
{
   
/**
     * source: www.distace.to/Origin/Destination
     *
     * Paris/Madrid 1.052,69 km #1 Paris (48.856667,2.350987) #2 Madrid (40.416691,-3.700345)
     */
   
function testParisMadridDistance()
    {
       
$distance = Tools::distance(48.856667, 2.350987, 40.416691, -3.700345);
       
// Let assume the result it's okay if the error of calculated distance is less than 1/1000 (1km)
       
$this->assertLessThan(1.052, abs(1052.69 - $distance));

       
// now use the indirect method to calculate distance in the same conditions
       
$madrid = new Point(40.416691,-3.700345);
       
$paris = new Point(48.856667,2.350987);

       
$this->assertLessThan(1.052, abs(1052.69 - $madrid->distanceTo($paris)));
    }

}