Makogan
Makogan

Reputation: 9540

Rapid Check how to get output for custom types?

I have the following code with rapidcheck:

namespace rc {

template<>
struct Arbitrary<Point> {
  static Gen<Point> arbitrary() {
    return gen::build<Point>(
        gen::set(&Point::x),
        gen::set(&Point::y),
        gen::set(&Point::z));
  }
};

void showValue(const Point &point, std::ostream &os) {
    os << "(" << point.x << ", " << point.y << "," << point.z << ")"  << std::endl;
}

void showValue(const std::vector<Point> &points, std::ostream &os) {
    for(const auto& p :points) showValue(p, os);
}
} // namespace rc

RC_GTEST_PROP(MathUtilsTests, TestRayTriangleIntersectionRC,
    (const Point &p1, const Point &p2, const Point &p3))
{
    cout << p1.x << endl;
    RC_ASSERT_FALSE(true);
}

int main(int argc, char **argv)
{
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}

According to the documentation: https://github.com/emil-e/rapidcheck/blob/master/doc/displaying.md

Merelely overloading the << operator is enough to see custom values being printed, but I see this:

Using configuration: seed=2752376473595600664
0
0
0
../../libraries/rapidcheck/extras/gtest/include/rapidcheck/gtest.h:29: Failure
Failed
Falsifiable after 1 tests

std::tuple<[unknown type], [unknown type], [unknown type]>:
(<???>, <???>, <???>)

../../Src/tests/Master_test.cpp:128:
RC_ASSERT_FALSE(true)

Expands to:
true

[  FAILED  ] MathUtilsTests.TestRayTriangleIntersectionRC (5 ms)

How can I get more meaningful error messages?

Upvotes: 0

Views: 229

Answers (1)

Jordfr&#228;s
Jordfr&#228;s

Reputation: 9153

To me it seems to work if I put showValue() in the namespce rc::detail:

namespace rc { namespace detail {

void showValue(const Point &point, std::ostream &os) {
    os << "(" << point.x << ", " << point.y << "," << point.z << ")"  << std::endl;
}

}}

Upvotes: 0

Related Questions