Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f8fe5f4a5f2c
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 167fa6db4c1b
Choose a head ref
  • 4 commits
  • 1 file changed
  • 1 contributor

Commits on Oct 12, 2021

  1. Copy the full SHA
    1a5c81b View commit details
  2. Copy the full SHA
    2368b23 View commit details
  3. Remove testing code.

    pleroy committed Oct 12, 2021
    Copy the full SHA
    6c06874 View commit details
  4. Merge pull request #3151 from pleroy/MoarTests

    DiscreteTrajectorySegment, part 5: some more testing
    pleroy authored Oct 12, 2021
    Copy the full SHA
    167fa6d View commit details
Showing with 57 additions and 0 deletions.
  1. +57 −0 physics/discrete_trajectory_segment_test.cpp
57 changes: 57 additions & 0 deletions physics/discrete_trajectory_segment_test.cpp
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
#include "quantities/named_quantities.hpp"
#include "quantities/quantities.hpp"
#include "quantities/si.hpp"
#include "testing_utilities/almost_equals.hpp"
#include "testing_utilities/approximate_quantity.hpp"
#include "testing_utilities/discrete_trajectory_factories.hpp"
#include "testing_utilities/is_near.hpp"
@@ -32,6 +33,7 @@ using quantities::si::Milli;
using quantities::si::Nano;
using quantities::si::Radian;
using quantities::si::Second;
using testing_utilities::AlmostEquals;
using testing_utilities::AppendTrajectorySegment;
using testing_utilities::IsNear;
using testing_utilities::NewCircularTrajectorySegment;
@@ -61,6 +63,11 @@ class DiscreteTrajectorySegmentTest : public ::testing::Test {
segment_->ForgetAfter(t);
}

void ForgetAfter(Instant const& t,
DiscreteTrajectorySegment<World>& segment) {
segment.ForgetAfter(t);
}

void ForgetBefore(Instant const& t) {
segment_->ForgetBefore(t);
}
@@ -233,5 +240,55 @@ TEST_F(DiscreteTrajectorySegmentTest, Downsampling) {
IsNear(14_⑴ * Milli(Metre / Second)));
}

TEST_F(DiscreteTrajectorySegmentTest, DownsamplingForgetAfter) {
auto const circle = NewEmptyTrajectorySegment<World>();
auto const forgotten_circle = NewEmptyTrajectorySegment<World>();
SetDownsampling({.max_dense_intervals = 50, .tolerance = 1 * Milli(Metre)},
*circle->front());
SetDownsampling({.max_dense_intervals = 50, .tolerance = 1 * Milli(Metre)},
*forgotten_circle->front());
AngularFrequency const ω = 3 * Radian / Second;
Length const r = 2 * Metre;
Time const Δt = 1.0 / 128.0 * Second; // Yields exact times.
Instant const t1 = t0_;
Instant const t2 = t0_ + 5 * Second;
Instant const t3 = t0_ + 10 * Second;

// Construct two identical trajectories with downsampling.
AppendTrajectorySegment(
*NewCircularTrajectorySegment<World>(ω, r, Δt, t1, t3)->front(),
/*to=*/*circle->front());
AppendTrajectorySegment(
*NewCircularTrajectorySegment<World>(ω, r, Δt, t1, t3)->front(),
/*to=*/*forgotten_circle->front());

// Forget one of the trajectories in the middle, and append new points.
Instant const restart_time =
forgotten_circle->front()->lower_bound(t2)->first;
ForgetAfter(t2, *forgotten_circle->front());
AppendTrajectorySegment(
*NewCircularTrajectorySegment<World>(ω, r, Δt, restart_time, t3)->front(),
/*to=*/*forgotten_circle->front());

EXPECT_THAT(circle->front()->size(), Eq(92));
EXPECT_THAT(forgotten_circle->front()->size(), Eq(circle->front()->size()));
std::vector<Length> position_errors;
std::vector<Speed> velocity_errors;

// Check that the two trajectories are identical.
for (auto const [t, degrees_of_freedom] : *forgotten_circle->front()) {
position_errors.push_back(
(circle->front()->find(t)->second.position() -
degrees_of_freedom.position()).Norm());
velocity_errors.push_back(
(circle->front()->find(t)->second.velocity() -
degrees_of_freedom.velocity()).Norm());
}
EXPECT_THAT(*std::max_element(position_errors.begin(), position_errors.end()),
AlmostEquals(0 * Metre, 0));
EXPECT_THAT(*std::max_element(velocity_errors.begin(), velocity_errors.end()),
AlmostEquals(0 * Metre / Second, 0));
}

} // namespace physics
} // namespace principia