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: c67f71b306c9
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9ff0a6426574
Choose a head ref
  • 4 commits
  • 6 files changed
  • 1 contributor

Commits on Sep 26, 2021

  1. Convert a test for parts.

    pleroy committed Sep 26, 2021
    Copy the full SHA
    4628683 View commit details
  2. Fix all the tests.

    pleroy committed Sep 26, 2021
    Copy the full SHA
    bf87de5 View commit details
  3. Cleanup.

    pleroy committed Sep 26, 2021
    Copy the full SHA
    8752074 View commit details
  4. Merge pull request #3128 from pleroy/VesselTest

    Change the tests for Vessel to use trajectory factories
    pleroy authored Sep 26, 2021
    Copy the full SHA
    9ff0a64 View commit details
378 changes: 160 additions & 218 deletions ksp_plugin_test/vessel_test.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions physics/degrees_of_freedom_body.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

#pragma once

#include "physics/degrees_of_freedom.hpp"

#include <string>
#include <vector>

#include "physics/degrees_of_freedom.hpp"

namespace principia {
namespace physics {
namespace internal_degrees_of_freedom {
11 changes: 6 additions & 5 deletions physics/mock_ephemeris.hpp
Original file line number Diff line number Diff line change
@@ -126,15 +126,16 @@ ACTION_P2(AppendToDiscreteTrajectory, time, degrees_of_freedom) {
arg0->Append(time, degrees_of_freedom);
}

// TODO(phl): Remove "2" once the other actions are gone.
ACTION_P2(AppendToDiscreteTrajectory2, trajectory, degrees_of_freedom) {
(*trajectory)->Append(arg0, degrees_of_freedom);
}

ACTION_P3(AppendToDiscreteTrajectory, trajectory, time, degrees_of_freedom) {
// The extra level of indirection is useful for tests that get a pointer to a
// trajectory and squirrel it away using |SaveArg<N>|.
(*trajectory)->Append(time, degrees_of_freedom);
}

ACTION_P(AppendPointsToDiscreteTrajectory, trajectory) {
for (auto const& [time, degrees_of_freedom] : *trajectory) {
arg0->Append(time, degrees_of_freedom);
}
}

} // namespace principia
14 changes: 12 additions & 2 deletions testing_utilities/trajectory_factories.hpp
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@

#include "base/not_null.hpp"
#include "geometry/named_quantities.hpp"
#include "physics/degrees_of_freedom.hpp"
#include "physics/discrete_trajectory.hpp"
#include "quantities/named_quantities.hpp"
#include "quantities/quantities.hpp"
@@ -15,13 +16,22 @@ namespace internal_trajectory_factories {
using base::not_null;
using geometry::Instant;
using geometry::Velocity;
using physics::DegreesOfFreedom;
using physics::DiscreteTrajectory;
using quantities::AngularFrequency;
using quantities::Length;
using quantities::Time;

// A linear trajectory with constant velocity, going through the origin at
// t = 0. The first point is at time |t1|, the last point at a time < |t2|.
// A linear trajectory with constant velocity, going through
// |degrees_of_freedom.position()| at t = 0. The first point is at time |t1|,
// the last point at a time < |t2|.
template<typename Frame>
not_null<std::unique_ptr<DiscreteTrajectory<Frame>>> NewLinearTrajectory(
DegreesOfFreedom<Frame> const& degrees_of_freedom,
Time const& Δt,
Instant const& t1,
Instant const& t2);
// Same as above, going through the origin at t = 0.
template<typename Frame>
not_null<std::unique_ptr<DiscreteTrajectory<Frame>>> NewLinearTrajectory(
Velocity<Frame> const& v,
21 changes: 16 additions & 5 deletions testing_utilities/trajectory_factories_body.hpp
Original file line number Diff line number Diff line change
@@ -21,17 +21,28 @@ using quantities::si::Radian;

template<typename Frame>
not_null<std::unique_ptr<DiscreteTrajectory<Frame>>> NewLinearTrajectory(
Velocity<Frame> const& v,
DegreesOfFreedom<Frame> const& degrees_of_freedom,
Time const& Δt,
Instant const& t1,
Instant const& t2) {
static Instant const t0;
auto trajectory = make_not_null_unique<DiscreteTrajectory<Frame>>();
for (auto t = t1; t < t2; t += Δt) {
DegreesOfFreedom<Frame> const dof = {Frame::origin + v * (t - t0), v};
trajectory->Append(t, dof);
auto const velocity = degrees_of_freedom.velocity();
auto const position = degrees_of_freedom.position() + velocity * (t - t0);
trajectory->Append(t, DegreesOfFreedom<Frame>(position, velocity));
}
return std::move(trajectory);
return trajectory;
}

template<typename Frame>
not_null<std::unique_ptr<DiscreteTrajectory<Frame>>> NewLinearTrajectory(
Velocity<Frame> const& v,
Time const& Δt,
Instant const& t1,
Instant const& t2) {
return NewLinearTrajectory(
DegreesOfFreedom<Frame>(Frame::origin, v), Δt, t1, t2);
}

template<typename Frame>
@@ -54,7 +65,7 @@ not_null<std::unique_ptr<DiscreteTrajectory<Frame>>> NewCircularTrajectory(
Speed{}}}};
trajectory->Append(t, dof);
}
return std::move(trajectory);
return trajectory;
}

