Skip to content

Commit

Permalink
Fix false-pos test and reformat things
Browse files Browse the repository at this point in the history
  • Loading branch information
atoff committed Nov 18, 2019
1 parent 98d0324 commit 376a4b7
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 69 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor
\.phpunit\.result\.cache
.idea
16 changes: 8 additions & 8 deletions examples/airacfordate.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?php
require('../vendor/autoload.php');

use CobaltGrid\Aviation\AIRACCalculator;
use Carbon\Carbon;
use CobaltGrid\Aviation\AIRACCalculator;

$date = Carbon::now();
if($_GET['date']){
if ($_GET['date']) {
$date = new Carbon($_GET['date']);
}
?>

<form>
Date (in format 19 JUN 2019 10:30):
<input type='text' name='date' />
<input type='submit' value='Submit' />
</form>
<form>
Date (in format 19 JUN 2019 10:30):
<input type='text' name='date'/>
<input type='submit' value='Submit'/>
</form>

<?php

echo "'Current' Date: ".$date->format('d M Y H:i')."</br>";
echo "'Current' Date: " . $date->format('d M Y H:i') . "</br>";
echo "The current AIRAC is " . AIRACCalculator::currentAiracCycle($date) . ", which became effective at " . AIRACCalculator::dateForCycle(AIRACCalculator::currentAiracCycle($date))->format('d/m/Y') . '</br>';
echo "The next effective AIRAC is " . AIRACCalculator::nextAiracCycle($date) . ", which becomes effective at " . AIRACCalculator::nextAiracDate($date)->format('d/m/Y');
32 changes: 16 additions & 16 deletions examples/airacyear.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?php
require('../vendor/autoload.php');

use CobaltGrid\Aviation\AIRACCalculator;
use Carbon\Carbon;
use CobaltGrid\Aviation\AIRACCalculator;

$date = Carbon::now();
if($_GET['year']){
$date = new Carbon($_GET['year'].'-01-01');
if ($_GET['year']) {
$date = new Carbon($_GET['year'] . '-01-01');
}
?>

<form>
AIRAC Year (in format 2019):
<input type='text' name='year' />
<input type='submit' value='Submit' />
<input type='text' name='year'/>
<input type='submit' value='Submit'/>
</form>

<?php
Expand All @@ -23,21 +23,21 @@
?>
<table>
<thead>
<tr>
<th>Cycle</th>
<th>Effective Date</th>
</tr>
<tr>
<th>Cycle</th>
<th>Effective Date</th>
</tr>
</thead>
<tbody>
<?php
foreach($cycles as $cycle){
<?php
foreach ($cycles as $cycle) {
?>
<tr>
<td><?= $cycle[0]?></td>
<td><?= $cycle[1]?></td>
</tr>
<td><?= $cycle[0] ?></td>
<td><?= $cycle[1] ?></td>
</tr>
<?php
}
?>
}
?>
</tbody>
</table>
1 change: 0 additions & 1 deletion examples/currentairac.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
require('../vendor/autoload.php');

use CobaltGrid\Aviation\AIRACCalculator;
use Carbon\Carbon;

echo "The current AIRAC is " . AIRACCalculator::currentAiracCycle() . ", which became effective at " . AIRACCalculator::dateForCycle(AIRACCalculator::currentAiracCycle());
1 change: 0 additions & 1 deletion examples/nextairac.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
require('../vendor/autoload.php');

use CobaltGrid\Aviation\AIRACCalculator;
use Carbon\Carbon;

echo "The next effective AIRAC is " . AIRACCalculator::nextAiracCycle() . ", which becomes effective at " . AIRACCalculator::nextAiracDate()->format('d/m/Y');
26 changes: 13 additions & 13 deletions tests/AccuracyTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

use Carbon\Carbon;
use PHPUnit\Framework\TestCase;
use CobaltGrid\Aviation\AIRACCalculator;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DomCrawler\Crawler;

final class AccuracyTest extends TestCase
Expand All @@ -11,30 +11,30 @@ public function testItWillGiveCorrectDatumDate(): void
{
$this->assertEquals(new Carbon(AIRACCalculator::$datumDate), AIRACCalculator::dateForCycle(AIRACCalculator::$datumCycle));
}

public function testItIsTheSameAsOfficalSource(): void
{
$crawler = new Crawler(file_get_contents('https://www.nm.eurocontrol.int/RAD/common/airac_dates.html'));

$years = $crawler->filter('table table');
// Check that it finds 5 years as expected
$this->assertEquals(5, count($years));
foreach ($years as $year){
// Check that it finds 4/5 years as expected
$this->assertContains(count($years), [4, 5]);

foreach ($years as $year) {
$year = new Crawler($year);

$cycles = $year->filter('tr');

// Disregard first two rows
for($i = 2;$i < count($cycles);$i++){
for ($i = 2; $i < count($cycles); $i++) {
$cycle = $cycles->eq($i);

$cycleNumber = $cycle->filter('td:nth-of-type(2)')->text();
$cycleDate = new Carbon($cycle->filter('td:nth-of-type(5)')->text());

$this->assertEquals($cycleDate, AIRACCalculator::dateForCycle($cycleNumber));
}
}
}

}
37 changes: 18 additions & 19 deletions tests/CurrentAiracTest.php
Original file line number Diff line number Diff line change
@@ -1,67 +1,66 @@
<?php

use Carbon\Carbon;
use PHPUnit\Framework\TestCase;
use CobaltGrid\Aviation\AIRACCalculator;
use Symfony\Component\DomCrawler\Crawler;
use PHPUnit\Framework\TestCase;

final class CurrentAiracTest extends TestCase
{
public function testItReportsCorrectCurrentAirac(): void
{
// 1906 cycle effective at 23 MAY 19
// 1907 cycle effective at 20 JUN 19

Carbon::setTestNow(new Carbon('19 JUN 19 10:10:10'));
$this->assertEquals('1906', AIRACCalculator::currentAiracCycle());

Carbon::setTestNow(new Carbon('19 JUN 19 23:59:59'));
$this->assertEquals('1906', AIRACCalculator::currentAiracCycle());


Carbon::setTestNow(new Carbon('20 JUN 19'));
$this->assertEquals('1907', AIRACCalculator::currentAiracCycle());

Carbon::setTestNow();
}

public function testItReportsCorrectlyOverAYear(): void
{
// 2014 cycle effective at 31 DEC 20
// 2101 cycle effective at 28 JAN 21

Carbon::setTestNow(new Carbon('10 JAN 21'));
$this->assertEquals('2014', AIRACCalculator::currentAiracCycle());

Carbon::setTestNow();
}

public function testItCorrectlyIndicatesIfTodayIsNewAirac(): void
{
// 1906 cycle effective at 23 MAY 19
// 1907 cycle effective at 20 JUN 19

Carbon::setTestNow(new Carbon('20 JUN 19'));
$this->assertTrue(AIRACCalculator::isNewAiracDay());

Carbon::setTestNow(new Carbon('20 JUN 19 14:35:59'));
$this->assertTrue(AIRACCalculator::isNewAiracDay());

Carbon::setTestNow(new Carbon('19 JUN 19 23:59:59'));
$this->assertFalse(AIRACCalculator::isNewAiracDay());

Carbon::setTestNow();
}

public function testItCorrectlyIndicatesIfADateIsNewAirac(): void
{
// 1906 cycle effective at 23 MAY 19
// 1907 cycle effective at 20 JUN 19

$this->assertTrue(AIRACCalculator::isNewAiracDay(new Carbon('20 JUN 19')));

$this->assertTrue(AIRACCalculator::isNewAiracDay(new Carbon('20 JUN 19 14:35:59')));

$this->assertFalse(AIRACCalculator::isNewAiracDay(new Carbon('19 JUN 19 23:59:59')));
}
}
21 changes: 10 additions & 11 deletions tests/CycleListTest.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
<?php

use Carbon\Carbon;
use PHPUnit\Framework\TestCase;
use CobaltGrid\Aviation\AIRACCalculator;
use Symfony\Component\DomCrawler\Crawler;
use PHPUnit\Framework\TestCase;

final class CycleListTest extends TestCase
{
public function testItReturnsCyclesForYear(): void
{
// 2019 has 13 cycles
// 2020 has 14 cycles

$this->assertEquals(13, count(AIRACCalculator::cyclesForYear('2019')));
$this->assertEquals(14, count(AIRACCalculator::cyclesForYear('2020')));

// Assert 2D array
$this->assertEquals(2, count(AIRACCalculator::cyclesForYear('2020')[0]));
}

public function testItReturnsCorrectArray(): void
{
// 2019 has 13 cycles, first cycle 1901 effective 2019-01-03

$cycles = AIRACCalculator::cyclesForYear('2019');

$this->assertEquals("1901", $cycles[0][0]);
$this->assertEquals(new Carbon('2019-01-03'), $cycles[0][1]);


// 2020 has 14 cycles, cycle 2014 effective 2020-12-31

$cycles = AIRACCalculator::cyclesForYear('2020');

$this->assertEquals("2014", $cycles[13][0]);
$this->assertEquals(new Carbon('2020-12-31'), $cycles[13][1]);
}
Expand Down

0 comments on commit 376a4b7

Please sign in to comment.