-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Vector Approx matcher #1499
Vector Approx matcher #1499
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1499 +/- ##
=======================================
Coverage 80.72% 80.72%
=======================================
Files 121 121
Lines 3424 3424
=======================================
Hits 2764 2764
Misses 660 660 |
Thanks, this looks good. I have one note and one nitpick though. Note: You should also add a test against strong typedef. |
I'm fine with adjusting this.
I'm not sure exactly what you mean by this. Could you give an example elsewhere in the code? I also have a question -- currently I need to use |
If you go to Thinking about this further, I think this actually opens up a philosophical question about the constructor of the Matcher. Specifically, whether the constructor shouldn't be templated and allow for vector filled with types that are convertible to double, but are not std::vector<Temperature> temps;
// fill temps somehow
REQUIRE_THAT(temps, Catch::Approx({17.2, 17.3, 18.2})); Which is nicer that having to convert the doubles to temperatures by yourself. As to your other question, I am afraid that is unfixable without a different name, because of the using Catch::Matchers::Approx;
CHECK_THAT(v3, Approx(v3));
CHECK_THAT(v4, Approx(v4)); works. |
I've opted for this solution. Regarding the strong typedefs, I had a go at this, but the main issue I seem to be getting if I try to implement a new template<typename T>
Vector::ApproxMatcher<T> Approx( std::initializer_list<T> const& comparator ) {
return Vector::ApproxMatcher<T>( comparator );
} is that this tends to cause segfaults due to the constant reference implicit in the This also seems like a more wholesale change, given that it doesn't work for the |
I modified the tests a bit and merged it. Thanks |
Description
In addition to Equals and UnorderedEquals, this PR implements an Approx matcher for std::vector.
It is implemented along the lines of Equals and UnorderedEquals, with inspiration from previous attempts in issue #760, and this StackOverflow discussion
GitHub Issues
Addresses #760