template<typename Frame>
21 changes: 16 additions & 5 deletions testing_utilities/trajectory_factories_test.cpp
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
#include "geometry/named_quantities.hpp"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "physics/degrees_of_freedom.hpp"
#include "quantities/elementary_functions.hpp"
#include "quantities/si.hpp"
#include "testing_utilities/almost_equals.hpp"
@@ -15,13 +16,16 @@
namespace principia {
namespace testing_utilities {

using geometry::Displacement;
using geometry::Frame;
using geometry::Handedness;
using geometry::Inertial;
using geometry::InnerProduct;
using geometry::Instant;
using geometry::Position;
using geometry::Velocity;
using physics::DegreesOfFreedom;
using quantities::Pow;
using quantities::Sqrt;
using quantities::si::Metre;
using quantities::si::Radian;
@@ -37,8 +41,12 @@ class TrajectoryFactoriesTest : public ::testing::Test {

TEST_F(TrajectoryFactoriesTest, NewLinearTrajectory) {
auto const trajectory = NewLinearTrajectory<World>(
/*v=*/Velocity<World>(
{6 * Metre / Second, 5 * Metre / Second, 4 * Metre / Second}),
/*degrees_of_freedom=*/
DegreesOfFreedom<World>(
World::origin +
Displacement<World>({30 * Metre, 40 * Metre, 50 * Metre}),
Velocity<World>(
{6 * Metre / Second, 5 * Metre / Second, 4 * Metre / Second})),
/*Δt=*/0.1 * Second,
/*t1=*/Instant() + 4 * Second,
/*t2=*/Instant() + 42 * Second);
@@ -47,9 +55,12 @@ TEST_F(TrajectoryFactoriesTest, NewLinearTrajectory) {
Position<World> const& position = degrees_of_freedom.position();
Velocity<World> const& velocity = degrees_of_freedom.velocity();

EXPECT_THAT(
(position - World::origin).Norm(),
AlmostEquals((time - Instant()) * Sqrt(77) * Metre / Second, 0, 1));
EXPECT_THAT((position - World::origin).Norm(),
AlmostEquals(Sqrt(5000 + 1160 * (time - Instant()) / Second +
77 * Pow<2>((time - Instant()) / Second)) *
Metre,
0,
1));
EXPECT_THAT(velocity.Norm(), AlmostEquals(Sqrt(77) * Metre / Second, 0, 0));
}
EXPECT_THAT(trajectory->begin()->time,