phpvms/tests/GeoTest.php

61 lines
1.8 KiB
PHP
Raw Permalink Normal View History

<?php
namespace Tests;
use App\Models\Navdata;
use Exception;
2018-01-02 09:02:22 +08:00
use Illuminate\Foundation\Testing\WithoutMiddleware;
class GeoTest extends TestCase
{
2018-01-02 09:02:22 +08:00
use WithoutMiddleware;
public function testClosestPoint()
{
$geoSvc = app('\App\Services\GeoService');
2018-01-02 09:02:22 +08:00
/**
* [2017-12-21 00:54:10] dev.INFO: Looking for ATL
* [2017-12-21 00:54:10] dev.INFO: ATL - 36.58106 x 26.375603
* [2017-12-21 00:54:10] dev.INFO: Looking for SIE
* [2017-12-21 00:54:10] dev.INFO: found 3 for SIE
* [2017-12-21 00:54:10] dev.INFO: name: SIE - 39.0955x-74.800344
* [2017-12-21 00:54:10] dev.INFO: name: SIE - 41.15169x-3.604667
* [2017-12-21 00:54:10] dev.INFO: name: SIE - 52.15527x22.200833
*/
2018-08-27 00:40:04 +08:00
// Start at ATL
$start_point = [36.58106, 26.375603];
2018-08-27 00:40:04 +08:00
// These are all SIE
$potential_points = [
[39.0955, -74.800344],
[41.15169, -3.604667],
[52.15527, 22.200833],
];
$coords = $geoSvc->getClosestCoords($start_point, $potential_points);
$this->assertEquals([52.15527, 22.200833], $coords);
}
2018-01-02 09:02:22 +08:00
/**
* Make sure the departure airports/sid/star are all filtered out
2018-08-27 02:51:47 +08:00
*
2018-08-27 02:50:08 +08:00
* @throws Exception
2018-01-02 09:02:22 +08:00
*/
public function testGetCoords()
{
$geoSvc = app('\App\Services\GeoService');
$route = [];
$nav_count = random_int(5, 20);
$navpoints = Navdata::factory()->count($nav_count)->create();
2018-01-02 09:02:22 +08:00
foreach ($navpoints as $point) {
$route[] = $point->id;
}
$route_str = 'KAUS SID '.implode(' ', $route).' STAR KJFK';
$coords = $geoSvc->getCoordsFromRoute('KAUS', 'KJFK', [0, 0], $route_str);
$this->assertCount($nav_count, $coords);
2018-01-02 09:02:22 +08:00
}
}