From c34ebcf060cbbd9b0d628508fb90f3bee9fbcb9b Mon Sep 17 00:00:00 2001 From: David Chen Date: Sat, 14 Apr 2018 11:53:08 +0800 Subject: [PATCH] Add Jar design Airbus format. --- src/QSP/QSP.csproj | 1 + .../Providers/FlightFactorA320Provider.cs | 18 +------- .../Providers/JarDesignAirbusProvider.cs | 32 ++++++++++++++ .../Providers/FlightFactorA320ProviderTest.cs | 2 +- .../Providers/JarDesignAirbusProviderTest.cs | 42 +++++++++++++++++++ src/Tests/UnitTest/UnitTest.csproj | 1 + 6 files changed, 79 insertions(+), 17 deletions(-) create mode 100644 src/QSP/RouteFinding/FileExport/Providers/JarDesignAirbusProvider.cs create mode 100644 src/Tests/UnitTest/RouteFinding/FileExport/Providers/JarDesignAirbusProviderTest.cs diff --git a/src/QSP/QSP.csproj b/src/QSP/QSP.csproj index 43f93786..d1982c5d 100644 --- a/src/QSP/QSP.csproj +++ b/src/QSP/QSP.csproj @@ -164,6 +164,7 @@ + diff --git a/src/QSP/RouteFinding/FileExport/Providers/FlightFactorA320Provider.cs b/src/QSP/RouteFinding/FileExport/Providers/FlightFactorA320Provider.cs index eae26b3d..1824647e 100644 --- a/src/QSP/RouteFinding/FileExport/Providers/FlightFactorA320Provider.cs +++ b/src/QSP/RouteFinding/FileExport/Providers/FlightFactorA320Provider.cs @@ -1,8 +1,4 @@ -using QSP.LibraryExtension; -using QSP.RouteFinding.Routes; -using System; -using System.Linq; -using static QSP.LibraryExtension.Types; +using QSP.RouteFinding.Routes; namespace QSP.RouteFinding.FileExport.Providers { @@ -14,19 +10,9 @@ public static class FlightFactorA320Provider /// 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}"; + return $"RTE {from}{to}01 " + JarDesignAirbusProvider.GetExportText(route); } } } diff --git a/src/QSP/RouteFinding/FileExport/Providers/JarDesignAirbusProvider.cs b/src/QSP/RouteFinding/FileExport/Providers/JarDesignAirbusProvider.cs new file mode 100644 index 00000000..16091d3a --- /dev/null +++ b/src/QSP/RouteFinding/FileExport/Providers/JarDesignAirbusProvider.cs @@ -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 JarDesignAirbusProvider + { + /// + /// Get string of the flight plan to export. + /// + /// + 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 $"{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 $"{from} {text} {to}"; + } + } +} diff --git a/src/Tests/UnitTest/RouteFinding/FileExport/Providers/FlightFactorA320ProviderTest.cs b/src/Tests/UnitTest/RouteFinding/FileExport/Providers/FlightFactorA320ProviderTest.cs index a4b3ab77..e3bae4e4 100644 --- a/src/Tests/UnitTest/RouteFinding/FileExport/Providers/FlightFactorA320ProviderTest.cs +++ b/src/Tests/UnitTest/RouteFinding/FileExport/Providers/FlightFactorA320ProviderTest.cs @@ -26,7 +26,7 @@ public void GetExportTextTest() } [Test] - public void GetExportTextNoWaypontDoesNotThrow() + public void GetExportTextNoWaypont() { var route = Common.GetRoute( new Waypoint("RJBB06L", 0.0, 0.0), "DCT", -1.0, diff --git a/src/Tests/UnitTest/RouteFinding/FileExport/Providers/JarDesignAirbusProviderTest.cs b/src/Tests/UnitTest/RouteFinding/FileExport/Providers/JarDesignAirbusProviderTest.cs new file mode 100644 index 00000000..a5a31ab2 --- /dev/null +++ b/src/Tests/UnitTest/RouteFinding/FileExport/Providers/JarDesignAirbusProviderTest.cs @@ -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 JarDesignAirbusProviderTest + { + [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 = JarDesignAirbusProvider.GetExportText(route); + + var expected = "RJBB DCT WPT0 B WPT1 DCT WPT2 DCT RJAA"; + + Assert.IsTrue(expected.EqualsIgnoreNewlineStyle(text)); + } + + [Test] + public void GetExportTextNoWaypont() + { + var route = Common.GetRoute( + new Waypoint("RJBB06L", 0.0, 0.0), "DCT", -1.0, + new Waypoint("RJAA18", 0.0, 3.0)); + + var text = JarDesignAirbusProvider.GetExportText(route); + + var expected = "RJBB RJAA"; + + Assert.IsTrue(expected.EqualsIgnoreNewlineStyle(text)); + } + } +} diff --git a/src/Tests/UnitTest/UnitTest.csproj b/src/Tests/UnitTest/UnitTest.csproj index deb778b4..25b0d736 100644 --- a/src/Tests/UnitTest/UnitTest.csproj +++ b/src/Tests/UnitTest/UnitTest.csproj @@ -163,6 +163,7 @@ +