-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(validation): check that active runways reference an actual runway
- Loading branch information
Showing
3 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/Compiler/Validate/AllActiveRunwaysMustReferenceARunway.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Linq; | ||
using Compiler.Argument; | ||
using Compiler.Error; | ||
using Compiler.Event; | ||
using Compiler.Model; | ||
|
||
namespace Compiler.Validate | ||
{ | ||
public class AllActiveRunwaysMustReferenceARunway: IValidationRule | ||
{ | ||
public void Validate(SectorElementCollection sectorElements, CompilerArguments args, IEventLogger events) | ||
{ | ||
var missingRunways = sectorElements.ActiveRunways | ||
.Where( | ||
activeRunway => !sectorElements.Runways.Exists(runway => IsSameRunway(activeRunway, runway)) | ||
); | ||
|
||
if (missingRunways.Count() == 0) | ||
{ | ||
return; | ||
} | ||
|
||
foreach (ActiveRunway runway in missingRunways) | ||
{ | ||
events.AddEvent( | ||
new ValidationRuleFailure( | ||
$"Ruunway {runway.Airfield}/{runway.Identifier} specified in active runway does not exist", | ||
runway | ||
) | ||
); | ||
} | ||
} | ||
|
||
private bool IsSameRunway(ActiveRunway activeRunway, Runway runway) | ||
{ | ||
return runway.AirfieldIcao == activeRunway.Airfield && | ||
(runway.FirstIdentifier == activeRunway.Identifier || | ||
runway.ReverseIdentifier == activeRunway.Identifier); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
tests/CompilerTest/Validate/AllActiveRunwaysMustReferenceARunwayTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Compiler.Validate; | ||
using CompilerTest.Bogus.Factory; | ||
using Xunit; | ||
|
||
namespace CompilerTest.Validate | ||
{ | ||
public class AllActiveRunwaysMustReferenceARunwayTest: AbstractValidatorTestCase | ||
{ | ||
public AllActiveRunwaysMustReferenceARunwayTest() | ||
{ | ||
sectorElements.Add(RunwayFactory.Make("EGLL", "09R", "27L")); | ||
sectorElements.Add(RunwayFactory.Make("EGKK", "26L", "08R")); | ||
} | ||
|
||
[Theory] | ||
[InlineData("EGLL", "27R")] | ||
[InlineData("EGKK", "26R")] | ||
[InlineData("EGLL", "abc")] | ||
[InlineData("EGGD", "09")] | ||
public void TestItFailsIfRunwayDoesntExist(string icao, string identifier) | ||
{ | ||
sectorElements.Add(ActiveRunwayFactory.Make(icao, identifier)); | ||
AssertValidationErrors(); | ||
} | ||
|
||
[Theory] | ||
[InlineData("EGLL", "09R")] // First identifier match | ||
[InlineData("EGKK", "26L")] // First identifier match | ||
[InlineData("EGLL", "27L")] // Second identifier match | ||
[InlineData("EGKK", "08R")] // Second identifier match | ||
public void TestItPassesIfRunwayExists(string icao, string identifier) | ||
{ | ||
sectorElements.Add(ActiveRunwayFactory.Make(icao, identifier)); | ||
AssertNoValidationErrors(); | ||
} | ||
|
||
protected override IValidationRule GetValidationRule() | ||
{ | ||
return new AllActiveRunwaysMustReferenceARunway(); | ||
} | ||
} | ||
} |