Skip to content

Commit

Permalink
Flattened catch2 for combined eigen3+ranges checks
Browse files Browse the repository at this point in the history
  • Loading branch information
fradav committed Jun 21, 2020
1 parent 63597a7 commit 1439712
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions test/eigenrange-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ TEST_CASE("Eigen with ranges")
// const auto& expected = Catch::Range::EqualsMatcher<std::vector<int>,std::vector<int>>(std::vector{1,2,3});
auto row0 = m1.row(0);
std::vector<int> vect_expected{1, std::numeric_limits<int>::quiet_NaN(), 3};
const auto &expected = Catch::Matchers::Equals<decltype(row0), std::vector<int>>(row0);
const auto &expected = Catch::Matchers::Equals<int, decltype(row0), std::vector<int>>(row0);
CHECK_THAT(vect_expected, expected);

MatrixXd m2(2, 3);
Expand All @@ -58,7 +58,7 @@ TEST_CASE("Eigen with ranges")

auto row1 = m2.row(0);
std::vector<double> vect_expected2{1.0, 2.0, 3.0};
const auto &expected2 = Catch::Matchers::Approx<decltype(row1), std::vector<double>>(row1);
const auto &expected2 = Catch::Matchers::Approx<double, decltype(row1), std::vector<double>>(row1);
CHECK_THAT(vect_expected2, expected2);

MatrixXd m3(2, 3);
Expand All @@ -67,15 +67,15 @@ TEST_CASE("Eigen with ranges")

auto row2 = m3.row(0);
std::vector<double> vect_expected3{1.0, std::numeric_limits<double>::quiet_NaN(), 3.0};
const auto &expected3 = Catch::Matchers::Approx<decltype(row2), std::vector<double>>(row2);
const auto &expected3 = Catch::Matchers::Approx<double, decltype(row2), std::vector<double>>(row2);
CHECK_THAT(vect_expected3, expected3);

MatrixXd m4(2, 3);
m3 << 1.0, 2.001, 3.0,
4.0, 5.0, 6.0;

auto row3 = m3.row(0);
const auto &expected4 = Catch::Matchers::Approx<decltype(row1), std::vector<double>>(row3);
const auto &expected4 = Catch::Matchers::Approx<double, decltype(row1), std::vector<double>>(row3);
CHECK_THAT(vect_expected2, !expected4);

RowVectorXd vec1(3);
Expand Down
8 changes: 4 additions & 4 deletions test/floatvectormatcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace Catch
template <typename Rng1, typename Rng2>
struct ApproxMatcher : MatcherBase<Rng2>
{
typedef ranges::range_value_t<Rng1> T;
typedef ranges::range_value_t<Rng2> T;

ApproxMatcher(Rng1 const &comparator) : m_comparator(comparator), approx{0.} {}

Expand Down Expand Up @@ -109,7 +109,7 @@ namespace Catch
template <typename Rng1, typename Rng2>
struct EqualsMatcher : MatcherBase<Rng2>
{
typedef ranges::range_value_t<Rng1> T;
typedef ranges::range_value_t<Rng2> T;

EqualsMatcher(const Rng1 &comparator) : m_comparator(comparator) {}

Expand Down Expand Up @@ -138,13 +138,13 @@ namespace Catch
};
} // namespace Range

template <typename Rng1, typename Rng2>
template <typename T, typename Rng1, typename Rng2>
Range::ApproxMatcher<Rng1, Rng2> Approx(Rng1 const &comparator)
{
return Range::ApproxMatcher<Rng1, Rng2>(comparator);
}

template <typename Rng1, typename Rng2>
template <typename T, typename Rng1, typename Rng2>
Range::EqualsMatcher<Rng1, Rng2> Equals(const Rng1 &comparator)
{
return Range::EqualsMatcher<Rng1, Rng2>(comparator);
Expand Down
2 changes: 1 addition & 1 deletion test/readreftable-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void test_random_lines(HighFive::File &file, const string &dataname, const Matri
ThreadPool::ParallelFor((size_t)0u, nloop, [&](size_t j) {
auto i = indices[j];
auto row = p.row(i);
const auto &expected = Catch::Matchers::Approx<decltype(row),std::vector<double>>(row);
const auto &expected = Catch::Matchers::Approx<double, decltype(row),std::vector<double>>(row);
CHECK_THAT(data[i], expected);
});
}
Expand Down

0 comments on commit 1439712

Please sign in to comment.