diff --git a/bindings/python/test/trajectory/test_segment.py b/bindings/python/test/trajectory/test_segment.py index 80a18cb32..3125d7132 100644 --- a/bindings/python/test/trajectory/test_segment.py +++ b/bindings/python/test/trajectory/test_segment.py @@ -175,3 +175,4 @@ def test_solve( == 0.0 ) assert len(solution.states) > 0 + assert solution.condition_is_satisfied diff --git a/bindings/python/test/trajectory/test_sequence.py b/bindings/python/test/trajectory/test_sequence.py index 45876ad8a..e5a237e31 100644 --- a/bindings/python/test/trajectory/test_sequence.py +++ b/bindings/python/test/trajectory/test_sequence.py @@ -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 diff --git a/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Segment.test.cpp b/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Segment.test.cpp index 9bb758ecd..a7cff85e0 100644 --- a/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Segment.test.cpp +++ b/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Segment.test.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -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; @@ -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 @@ -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 eventCondition = std::make_shared(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) diff --git a/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Sequence.test.cpp b/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Sequence.test.cpp index 9d807b337..d62cc9296 100644 --- a/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Sequence.test.cpp +++ b/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Sequence.test.cpp @@ -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) @@ -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_); }