-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5587024
commit dc45ee5
Showing
5 changed files
with
76 additions
and
2 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
32 changes: 32 additions & 0 deletions
32
src/QSP/RouteFinding/FileExport/Providers/FlightFactorA320Provider.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,32 @@ | ||
using QSP.LibraryExtension; | ||
using QSP.RouteFinding.Routes; | ||
using System; | ||
using System.Linq; | ||
using static QSP.LibraryExtension.Types; | ||
|
||
namespace QSP.RouteFinding.FileExport.Providers | ||
{ | ||
public static class FlightFactorA320Provider | ||
{ | ||
/// <summary> | ||
/// Get string of the flight plan to export. | ||
/// </summary> | ||
/// <exception cref="Exception"></exception> | ||
public static string GetExportText(Route route) | ||
{ | ||
if (route.Count < 2) throw new ArgumentException(); | ||
var from = route.FirstWaypoint.ID.Substring(0, 4); | ||
var to = route.LastWaypoint.ID.Substring(0, 4); | ||
|
||
var str = route.ToString(true); | ||
if (str == "DCT") return $"RTE {from}{to}01 {from} {to}"; | ||
|
||
// Replace SID/STAR with DCT. | ||
var split = str.Split(' '); | ||
if (split.Length < 3) throw new ArgumentException(); | ||
var middle= split.WithoutFirstAndLast(); | ||
var text = string.Join(" ", List("DCT").Concat(middle).Concat(List("DCT"))); | ||
return $"RTE {from}{to}01 {from} {text} {to}"; | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/Tests/UnitTest/RouteFinding/FileExport/Providers/FlightFactorA320ProviderTest.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 NUnit.Framework; | ||
using QSP.LibraryExtension; | ||
using QSP.RouteFinding.Containers; | ||
using QSP.RouteFinding.FileExport.Providers; | ||
|
||
namespace UnitTest.RouteFinding.FileExport.Providers | ||
{ | ||
[TestFixture] | ||
public class FlightFactorA320ProviderTest | ||
{ | ||
[Test] | ||
public void GetExportTextTest() | ||
{ | ||
var route = Common.GetRoute( | ||
new Waypoint("RJBB06L", 0.0, 0.0), "A", -1.0, | ||
new Waypoint("WPT0", 0.0, 10.0), "B", -1.0, | ||
new Waypoint("WPT1", 0.0, -20.0), "DCT", -1.0, | ||
new Waypoint("WPT2", 0.0, 2.5), "C", -1.0, | ||
new Waypoint("RJAA18", 0.0, 3.0)); | ||
|
||
var text = FlightFactorA320Provider.GetExportText(route); | ||
|
||
var expected = "RTE RJBBRJAA01 RJBB DCT WPT0 B WPT1 DCT WPT2 DCT RJAA"; | ||
|
||
Assert.IsTrue(expected.EqualsIgnoreNewlineStyle(text)); | ||
} | ||
|
||
[Test] | ||
public void GetExportTextNoWaypontDoesNotThrow() | ||
{ | ||
var route = Common.GetRoute( | ||
new Waypoint("RJBB06L", 0.0, 0.0), "DCT", -1.0, | ||
new Waypoint("RJAA18", 0.0, 3.0)); | ||
|
||
var text = FlightFactorA320Provider.GetExportText(route); | ||
|
||
var expected = "RTE RJBBRJAA01 RJBB RJAA"; | ||
|
||
Assert.IsTrue(expected.EqualsIgnoreNewlineStyle(text)); | ||
} | ||
} | ||
} |
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