Skip to content

Commit

Permalink
feat: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vishwa2710 committed Oct 6, 2023
1 parent a8933c9 commit 41d4096
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 14 deletions.
1 change: 1 addition & 0 deletions bindings/python/test/trajectory/test_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,4 @@ def test_solve(
== 0.0
)
assert len(solution.states) > 0
assert solution.condition_is_satisfied
1 change: 1 addition & 0 deletions bindings/python/test/trajectory/test_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,4 @@ def test_solve(self, state: State, sequence: Sequence, segments: list[Segment]):
assert len(solution.segment_solutions) == len(segments)

assert solution.get_states() is not None
assert solution.sequence_is_complete
23 changes: 22 additions & 1 deletion test/OpenSpaceToolkit/Astrodynamics/Trajectory/Segment.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <OpenSpaceToolkit/Astrodynamics/Dynamics/CentralBodyGravity.hpp>
#include <OpenSpaceToolkit/Astrodynamics/Dynamics/PositionDerivative.hpp>
#include <OpenSpaceToolkit/Astrodynamics/Dynamics/Thruster/ConstantThrust.hpp>
#include <OpenSpaceToolkit/Astrodynamics/EventCondition/COECondition.hpp>
#include <OpenSpaceToolkit/Astrodynamics/EventCondition/InstantCondition.hpp>
#include <OpenSpaceToolkit/Astrodynamics/Trajectory/Segment.hpp>
#include <OpenSpaceToolkit/Astrodynamics/Trajectory/State/NumericalSolver.hpp>
Expand All @@ -30,6 +31,7 @@ using ostk::physics::env::obj::celest::Earth;
using ostk::physics::coord::Frame;
using ostk::physics::coord::Position;
using ostk::physics::coord::Velocity;
using EarthGravitationalModel = ostk::physics::environment::gravitational::Earth;

using ostk::astro::trajectory::state::NumericalSolver;
using ostk::astro::Dynamics;
Expand All @@ -41,6 +43,8 @@ using ostk::astro::trajectory::LocalOrbitalFrameFactory;
using ostk::astro::dynamics::CentralBodyGravity;
using ostk::astro::dynamics::PositionDerivative;
using ostk::astro::eventcondition::InstantCondition;
using ostk::astro::eventcondition::COECondition;
using ostk::astro::eventcondition::RealCondition;
using ostk::astro::trajectory::State;

class OpenSpaceToolkit_Astrodynamics_Trajectory_TrajectorySegment : public ::testing::Test
Expand Down Expand Up @@ -170,13 +174,30 @@ TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_TrajectorySegment, StreamOperat
TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_TrajectorySegment, Solve)
{
{
Segment::Solution solution = defaultCoastSegment_.solve(defaultState_);
const Segment::Solution solution = defaultCoastSegment_.solve(defaultState_);

EXPECT_LT(
(solution.states.accessLast().getInstant() - defaultInstantCondition_->getInstant()).inSeconds(), 1e-7
);
EXPECT_TRUE(solution.states.getSize() > 0);
}

{
const Shared<RealCondition> eventCondition = std::make_shared<RealCondition>(COECondition::Eccentricity(
RealCondition::Criterion::AnyCrossing,
Frame::GCRF(),
0.5,
EarthGravitationalModel::EGM2008.gravitationalParameter_
));

const Segment segment =
Segment::Coast("SMA condition", eventCondition, defaultDynamics_, defaultNumericalSolver_);

const Segment::Solution solution = segment.solve(defaultState_, Duration::Minutes(1.0));

EXPECT_TRUE(solution.states.getSize() > 0);
EXPECT_FALSE(solution.conditionIsSatisfied);
}
}

TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_TrajectorySegment, Print)
Expand Down
47 changes: 34 additions & 13 deletions test/OpenSpaceToolkit/Astrodynamics/Trajectory/Sequence.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,28 +235,49 @@ TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Sequence, AddManeuverSegment)

EXPECT_TRUE(defaultSequence_.getSegments().getSize() == segmentsCount + 1);
}

{
}
}

TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Sequence, Solve)
{
Sequence::Solution solution = defaultSequence_.solve(defaultState_);
{
const Sequence::Solution solution = defaultSequence_.solve(defaultState_);

EXPECT_TRUE(
solution.segmentSolutions.getSize() == defaultSequence_.getSegments().getSize() * defaultRepetitionCount_
);
EXPECT_TRUE(
solution.segmentSolutions.getSize() == defaultSequence_.getSegments().getSize() * defaultRepetitionCount_
);

Size statesSize = 0;
for (const Segment::Solution& segmentSolution : solution.segmentSolutions)
{
EXPECT_TRUE(segmentSolution.states.getSize() > 0);
Size statesSize = 0;
for (const Segment::Solution& segmentSolution : solution.segmentSolutions)
{
EXPECT_TRUE(segmentSolution.states.getSize() > 0);

const Real targetAngle = defaultCondition_->getEvaluator()(segmentSolution.states.accessLast());
EXPECT_NEAR(targetAngle, defaultCondition_->getTargetAngle().inRadians(0.0, Real::TwoPi()), 1e-6);
const Real targetAngle = defaultCondition_->getEvaluator()(segmentSolution.states.accessLast());
EXPECT_NEAR(targetAngle, defaultCondition_->getTargetAngle().inRadians(0.0, Real::TwoPi()), 1e-6);

statesSize += segmentSolution.states.getSize();
statesSize += segmentSolution.states.getSize();
}

EXPECT_TRUE(solution.getStates().getSize() == statesSize);
}

EXPECT_TRUE(solution.getStates().getSize() == statesSize);
{
const Sequence sequence = {
defaultSegments_,
defaultRepetitionCount_,
defaultNumericalSolver_,
defaultDynamics_,
Duration::Seconds(1.0),
};

const Sequence::Solution solution = sequence.solve(defaultState_);

EXPECT_FALSE(solution.sequenceIsComplete);
EXPECT_TRUE(solution.segmentSolutions.getSize() == 1);
EXPECT_FALSE(solution.segmentSolutions[0].conditionIsSatisfied);
}
}

TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Sequence, Solve_2)
Expand Down Expand Up @@ -341,7 +362,7 @@ TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Sequence, Solve_2)
coordinatesBrokerSPtr,
};

Sequence::Solution solution = sequence.solve(state);
const Sequence::Solution solution = sequence.solve(state);

EXPECT_TRUE(solution.segmentSolutions.getSize() == 2 * defaultRepetitionCount_);
}
Expand Down

0 comments on commit 41d4096

Please sign in to comment.