<commit_before>﻿#include "ksp_plugin/plugin.hpp"

#include <algorithm>
#include <cmath>
#include <limits>
#include <map>
#include <memory>
#include <utility>
#include <vector>

#include "geometry/permutation.hpp"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "physics/mock_n_body_system.hpp"
#include "quantities/si.hpp"
#include "testing_utilities/almost_equals.hpp"
#include "testing_utilities/componentwise.hpp"
#include "testing_utilities/numerics.hpp"
#include "testing_utilities/solar_system.hpp"

namespace principia {

using geometry::Bivector;
using geometry::Permutation;
using geometry::Trivector;
using physics::MockNBodySystem;
using quantities::Abs;
using quantities::ArcTan;
using quantities::Cos;
using quantities::Sin;
using quantities::Sqrt;
using si::Day;
using si::Hour;
using si::Minute;
using si::Radian;
using si::AstronomicalUnit;
using testing_utilities::AbsoluteError;
using testing_utilities::AlmostEquals;
using testing_utilities::Componentwise;
using testing_utilities::ICRFJ2000Ecliptic;
using testing_utilities::RelativeError;
using testing_utilities::SolarSystem;
using ::testing::AllOf;
using ::testing::Contains;
using ::testing::Eq;
using ::testing::Ge;
using ::testing::Gt;
using ::testing::InSequence;
using ::testing::Le;
using ::testing::Lt;
using ::testing::Ref;
using ::testing::SizeIs;
using ::testing::StrictMock;
using ::testing::_;

namespace ksp_plugin {

namespace {

int const kNotABody = 1729;

// Appends a |DegreesOfFreedom| equal to the last one at the given |time| to
// each |Trajectory| in the |k|th parameter of the expected call.
// This parameter must be an |NBodySystem<Barycentric>::Trajectories|, |time|
// must be an |Instant|.
ACTION_TEMPLATE(AppendTimeToTrajectories,
                HAS_1_TEMPLATE_PARAMS(int, k),
                AND_1_VALUE_PARAMS(time)) {
  for (auto trajectory : static_cast<NBodySystem<Barycentric>::Trajectories>(
                             std::tr1::get<k>(args))) {
    trajectory->Append(time, trajectory->last().degrees_of_freedom());
  }
}

MATCHER_P(HasNonvanishingIntrinsicAccelerationAt, t, "") {
  if (arg->has_intrinsic_acceleration()) {
    if (arg->evaluate_intrinsic_acceleration(t) ==
        Vector<Acceleration, Barycentric>()) {
       *result_listener << "has vanishing intrinsic acceleration at";
       return false;
    } else {
       *result_listener << "has nonvanishing intrinsic acceleration at";
       return true;
    }
  }
  *result_listener << "has no intrinsic acceleration";
  return false;
}

}  // namespace

class TestablePlugin : public Plugin {
  std::map<Index, ContinuousTrajectory<Barycentric>> trajectories_;
 public:
  TestablePlugin(Instant const& initial_time,
                 Index const sun_index,
                 GravitationalParameter const& sun_gravitational_parameter,
                 Angle const& planetarium_rotation)
      : Plugin(initial_time,
               sun_index,
               sun_gravitational_parameter,
               planetarium_rotation) {}

