Skip to content

Commit

Permalink
Merge pull request #4146 from eggrobin/sourcery
Browse files Browse the repository at this point in the history
Sourcery for functions
  • Loading branch information
eggrobin authored Dec 30, 2024
2 parents cbfb62e + 5b5e2e1 commit 4bde797
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion functions/accurate_table_generator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "mathematica/logger.hpp"
#include "mathematica/mathematica.hpp"
#include "numerics/combinatorics.hpp"
#include "quantities/numbers.hpp"
#include "quantities/numbers.hpp" // 🧙 For π.
#include "testing_utilities/approximate_quantity.hpp"
#include "testing_utilities/is_near.hpp"
#include "testing_utilities/matchers.hpp"
Expand Down
5 changes: 2 additions & 3 deletions functions/core_math_accuracy_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
#include "glog/logging.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "quantities/numbers.hpp"
#include "quantities/numbers.hpp" // 🧙 For π.
#include "testing_utilities/approximate_quantity.hpp"
#include "testing_utilities/is_near.hpp"

namespace principia {
namespace functions {
namespace _multiprecision {

using namespace boost::multiprecision;
using namespace principia::functions::_multiprecision;
using namespace principia::testing_utilities::_approximate_quantity;
using namespace principia::testing_utilities::_is_near;

Expand Down Expand Up @@ -74,6 +74,5 @@ TEST_F(CoreMathAccuracyTest, SinCos) {

#endif

} // namespace _multiprecision
} // namespace functions
} // namespace principia
21 changes: 12 additions & 9 deletions functions/sin_cos_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@
#include "glog/logging.h"
#include "gtest/gtest.h"
#include "numerics/next.hpp"
#include "quantities/numbers.hpp"
#include "quantities/numbers.hpp" // 🧙 For π.
#include "testing_utilities/almost_equals.hpp"

// This test lives in `functions` to avoid pulling `boost` into `numerics`.
// It uses neither the `functions` nor the `numerics` namespace so that the Sin
// and Cos from both (`principia::functions::_multiprecision` and
// `principia::numerics::_sin_cos`) are made visible by the using directives
// below.

namespace principia {
namespace numerics {
namespace _sin_cos {
namespace functions_test {

using namespace boost::multiprecision;
using namespace principia::functions::_multiprecision;
using namespace principia::numerics::_next;
using namespace principia::numerics::_sin_cos;
using namespace principia::testing_utilities::_almost_equals;

class SinCosTest : public ::testing::Test {};
Expand All @@ -44,8 +50,7 @@ TEST_F(SinCosTest, Random) {
double const principia_argument = uniformly_at(random);
auto const boost_argument = cpp_rational(principia_argument);
{
auto const boost_sin =
functions::_multiprecision::Sin(boost_argument);
auto const boost_sin = Sin(boost_argument);
double const principia_sin = Sin(principia_argument);
auto const sin_error =
abs(boost_sin - static_cast<cpp_bin_float_50>(principia_sin));
Expand All @@ -61,8 +66,7 @@ TEST_F(SinCosTest, Random) {
}
}
{
auto const boost_cos =
functions::_multiprecision::Cos(boost_argument);
auto const boost_cos = Cos(boost_argument);
double const principia_cos = Cos(principia_argument);
auto const cos_error =
abs(boost_cos - static_cast<cpp_bin_float_50>(principia_cos));
Expand Down Expand Up @@ -143,6 +147,5 @@ TEST_F(SinCosTest, HardReduction) {
AlmostEquals(-4.687165924254627611122582801963884e-19, 0));
}

} // namespace _sin_cos
} // namespace numerics
} // namespace functions_test
} // namespace principia
3 changes: 1 addition & 2 deletions functions/std_accuracy_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

namespace principia {
namespace functions {
namespace _multiprecision {

using ::testing::AnyOf;
using namespace boost::multiprecision;
using namespace principia::functions::_multiprecision;
using namespace principia::quantities::_si;
using namespace principia::testing_utilities::_almost_equals;
using namespace principia::testing_utilities::_approximate_quantity;
Expand Down Expand Up @@ -85,6 +85,5 @@ TEST_F(StdAccuracyTest, SinCos) {

#endif

} // namespace _multiprecision
} // namespace functions
} // namespace principia
1 change: 1 addition & 0 deletions geometry/serialization_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "geometry/grassmann.hpp"
#include "geometry/point.hpp"
#include "quantities/quantities.hpp"
#include "quantities/serialization.hpp"

namespace principia {
namespace geometry {
Expand Down
6 changes: 4 additions & 2 deletions include_what_you_using_all_the_things.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
--project:astronomy `
--project:base `
--project:benchmarks `
--project:functions `
--project:geometry `
--project:integrators `
--project:journal `
--project:nanobenchmarks `
--project:ksp_plugin `
--project:ksp_plugin_test `
--project:mathematica `
--project:nanobenchmarks `
--project:numerics `
--project:physics `
--project:quantities `
Expand All @@ -24,4 +25,5 @@
--special_own_header:ksp_plugin/interface_*.cpp=ksp_plugin/interface.hpp `
--special_own_header:ksp_plugin_test/interface_*.cpp=ksp_plugin/interface.hpp `
--special_own_header:ksp_plugin_test/benchmark.cpp=ksp_plugin/plugin.hpp `
--special_own_header:ksp_plugin_test/plugin*_test.cpp=ksp_plugin/plugin.hpp
--special_own_header:ksp_plugin_test/plugin*_test.cpp=ksp_plugin/plugin.hpp `
--special_own_header:functions/sin_cos_test.cpp=numerics/sin_cos.hpp
22 changes: 9 additions & 13 deletions sourcerer/include_what_you_using.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ private static void FixIncludes(Parser.File file,
foreach (string ns in using_namespaces) {
var segments = ns.Split("::", StringSplitOptions.RemoveEmptyEntries);
var include_path = Array.Empty<string>();
bool skip = false;
if (ns == file.file_namespace_full_name) {
// Don't add an include for our own header. This matters for tests.
continue;
}
foreach (string segment in segments) {
if (segment == "principia") {
continue;
Expand All @@ -195,24 +198,17 @@ private static void FixIncludes(Parser.File file,
segment == "std") {
// We have using directives for namespaces in absl or std, don't emit
// an include for them.
skip = true;
continue;
goto next_using_directive;
} else if (segment[0] == '_') {
// Don't add an include for our own header. This matters for tests.
if (segment == file.file_namespace_simple_name) {
skip = true;
} else {
string header_filename = Regex.Replace(segment, @"^_", "");
include_path = include_path.Append(header_filename).ToArray();
}
string header_filename = Regex.Replace(segment, @"^_", "");
include_path = include_path.Append(header_filename).ToArray();
break;
} else {
include_path = include_path.Append(segment).ToArray();
}
}
if (!skip) {
new_include_paths.Add(include_path);
}
new_include_paths.Add(include_path);
next_using_directive: {}
}

// Extract the includes.
Expand Down

0 comments on commit 4bde797

Please sign in to comment.