-
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
dc45ee5
commit c34ebcf
Showing
6 changed files
with
79 additions
and
17 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/JarDesignAirbusProvider.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 JarDesignAirbusProvider | ||
{ | ||
/// <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 $"{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}"; | ||
} | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
src/Tests/UnitTest/RouteFinding/FileExport/Providers/JarDesignAirbusProviderTest.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 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)); | ||
} | ||
} | ||
} |
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