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: bd49e590d848
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: df5cce36664b
Choose a head ref
  • 3 commits
  • 4 files changed
  • 2 contributors

Commits on Mar 31, 2018

  1. Copy the full SHA
    bae5a37 View commit details
  2. Copy the full SHA
    e5f9f8e View commit details

Commits on Apr 1, 2018

  1. Merge pull request #1782 from eggrobin/more-is-near

    Use IsNear where appropriate in SymplecticRungeKuttaNyströmIntegratorTest
    pleroy authored Apr 1, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    df5cce3 View commit details
10 changes: 4 additions & 6 deletions integrators/symplectic_runge_kutta_nyström_integrator_test.cpp
Original file line number Diff line number Diff line change
@@ -47,7 +47,6 @@ using testing_utilities::ComputeHarmonicOscillatorAcceleration1D;
using testing_utilities::EqualsProto;
using testing_utilities::IsNear;
using testing_utilities::PearsonProductMomentCorrelationCoefficient;
using testing_utilities::RelativeError;
using testing_utilities::Slope;
using testing_utilities::VanishesBefore;
using ::std::placeholders::_1;
@@ -527,8 +526,8 @@ TEST_P(SymplecticRungeKuttaNyströmIntegratorTest, Convergence) {
LOG(INFO) << "Correlation : " << q_correlation;

#if !defined(_DEBUG)
EXPECT_THAT(RelativeError(GetParam().order, q_convergence_order),
Lt(0.02));
EXPECT_THAT(q_convergence_order,
IsNear(static_cast<double>(GetParam().order), 1.04));
EXPECT_THAT(q_correlation, IsNear(1.0, /*tolerance=*/1.02));
#endif
double const v_convergence_order = Slope(log_step_sizes, log_p_errors);
@@ -538,9 +537,8 @@ TEST_P(SymplecticRungeKuttaNyströmIntegratorTest, Convergence) {
LOG(INFO) << "Correlation : " << v_correlation;
#if !defined(_DEBUG)
// SPRKs with odd convergence order have a higher convergence order in p.
EXPECT_THAT(RelativeError(GetParam().order + (GetParam().order % 2),
v_convergence_order),
Lt(0.02));
EXPECT_THAT(v_convergence_order,
IsNear(GetParam().order + (GetParam().order % 2), 1.05));
EXPECT_THAT(v_correlation, IsNear(1.0, /*tolerance=*/1.02));
#endif
}
9 changes: 7 additions & 2 deletions testing_utilities/is_near.hpp
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
#pragma once

#include <string>
#include <type_traits>

#include "gmock/gmock.h"
#include "quantities/quantities.hpp"
@@ -13,15 +14,19 @@ namespace internal_is_near {
template<typename T>
class IsNearMatcher;

template<typename T>
using ExpectedType =
std::conditional_t<std::is_arithmetic<T>::value, double, T>;

// Calls the next function with |tolerance| set to 1.1.
template<typename T>
testing::PolymorphicMatcher<IsNearMatcher<T>> IsNear(
testing::PolymorphicMatcher<IsNearMatcher<ExpectedType<T>>> IsNear(
T const& expected);

// Checks that |expected| is in the range
// [expected / √tolerance, expected √tolerance].
template<typename T>
testing::PolymorphicMatcher<IsNearMatcher<T>> IsNear(
testing::PolymorphicMatcher<IsNearMatcher<ExpectedType<T>>> IsNear(
T const& expected,
double tolerance);

27 changes: 13 additions & 14 deletions testing_utilities/is_near_body.hpp
Original file line number Diff line number Diff line change
@@ -3,11 +3,9 @@

#include "testing_utilities/is_near.hpp"

#include <float.h>
#include <math.h>
#include <stdint.h>

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <limits>
#include <string>

@@ -25,19 +23,19 @@ using quantities::DebugString;
using quantities::Pow;

template<typename T>
testing::PolymorphicMatcher<IsNearMatcher<T>> IsNear(
testing::PolymorphicMatcher<IsNearMatcher<ExpectedType<T>>> IsNear(
T const& expected) {
return testing::MakePolymorphicMatcher(
IsNearMatcher<T>(expected, /*tolerance=*/1.1));
IsNearMatcher<ExpectedType<T>>(expected, /*tolerance=*/1.1));
}

template<typename T>
testing::PolymorphicMatcher<IsNearMatcher<T>> IsNear(
testing::PolymorphicMatcher<IsNearMatcher<ExpectedType<T>>> IsNear(
T const& expected,
double const tolerance) {
CHECK_LE(1.0, tolerance);
return testing::MakePolymorphicMatcher(
IsNearMatcher<T>(expected, tolerance));
IsNearMatcher<ExpectedType<T>>(expected, tolerance));
}

template<typename T>
@@ -57,7 +55,7 @@ bool IsNearMatcher<T>::MatchAndExplain(
bool const match = low_ <= actual && actual <= high_;
if (!match) {
*listener << "which is not in the range [" << low_ << ", " << high_
<< "] and is a factor of "
<< u8"] and is a factor of "
<< Pow<2>(std::max(actual / expected_, expected_ / actual))
<< " from the expected value";
}
@@ -70,24 +68,25 @@ bool IsNearMatcher<T>::MatchAndExplain(
testing::MatchResultListener* listener) const {
bool const match = low_ <= actual && actual <= high_;
if (!match) {
*listener << "which is not in the range [" << DebugString(low_)
<< ", " << DebugString(high_) << "] and is off by "
<< std::max(actual / expected_, expected_ / actual);
*listener << "which is not in the range [" << DebugString(low_) << ", "
<< DebugString(high_) << u8"] and is a factor of √"
<< Pow<2>(std::max(actual / expected_, expected_ / actual))
<< " from the expected value";
}
return match;
}

template<typename T>
void IsNearMatcher<T>::DescribeTo(std::ostream* out) const {
*out << "is within ["<< low_
<< ", " << high_ << "], i.e., a factor " << tolerance_
<< ", " << high_ << u8"], i.e., a factor " << tolerance_
<< " away from " << expected_;
}

template<typename T>
void IsNearMatcher<T>::DescribeNegationTo(std::ostream* out) const {
*out << "is not within ["<< low_
<< ", " << high_ << "], i.e., a factor " << tolerance_
<< ", " << high_ << u8"], i.e., a factor " << tolerance_
<< " away from " << expected_;
}

2 changes: 1 addition & 1 deletion testing_utilities/is_near_test.cpp
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ TEST_F(IsNearTest, Quantity) {
}

TEST_F(IsNearTest, Negatives) {
EXPECT_THAT(π - std::exp(π), IsNear(-20, 1.00001));
EXPECT_THAT(π - std::exp(π), IsNear(-20, 1.0001));
}

} // namespace testing_utilities