Skip to content

Commit

Permalink
feat(validation): check that active runways reference an actual runway
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyTWF committed Jan 29, 2021
1 parent afb2e83 commit 34ac130
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
41 changes: 41 additions & 0 deletions src/Compiler/Validate/AllActiveRunwaysMustReferenceARunway.cs
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);
}
}
}
3 changes: 2 additions & 1 deletion src/Compiler/Validate/OutputValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public class OutputValidator
new AllCoordinationPointsMustHaveValidDepartureRunways(),
new AllCoordinationPointsMustHaveValidArrivalRunways(),
new CentrelineColourIsDefined(),
new AllActiveRunwaysMustReferenceAnAirport()
new AllActiveRunwaysMustReferenceAnAirport(),
new AllActiveRunwaysMustReferenceARunway(),
};

public static void Validate(SectorElementCollection sectorElements, CompilerArguments args, IEventLogger events)
Expand Down
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();
}
}
}

0 comments on commit 34ac130

Please sign in to comment.