Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ cmake-build-debug-linux/
build/
/.idea/
build_release/
/.vs
/IO.Astrodynamics.Net/IO.Astrodynamics/pykep
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<FileVersion>0.0.1</FileVersion>
<PackAsTool>true</PackAsTool>
<ToolCommandName>astro</ToolCommandName>
<Version>0.6.4.0</Version>
<Version>0.6.5.0</Version>
<Title>Astrodynamics command line interface</Title>
<Authors>Sylvain Guillet</Authors>
<Description>This CLI allows end user to exploit IO.Astrodynamics framework </Description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PackageReference Include="BenchmarkDotNet" Version="0.15.2" />
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="coverlet.collector" Version="6.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using IO.Astrodynamics.Maneuver.Lambert;
using IO.Astrodynamics.Math;
using Xunit;

namespace IO.Astrodynamics.Tests.Maneuvers.Lambert
{
public class LambertResultTests
{
private LambertSolution CreateLambertSolution(uint revolutions)
{
var v1 = new Vector3(1.0, 2.0, 3.0);
var v2 = new Vector3(4.0, 5.0, 6.0);
double x = 0.5;
uint iterations = 10;
LambertBranch? branch = revolutions == 0 ? null : LambertBranch.Left;
return new LambertSolution(revolutions, v1, v2, x, iterations, v1, v2, branch);
}

[Fact]
public void Constructor_InitializesProperties()
{
ushort maxRevolutions = 2;
var result = new LambertResult(maxRevolutions);

Assert.Equal(maxRevolutions, result.MaxRevolutions);
Assert.NotNull(result.Solutions);
Assert.Empty(result.Solutions);
}

[Fact]
public void AddSolution_AddsSolutionToCollection()
{
var result = new LambertResult(1);
var solution = CreateLambertSolution(0);

result.AddSolution(solution);

Assert.Single(result.Solutions);
Assert.Contains(solution, result.Solutions);
}

[Fact]
public void GetZeroRevolutionSolution_ReturnsCorrectSolution()
{
var result = new LambertResult(2);
var sol0 = CreateLambertSolution(0);
var sol1 = CreateLambertSolution(1);

result.AddSolution(sol1);
result.AddSolution(sol0);

var found = result.GetZeroRevolutionSolution();
Assert.Equal(sol0, found);
}

[Fact]
public void GetZeroRevolutionSolution_ReturnsNullIfNotFound()
{
var result = new LambertResult(1);
var sol1 = CreateLambertSolution(1);
result.AddSolution(sol1);

var found = result.GetZeroRevolutionSolution();
Assert.Null(found);
}

[Fact]
public void GetMultiRevolutionSolutions_ReturnsCorrectSolutions()
{
var result = new LambertResult(3);
var sol0 = CreateLambertSolution(0);
var sol1a = CreateLambertSolution(1);
var sol1b = CreateLambertSolution(1);
var sol2 = CreateLambertSolution(2);

result.AddSolution(sol0);
result.AddSolution(sol1a);
result.AddSolution(sol1b);
result.AddSolution(sol2);

var found = result.GetMultiRevolutionSolutions(1).ToList();
Assert.Equal(2, found.Count);
Assert.All(found, s => Assert.Equal((uint)1, s.Revolutions));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using Xunit;
using IO.Astrodynamics.Maneuver.Lambert;
using IO.Astrodynamics.Math;

namespace IO.Astrodynamics.Tests.Maneuvers.Lambert;

public class LambertSolutionTests
{
[Fact]
public void Constructor_WithAllParameters_SetsPropertiesCorrectly()
{
// Arrange
uint revolutions = 2;
var v1 = new Vector3(1.0, 2.0, 3.0);
var v2 = new Vector3(4.0, 5.0, 6.0);
double x = 42.0;
uint iterations = 7;
LambertBranch branch = LambertBranch.Right;

// Act
var solution = new LambertSolution(revolutions, v1, v2, x, iterations, v1, v2, branch);

// Assert
Assert.Equal(revolutions, solution.Revolutions);
Assert.Equal(branch, solution.Branch);
Assert.Equal(v1, solution.V1);
Assert.Equal(v1, solution.DeltaV1);
Assert.Equal(v2, solution.V2);
Assert.Equal(v2, solution.DeltaV2);
Assert.Equal(x, solution.X);
Assert.Equal(iterations, solution.Iterations);
}

[Fact]
public void Constructor_DirectTransfer_SetsRevolutionsZeroAndBranchNull()
{
// Arrange
var v1 = new Vector3(1.0, 0.0, 0.0);
var v2 = new Vector3(0.0, 1.0, 0.0);
double x = 3.14;
uint iterations = 2;

// Act
var solution = new LambertSolution(v1, v2, x, iterations, v1, v2);

// Assert
Assert.Equal(0u, solution.Revolutions);
Assert.Null(solution.Branch);
Assert.Equal(v1, solution.V1);
Assert.Equal(v1, solution.DeltaV1);
Assert.Equal(v2, solution.V2);
Assert.Equal(v2, solution.DeltaV2);
Assert.Equal(x, solution.X);
Assert.Equal(iterations, solution.Iterations);
}

[Fact]
public void LambertBranch_Enum_HasLeftAndRightValues()
{
Assert.Equal(0, (int)LambertBranch.Left);
Assert.Equal(1, (int)LambertBranch.Right);
}

[Fact]
public void LambertSolution_Constructor_SetsDeltaVProperties()
{
// Arrange
var v1 = new Vector3(1.0, 2.0, 3.0);
var v2 = new Vector3(4.0, 5.0, 6.0);
double x = 42.0;
uint iterations = 7;

// Act
var solution = new LambertSolution(0, v1, v2, x, iterations, v1, v2);

// Assert
Assert.Equal(v1, solution.DeltaV1);
Assert.Equal(v2, solution.DeltaV2);
Assert.Equal(v1.Magnitude() + v2.Magnitude(), solution.DeltaV);
}
}
Loading