From f8464a28dd77e7265fb2cc9c110e490bc5902b92 Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Sun, 16 May 2021 16:21:49 +0100 Subject: [PATCH] feat(sids): validate the runways used on sids and stars (#148) Used to use just airfield, now do both. --- ...port.cs => AllSidsMustHaveAValidRunway.cs} | 14 ++--- src/Compiler/Validate/OutputValidator.cs | 4 +- .../AllSidsMustHaveAValidAirportTest.cs | 49 ----------------- .../AllSidsMustHaveAValidRunwayTest.cs | 55 +++++++++++++++++++ 4 files changed, 61 insertions(+), 61 deletions(-) rename src/Compiler/Validate/{AllSidsMustHaveAValidAirport.cs => AllSidsMustHaveAValidRunway.cs} (52%) delete mode 100644 tests/CompilerTest/Validate/AllSidsMustHaveAValidAirportTest.cs create mode 100644 tests/CompilerTest/Validate/AllSidsMustHaveAValidRunwayTest.cs diff --git a/src/Compiler/Validate/AllSidsMustHaveAValidAirport.cs b/src/Compiler/Validate/AllSidsMustHaveAValidRunway.cs similarity index 52% rename from src/Compiler/Validate/AllSidsMustHaveAValidAirport.cs rename to src/Compiler/Validate/AllSidsMustHaveAValidRunway.cs index e8ff8d63..273cd6cd 100644 --- a/src/Compiler/Validate/AllSidsMustHaveAValidAirport.cs +++ b/src/Compiler/Validate/AllSidsMustHaveAValidRunway.cs @@ -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)); } } diff --git a/src/Compiler/Validate/OutputValidator.cs b/src/Compiler/Validate/OutputValidator.cs index c6a78d63..fe1f4707 100644 --- a/src/Compiler/Validate/OutputValidator.cs +++ b/src/Compiler/Validate/OutputValidator.cs @@ -16,7 +16,6 @@ public class OutputValidator new AllColoursMustHaveAUniqueId(), new AllFixesMustBeUnique(), new AllSidsMustBeUnique(), - new AllSidsMustHaveAValidAirport(), new AllSidsMustHaveAValidRoute(), new AllSctSidsMustHaveAValidRoute(), new AllSctStarsMustHaveAValidRoute(), @@ -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) diff --git a/tests/CompilerTest/Validate/AllSidsMustHaveAValidAirportTest.cs b/tests/CompilerTest/Validate/AllSidsMustHaveAValidAirportTest.cs deleted file mode 100644 index 16802349..00000000 --- a/tests/CompilerTest/Validate/AllSidsMustHaveAValidAirportTest.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Xunit; -using Compiler.Model; -using Compiler.Validate; -using CompilerTest.Bogus.Factory; - -namespace CompilerTest.Validate -{ - public class AllSidsMustHaveAValidAirportTest: AbstractValidatorTestCase - { - private readonly SidStar sid1; - private readonly SidStar sid2; - private readonly SidStar sid3; - - public AllSidsMustHaveAValidAirportTest() - { - sid1 = SidStarFactory.Make(airport: "EGKK"); - sid2 = SidStarFactory.Make(airport: "EGCC"); - sid3 = SidStarFactory.Make(airport: "EGBB"); - - sectorElements.Add(AirportFactory.Make("EGKK")); - sectorElements.Add(AirportFactory.Make("EGLL")); - sectorElements.Add(AirportFactory.Make("EGCC")); - } - - [Fact] - public void TestItPassesOnAllValid() - { - sectorElements.Add(sid1); - sectorElements.Add(sid2); - - AssertNoValidationErrors(); - } - - [Fact] - public void TestItFailsOnInvalidAirport() - { - sectorElements.Add(sid1); - sectorElements.Add(sid2); - sectorElements.Add(sid3); - - AssertValidationErrors(); - } - - protected override IValidationRule GetValidationRule() - { - return new AllSidsMustHaveAValidAirport(); - } - } -} diff --git a/tests/CompilerTest/Validate/AllSidsMustHaveAValidRunwayTest.cs b/tests/CompilerTest/Validate/AllSidsMustHaveAValidRunwayTest.cs new file mode 100644 index 00000000..4eab53e6 --- /dev/null +++ b/tests/CompilerTest/Validate/AllSidsMustHaveAValidRunwayTest.cs @@ -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(); + } + } +}