Skip to content
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

Create containsAllIn matcher #72

Closed
alanrussian opened this issue Apr 5, 2018 · 3 comments
Closed

Create containsAllIn matcher #72

alanrussian opened this issue Apr 5, 2018 · 3 comments

Comments

@alanrussian
Copy link

One of the matchers I use often in Java's truth library is "containsAllIn". I've found myself needing something like this in Dart a few times now.

A comparison of matchers in Truth vs. this package (credit @natebosch):

containsExactlyElementsIn(...) -> unorderedEquals(...)
containsExactlyElementsIn(...).inOrder() -> orderedEquals(...)
containsAll(Iterable matchers) => allOf(matchers.map(contains).toList())
containsAllOf(...).inOrder() -> containsAllInOrder(...)
containsAllIn -> Does not exist

@natebosch
Copy link
Member

On thing that makes this tricky is that to match the semantics of other Iterable matchers in this package we'd want to support some looseness which means that a given element in the checked value could match more than one element of the expectation.

expect([2,1], containsAll([greaterThan(0), greaterThan(1)]);

My first greedy approach to solve this didn't work since the 2 matched the greaterThan(0) and failed to find a match for greaterThan(1). We might need to treat it like a bipartite matching problem.

@natebosch
Copy link
Member

looks like unorderedMatches suffers the same problem
#73

natebosch added a commit that referenced this issue Apr 11, 2018
Closes #72

- Add `mustMatchEveryValue` to the implementation for unordered matches.
- Implement containsAll as an unorderedMatches which does allows extra
  values in the checked iterable.
natebosch added a commit that referenced this issue Apr 12, 2018
Closes #72

- Add `allowUnmatchedValues` to the implementation for unordered matches.
- Implement containsAll as an unorderedMatches which does allows extra
  values in the checked iterable.
@alanrussian
Copy link
Author

Thanks for the quick fix, Nate! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants