-
Notifications
You must be signed in to change notification settings - Fork 112
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
hamcrest.contains_inanyorder is order sensitive #118
Comments
Hmmmmm. I can see what's going on here. It's not that In your example, the I'm not sure how I'd approach fixing this. Any ideas, @robertwb? |
In the meantime, the matcher is working as documented, and you can support your use case by specifying the more specific matchers first, then the less specific. |
Yes, in this toy example it's clear to see what the order could be, but that's not always the case. This could be solved generally with https://en.wikipedia.org/wiki/Maximum_cardinality_matching |
Interesting, but I'm not sure I think the complexity is worthwhile. How often is this an issue? If we implemented a maximum cardinality matching algorithm, how would that work with consume-once actuals, such as generators? In any case, I won't get to look at it until #117 is in. |
I've run into it a couple of times, the latest because the set of matchers is derived from a container with non-deterministic ordering. For consume-once actuals, one would either run it against all matchers while iterating (rather than just until one finds a match) or reify it into a list. |
E.g.
assert_that([1, 2], contains_inanyorder(anything(), 1))
fails.The text was updated successfully, but these errors were encountered: