-
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): validate that active runway rows are unique
- Loading branch information
Showing
6 changed files
with
99 additions
and
5 deletions.
There are no files selected for viewing
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
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,36 @@ | ||
using System.Linq; | ||
using Compiler.Argument; | ||
using Compiler.Error; | ||
using Compiler.Event; | ||
using Compiler.Model; | ||
|
||
namespace Compiler.Validate | ||
{ | ||
public class AllActiveRunwaysMustBeUnique: IValidationRule | ||
{ | ||
public void Validate(SectorElementCollection sectorElements, CompilerArguments args, IEventLogger events) | ||
{ | ||
var duplicates = sectorElements.ActiveRunways.GroupBy( | ||
runway => runway | ||
) | ||
.Where(g => g.Count() > 1) | ||
.ToList(); | ||
|
||
if (!duplicates.Any()) | ||
{ | ||
return; | ||
} | ||
|
||
foreach (var duplicate in duplicates) | ||
{ | ||
ActiveRunway runway = duplicate.First(); | ||
events.AddEvent( | ||
new ValidationRuleFailure( | ||
$"Duplicate ACTIVE_RUNWAY {runway.Airfield}:{runway.Identifier}:{runway.Mode}", | ||
runway | ||
) | ||
); | ||
} | ||
} | ||
} | ||
} |
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
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
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
37 changes: 37 additions & 0 deletions
37
tests/CompilerTest/Validate/AllActiveRunwaysMustBeUniqueTest.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,37 @@ | ||
using Compiler.Validate; | ||
using CompilerTest.Bogus.Factory; | ||
using Xunit; | ||
|
||
namespace CompilerTest.Validate | ||
{ | ||
public class AllActiveRunwaysMustBeUniqueTest: AbstractValidatorTestCase | ||
{ | ||
[Fact] | ||
public void TestItFailsIfDuplicatesExist() | ||
{ | ||
sectorElements.Add(ActiveRunwayFactory.Make("EGLL", "27R", 1)); | ||
sectorElements.Add(ActiveRunwayFactory.Make("EGLL", "27R", 1)); | ||
sectorElements.Add(ActiveRunwayFactory.Make("EGLL", "27R", 0)); | ||
sectorElements.Add(ActiveRunwayFactory.Make("EGLL", "27L", 1)); | ||
sectorElements.Add(ActiveRunwayFactory.Make("EGLL", "27L", 1)); | ||
sectorElements.Add(ActiveRunwayFactory.Make("EGLL", "27L", 0)); | ||
sectorElements.Add(ActiveRunwayFactory.Make("EGLL", "27L", 0)); | ||
AssertValidationErrors(3); | ||
} | ||
|
||
[Fact] | ||
public void TestItPassesOnNoDuplicates() | ||
{ | ||
sectorElements.Add(ActiveRunwayFactory.Make("EGLL", "27R", 1)); | ||
sectorElements.Add(ActiveRunwayFactory.Make("EGLL", "27R", 0)); | ||
sectorElements.Add(ActiveRunwayFactory.Make("EGLL", "27L", 0)); | ||
sectorElements.Add(ActiveRunwayFactory.Make("EGXY", "27L", 0)); | ||
AssertNoValidationErrors(); | ||
} | ||
|
||
protected override IValidationRule GetValidationRule() | ||
{ | ||
return new AllActiveRunwaysMustBeUnique(); | ||
} | ||
} | ||
} |