Skip to content

Commit

Permalink
feat(sids): validate the runways used on sids and stars (#148)
Browse files Browse the repository at this point in the history
Used to use just airfield, now do both.
  • Loading branch information
AndyTWF authored May 16, 2021
1 parent 239a796 commit f8464a2
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
using System.Linq;
using Compiler.Event;
using Compiler.Event;
using Compiler.Error;
using Compiler.Model;
using Compiler.Argument;

namespace Compiler.Validate
{
public class AllSidsMustHaveAValidAirport : IValidationRule
public class AllSidsMustHaveAValidRunway : AbstractCoordinationPointRunwayChecker, IValidationRule
{
public void Validate(SectorElementCollection sectorElements, CompilerArguments args, IEventLogger events)
{
foreach(SidStar sidStar in sectorElements.SidStars)
{
bool airportExists = sectorElements.Airports
.Count(airport => sidStar.Airport == airport.Icao) != 0;

if (!airportExists)
{
if (!RunwayValid(sectorElements, sidStar.Runway, sidStar.Airport)) {
string errorMessage =
$"Airport {sidStar.Airport} is not valid for {sidStar.Type}/{sidStar.Identifier}";

$"Runway {sidStar.Airport}/{sidStar.Runway} is not valid for {sidStar.Type}/{sidStar.Identifier}";
events.AddEvent(new ValidationRuleFailure(errorMessage, sidStar));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Validate/OutputValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class OutputValidator
new AllColoursMustHaveAUniqueId(),
new AllFixesMustBeUnique(),
new AllSidsMustBeUnique(),
new AllSidsMustHaveAValidAirport(),
new AllSidsMustHaveAValidRoute(),
new AllSctSidsMustHaveAValidRoute(),
new AllSctStarsMustHaveAValidRoute(),
Expand Down Expand Up @@ -55,7 +54,8 @@ public class OutputValidator
new AllActiveRunwaysMustBeUnique(),
new AllRunwayExitsMustHaveAValidRunway(),
new OwnersMayOnlyAppearOnceInSectorOwnership(),
new AltOwnersMayOnlyAppearOnceInEachAltOwnershipLine()
new AltOwnersMayOnlyAppearOnceInEachAltOwnershipLine(),
new AllSidsMustHaveAValidRunway()
};

public static void Validate(SectorElementCollection sectorElements, CompilerArguments args, IEventLogger events)
Expand Down
49 changes: 0 additions & 49 deletions tests/CompilerTest/Validate/AllSidsMustHaveAValidAirportTest.cs

This file was deleted.

55 changes: 55 additions & 0 deletions tests/CompilerTest/Validate/AllSidsMustHaveAValidRunwayTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Xunit;
using Compiler.Model;
using Compiler.Validate;
using CompilerTest.Bogus.Factory;

namespace CompilerTest.Validate
{
public class AllSidsMustHaveAValidRunwayTest: AbstractValidatorTestCase
{
private readonly SidStar sid1;
private readonly SidStar sid2;
private readonly SidStar sid3;
private readonly SidStar sid4;

public AllSidsMustHaveAValidRunwayTest()
{
sid1 = SidStarFactory.Make(airport: "EGKK", runway: "26L");
sid2 = SidStarFactory.Make(airport: "EGCC", runway: "23R");
sid3 = SidStarFactory.Make(airport: "EGBB", runway: "16");
sid4 = SidStarFactory.Make(airport: "EGKB", runway: "08");

sectorElements.Add(AirportFactory.Make("EGKK"));
sectorElements.Add(AirportFactory.Make("EGCC"));
sectorElements.Add(AirportFactory.Make("EGBB"));
sectorElements.Add(RunwayFactory.Make("EGKK", "26L", "08R"));
sectorElements.Add(RunwayFactory.Make("EGCC", "23R", "05L"));
sectorElements.Add(RunwayFactory.Make("EGBB", "33", "15"));
}

[Fact]
public void TestItPassesOnAllValid()
{
sectorElements.Add(sid1);
sectorElements.Add(sid2);

AssertNoValidationErrors();
}

[Fact]
public void TestItFailsOnInvalidAirport()
{
sectorElements.Add(sid1);
sectorElements.Add(sid2);
sectorElements.Add(sid3); // Airport exists, not runway
sectorElements.Add(sid4); // Airport doesn't exist

AssertValidationErrors(2);
}

protected override IValidationRule GetValidationRule()
{
return new AllSidsMustHaveAValidRunway();
}
}
}

0 comments on commit f8464a2

Please sign in to comment.