Skip to content

Commit

Permalink
Add Jar design Airbus format.
Browse files Browse the repository at this point in the history
  • Loading branch information
JetStream96 committed Apr 14, 2018
1 parent dc45ee5 commit c34ebcf
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/QSP/QSP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
<Compile Include="FuelCalculation\Calculations\IPlanNode.cs" />
<Compile Include="FuelCalculation\Calculations\NextPlanNodeParameter.cs" />
<Compile Include="RouteFinding\FileExport\Providers\FlightFactorA320Provider.cs" />
<Compile Include="RouteFinding\FileExport\Providers\JarDesignAirbusProvider.cs" />
<Compile Include="WindAloft\WxTable.cs" />
<Compile Include="WindAloft\TableItem.cs" />
<Content Include="config.xml">
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -14,19 +10,9 @@ public static class FlightFactorA320Provider
/// <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}";
return $"RTE {from}{to}01 " + JarDesignAirbusProvider.GetExportText(route);
}
}
}
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}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
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));
}
}
}
1 change: 1 addition & 0 deletions src/Tests/UnitTest/UnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
<Compile Include="RouteFinding\Data\Interfaces\ICoordinateExtensionTest.cs" />
<Compile Include="RouteFinding\Data\LatLonSearcherTest.cs" />
<Compile Include="RouteFinding\FileExport\ExportCommandTest.cs" />
<Compile Include="RouteFinding\FileExport\Providers\JarDesignAirbusProviderTest.cs" />
<Compile Include="RouteFinding\FileExport\Providers\FlightFactorA320ProviderTest.cs" />
<Compile Include="RouteFinding\FileExport\Providers\PmdgWindUplinkProviderTest.cs" />
<Compile Include="RouteFinding\FileExport\Providers\Fs9ProviderTest.cs" />
Expand Down

0 comments on commit c34ebcf

Please sign in to comment.