Skip to content

Commit

Permalink
feat: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vishwa2710 committed Jan 4, 2025
1 parent 402f0d1 commit 57251f3
Show file tree
Hide file tree
Showing 6 changed files with 370 additions and 298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Access_Generator(pybind11::module& a
accessTargetClass
.def(
"get_type",
&AccessTarget::getType,
&AccessTarget::accessType,
R"doc(
Get the type of the access target.
Expand All @@ -53,7 +53,7 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Access_Generator(pybind11::module& a
)
.def(
"get_visibility_criterion",
&AccessTarget::getVisibilityCriterion,
&AccessTarget::accessVisibilityCriterion,
R"doc(
Get the visibility criterion associated with the access target.
Expand All @@ -63,7 +63,7 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Access_Generator(pybind11::module& a
)
.def(
"get_trajectory",
&AccessTarget::getTrajectory,
&AccessTarget::accessTrajectory,
R"doc(
Get the trajectory associated with the access target.
Expand Down Expand Up @@ -258,14 +258,14 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Access_Generator(pybind11::module& a
Get the condition function.
Args:
from_trajectory (State): The state at the start of the interval.
to_trajectory (State): The state at the end of the interval.
access_target (AccessTarget): The access target from which the condition function is being evaluated against.
to_trajectory (Trajectory): The trajectory to which the condition function is being evaluated against.
Returns:
function: The condition function.
)doc",
arg("from_trajectory"),
arg("access_target"),
arg("to_trajectory")
)
.def(
Expand Down
95 changes: 35 additions & 60 deletions bindings/python/test/access/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ def earth(environment: Environment) -> Celestial:
def generator(environment: Environment) -> Generator:
return Generator(
environment=environment,
aer_filter=lambda aer: True,
access_filter=lambda access: True,
state_filter=lambda state_1, state_2: True,
state_filter=None,
)


Expand Down Expand Up @@ -109,6 +108,14 @@ def access_target(
return AccessTarget.from_lla(visibility_criterion, lla, earth)


@pytest.fixture
def trajectory_target(
visibility_criterion: VisibilityCriterion,
from_trajectory: Trajectory,
) -> AccessTarget:
return AccessTarget.from_trajectory(visibility_criterion, from_trajectory)


class TestAccessTarget:
def test_constructor_success(self, access_target: AccessTarget):
assert isinstance(access_target, AccessTarget)
Expand Down Expand Up @@ -187,15 +194,6 @@ def test_constructor_success_environment(self, environment: Environment):
assert generator is not None
assert isinstance(generator, Generator)

def test_constructor_success_environment_aer_filter(self, environment: Environment):
generator = Generator(
environment=environment,
aer_filter=lambda aer: True,
)

assert generator is not None
assert isinstance(generator, Generator)

def test_constructor_success_environment_access_filter(
self,
environment: Environment,
Expand Down Expand Up @@ -238,18 +236,17 @@ def test_constructor_success_environment_step_tolerance(
def test_getters_success(self, generator: Generator):
assert generator.get_step() == Duration.minutes(1.0)
assert generator.get_tolerance() == Duration.microseconds(1.0)
assert generator.get_aer_filter() is not None
assert generator.get_access_filter() is not None
assert generator.get_state_filter() is not None
assert generator.get_state_filter() is None

def test_get_condition_function_success(
self,
generator: Generator,
from_trajectory: Trajectory,
trajectory_target: AccessTarget,
to_trajectory: Trajectory,
):
condition_function = generator.get_condition_function(
from_trajectory=from_trajectory,
access_target=trajectory_target,
to_trajectory=to_trajectory,
)

Expand All @@ -264,15 +261,15 @@ def test_get_condition_function_success(
def test_compute_accesses_success(
self,
generator: Generator,
from_trajectory: Trajectory,
trajectory_target: AccessTarget,
to_trajectory: Trajectory,
):
accesses = generator.compute_accesses(
interval=Interval.closed(
Instant.date_time(DateTime(2018, 1, 1, 0, 0, 0), Scale.UTC),
Instant.date_time(DateTime(2018, 1, 1, 2, 0, 0), Scale.UTC),
),
from_trajectory=from_trajectory,
access_target=trajectory_target,
to_trajectory=to_trajectory,
)

Expand All @@ -281,15 +278,33 @@ def test_compute_accesses_success(
assert accesses[0] is not None
assert isinstance(accesses[0], Access)

def test_compute_accesses_multiple_targets_success(
self,
generator: Generator,
trajectory_target: AccessTarget,
to_trajectory: Trajectory,
):
accesses = generator.compute_accesses(
interval=Interval.closed(
Instant.date_time(DateTime(2018, 1, 1, 0, 0, 0), Scale.UTC),
Instant.date_time(DateTime(2018, 1, 1, 2, 0, 0), Scale.UTC),
),
access_targets=[trajectory_target],
to_trajectory=to_trajectory,
)

assert accesses is not None
assert isinstance(accesses, list)
assert accesses[0] is not None
assert isinstance(accesses[0], list)
assert isinstance(accesses[0][0], Access)

def test_set_step_success(self, generator: Generator):
generator.set_step(Duration.seconds(1.0))

def test_set_tolerance_success(self, generator: Generator):
generator.set_tolerance(Duration.seconds(1.0))

def test_set_aer_filter_success(self, generator: Generator):
generator.set_aer_filter(aer_filter=lambda aer: True)

def test_set_access_filter_success(self, generator: Generator):
generator.set_access_filter(access_filter=lambda access: True)

Expand All @@ -302,43 +317,3 @@ def test_undefined_success(self):
assert generator is not None
assert isinstance(generator, Generator)
assert generator.is_defined() is False

def test_aer_ranges_success(self, environment: Environment):
# Construct arbitrary AER ranges
azimuth_interval = RealInterval.closed(0.0, 360.0)
elevation_interval = RealInterval.closed(0.0, 90.0)
range_interval = RealInterval.closed(0.0, 7000e3)

generator = Generator.aer_ranges(
azimuth_range=azimuth_interval,
elevation_range=elevation_interval,
range_range=range_interval,
environment=environment,
)

assert generator is not None
assert isinstance(generator, Generator)
assert generator.is_defined()

def test_aer_mask_success(self, environment: Environment):
# Construct arbitrary anAzimuthElevationMask using python dict
an_azimuth_elevation_mask = {
0.0: 30.0,
90.0: 60.0,
180.0: 60.0,
270.0: 30.0,
359.0: 30.0,
}

# Construct arbitrary aRangerange
a_range_range = RealInterval(0.0, 10e4, RealInterval.Type.Closed)

generator = Generator.aer_mask(
azimuth_elevation_mask=an_azimuth_elevation_mask,
range_range=a_range_range,
environment=environment,
)

assert generator is not None
assert isinstance(generator, Generator)
assert generator.is_defined()
18 changes: 9 additions & 9 deletions include/OpenSpaceToolkit/Astrodynamics/Access/Generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,35 +72,35 @@ class AccessTarget
Trajectory
};

/// @brief Get the type
/// @brief Access the type
///
/// @code{.cpp}
/// AccessTarget accessTarget = { ... } ;
/// AccessTarget::Type type = accessTarget.getType();
/// AccessTarget::Type type = accessTarget.accessType();
/// @endcode
///
/// @return The type
Type getType() const;
const Type& accessType() const;

/// @brief Get the visibility criteria
/// @brief Access the visibility criteria
///
/// @code{.cpp}
/// AccessTarget accessTarget = { ... } ;
/// VisibilityCriterion visibilityCriterion = accessTarget.getVisibilityCriterion();
/// VisibilityCriterion visibilityCriterion = accessTarget.accessVisibilityCriterion();
/// @endcode
///
/// @return The visibility criteria
VisibilityCriterion getVisibilityCriterion() const;
const VisibilityCriterion& accessVisibilityCriterion() const;

/// @brief Get the trajectory
/// @brief Access the trajectory
///
/// @code{.cpp}
/// AccessTarget accessTarget = { ... } ;
/// Trajectory trajectory = accessTarget.getTrajectory();
/// const Trajectory& trajectory = accessTarget.accessTrajectory();
/// @endcode
///
/// @return The trajectory
Trajectory getTrajectory() const;
const Trajectory& accessTrajectory() const;

/// @brief Get the position
///
Expand Down
Loading

0 comments on commit 57251f3

Please sign in to comment.