  void EndInitialization() override {
    initializing_.Flop();
    std::vector<not_null<std::unique_ptr<MassiveBody const>>> bodies;
    std::vector<DegreesOfFreedom<Barycentric>> initial_state;
    auto bodies_it = bodies_->begin();
    for (auto const& index_state : *initial_state_) {
      EXPECT_EQ(index_state.first, bodies_it->first);
      auto const inserted = 
          trajectories_.emplace(std::piecewise_construct,
                                std::forward_as_tuple(index_state.first),
                                std::forward_as_tuple(45 * Minute,
                                                      1 * Milli(Metre)));
      EXPECT_TRUE(inserted.second);
      inserted.first->second.Append(current_time_, index_state.second);
      ++bodies_it;
    }
    bodies_.reset();
    initial_state_.reset();
    n_body_system_ = std::make_unique<MockNBodySystem<Barycentric>>();<commit_msg>turned a crashing test into a failing test. Progress!<commit_after>﻿#include "ksp_plugin/plugin.hpp"

#include <algorithm>
#include <cmath>
#include <limits>
#include <map>
#include <memory>
#include <utility>
#include <vector>

#include "geometry/permutation.hpp"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "physics/mock_n_body_system.hpp"
#include "quantities/si.hpp"
#include "testing_utilities/almost_equals.hpp"
#include "testing_utilities/componentwise.hpp"
#include "testing_utilities/numerics.hpp"
#include "testing_utilities/solar_system.hpp"

namespace principia {

using geometry::Bivector;
using geometry::Permutation;
using geometry::Trivector;
using physics::MockNBodySystem;
using quantities::Abs;
using quantities::ArcTan;
using quantities::Cos;
using quantities::Sin;
using quantities::Sqrt;
using si::Day;
using si::Hour;
using si::Minute;
using si::Radian;
using si::AstronomicalUnit;
using testing_utilities::AbsoluteError;
using testing_utilities::AlmostEquals;
using testing_utilities::Componentwise;
using testing_utilities::ICRFJ2000Ecliptic;
using testing_utilities::RelativeError;
using testing_utilities::SolarSystem;
using ::testing::AllOf;
using ::testing::Contains;
using ::testing::Eq;
using ::testing::Ge;
using ::testing::Gt;
using ::testing::InSequence;
using ::testing::Le;
using ::testing::Lt;
using ::testing::Ref;
using ::testing::SizeIs;
using ::testing::StrictMock;
using ::testing::_;

namespace ksp_plugin {

namespace {

int const kNotABody = 1729;

// Appends a |DegreesOfFreedom| equal to the last one at the given |time| to
// each |Trajectory| in the |k|th parameter of the expected call.
// This parameter must be an |NBodySystem<Barycentric>::Trajectories|, |time|
// must be an |Instant|.
ACTION_TEMPLATE(AppendTimeToTrajectories,
                HAS_1_TEMPLATE_PARAMS(int, k),
                AND_1_VALUE_PARAMS(time)) {
  for (auto trajectory : static_cast<NBodySystem<Barycentric>::Trajectories>(
                             std::tr1::get<k>(args))) {
    trajectory->Append(time, trajectory->last().degrees_of_freedom());
  }
}

MATCHER_P(HasNonvanishingIntrinsicAccelerationAt, t, "") {
  if (arg->has_intrinsic_acceleration()) {
    if (arg->evaluate_intrinsic_acceleration(t) ==
        Vector<Acceleration, Barycentric>()) {
       *result_listener << "has vanishing intrinsic acceleration at";
       return false;
    } else {
       *result_listener << "has nonvanishing intrinsic acceleration at";
       return true;
    }
  }
  *result_listener << "has no intrinsic acceleration";
  return false;
}

}  // namespace

class TestablePlugin : public Plugin {
  std::map<Index, ContinuousTrajectory<Barycentric>> trajectories_;
 public:
  TestablePlugin(Instant const& initial_time,
                 Index const sun_index,
                 GravitationalParameter const& sun_gravitational_parameter,
                 Angle const& planetarium_rotation)
      : Plugin(initial_time,
               sun_index,
               sun_gravitational_parameter,
               planetarium_rotation) {}

  void EndInitialization() override {
    initializing_.Flop();
    std::vector<not_null<std::unique_ptr<MassiveBody const>>> bodies;
    std::vector<DegreesOfFreedom<Barycentric>> initial_state;
    auto bodies_it = bodies_->begin();
    for (auto const& index_state : *initial_state_) {
      EXPECT_EQ(index_state.first, bodies_it->first);
      auto const inserted = 
          trajectories_.emplace(std::piecewise_construct,
                                std::forward_as_tuple(index_state.first),
                                std::forward_as_tuple(45 * Minute,
                                                      1 * Milli(Metre)));
      EXPECT_TRUE(inserted.second);
      for (int i = 0; i < 9; ++i) {
        inserted.first->second.Append(
            current_time_ + i * 45 * Minute,
            {index_state.second.position() +
                 i * 45 * Minute * index_state.second.velocity(),
             index_state.second.velocity()});
      }
      ++bodies_it;
    }
    bodies_.reset();
    initial_state_.reset();
    n_body_system_ = std::make_unique<MockNBodySystem<Barycentric>>();
{'fraction_non_alphanumeric': 0.11761076144637789, 'fraction_numerical': 0.004195976798716525, 'mean_word_length': 3.8701923076923075, 'pattern_counts': {'":': 0, '<': 58, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6622673', 'n_tokens_mistral': 2535, 'n_tokens_neox': 2436, 'n_words': 513}