-
-
Notifications
You must be signed in to change notification settings - Fork 649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide some easy way to compare structs containing float/doubles #73
Comments
Have you tried writing a function like: void checkA(const A& lhs, const B& rhs) {
CHECK(lhs.x==Approx(rhs.x));
CHECK(lhs.y==Approx(rhs.y));
CHECK(lhs.z==Approx(rhs.z));
} |
@chambm: It doesn't work, because if the macro fails the error won't be on the line calling checkA, but inside checkA, so it will be really hard to debug this problem only looking at the log. |
How about a macro then? #define checkA(lhs, rhs) do { \
CHECK((lhs).x==Approx((rhs).x)); \
CHECK((lhs).y==Approx((rhs).y)); \
CHECK((lhs).z==Approx((rhs).z)); \
} while(false) |
I don't see a way for doctest to solve this for user types in a generic way out of the box - I'd recommend using a macro like @chambm suggests. |
Sorry for necroing, but in catch2, that has the same construction, I implemented a custom templated version of Approx, that's basically calling a global approx_equal function:
it is less macros and I can use the standard Not sure if doctest support less/greater than operators for Approx like catch2 but I don't use them so they are excluded from my version. |
I have Vector3, Color3 and similar classes that I need to test.
They look like:
struct A { float x, y, z; };
I want to be able to use something like the Floating point comparisons to do per component comparisons.
So I want to be able to do:
The added benefit is that the values of a and b will be visible when the test fails. At the moment I can only do this with a function returning a bool value.
The text was updated successfully, but these errors were encountered: