Skip to content

Commit

Permalink
Add flightfactor A320 format.
Browse files Browse the repository at this point in the history
  • Loading branch information
JetStream96 committed Apr 14, 2018
1 parent 5587024 commit dc45ee5
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/QSP/QSP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
<Compile Include="FuelCalculation\Calculations\ICrzAltProvider.cs" />
<Compile Include="FuelCalculation\Calculations\IPlanNode.cs" />
<Compile Include="FuelCalculation\Calculations\NextPlanNodeParameter.cs" />
<Compile Include="RouteFinding\FileExport\Providers\FlightFactorA320Provider.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
Expand Up @@ -9,8 +9,6 @@ namespace QSP.RouteFinding.FileExport.Providers
/// </summary>
public static class AerosoftAirbusProvider
{
// TODO: Consecutive airways should be combined.

/// <summary>
/// Get string of the flight plan to export.
/// </summary>
Expand Down
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}";
}
}
}
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));
}
}
}
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\FlightFactorA320ProviderTest.cs" />
<Compile Include="RouteFinding\FileExport\Providers\PmdgWindUplinkProviderTest.cs" />
<Compile Include="RouteFinding\FileExport\Providers\Fs9ProviderTest.cs" />
<Compile Include="RouteFinding\FileExport\Providers\FsxProviderTest.cs" />
Expand Down

0 comments on commit dc45ee5

Please sign in to comment.