Repository navigation
Relative order - #74
Merged
Merged
Conversation
order) between items in an iterable. The iterable may contain gaps inbetween two matching items. Gaps may appear at the beginning, end or in between. A user may specify may gaps in the sequence. e.g. Given an iterable 1, 2, 3, 4, 5, 6, 7 if the user were to specify containsInRelativeOrder(2, 4, 6) this would match successfully. This commit is the direct incorporation of a patch provided by Kevin Pauli. See also https://groups.google.com/forum/?fromgroups#!topic/hamcrest-dev/FsLlyRcGPzs
it'll appear on the "Matchers" factory utility which was initially missing from Kevin Pauli's patch.
|
If I'm understanding this correctly, However, the similarly-named Is this correct? Should we rename this so it's not confused with |
|
Here's a pull request that implements a non-anchored |
|
Hi Ben, It does seem to me that it should be called hasItemsInRelativeOrder, similar to your recent PR. |
sdwilsh
pushed a commit
to meta/buck
that referenced
this pull request
Jan 10, 2015
Summary: Hamcrest includes `Matcher` implementations which: 1) Check if a collection includes a single item anywhere (`hasItem`) 2) Check if a collection includes multiple items anywhere (`hasItems`) 3) Check if a collection exactly matches another collection in order (`contains`) 4) Check if a collection exactly matches another collection in any order (`containsInAnyOrder`) Bizarrely, Hamcrest even recently added a `Matcher` which searches for the items of a collection in relative order anywhere inside the target collection (`containsInRelativeOrder`). (Note that this searches anywhere inside the container, unlike the other `contains` `Matcher`s!) hamcrest/JavaHamcrest#74 We need a `Matcher` which finds a sub-collection inside a larger collection in order (i.e., finding `[2, 3]` inside `[1, 2, 3]` but not inside `[1, 2, 42, 3]`). This diff adds that matcher, `hasConsecutiveItems()`, along with tests. Test Plan: Unit tests includes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is a feature I've wanted for some time that Kevin Pauli from the Hamcrest Developers mailing list suggested in April along with a patch. I've applied his patch to the codebase and ensured it all looks sensible. My only contribution to this is a couple test cases I felt were useful and inclusion in matchers.xml.
The matcher is similar to the IsIterableContainingInOrder matcher except it accepts a partial order ("relative order") between elements. Allowing you to match an actual collection of 1, 2, 3, 4, 5, 6, 7 with a specification of containsInRelativeOrder(2, 4, 6).
Kevin Pauli's initial post https://groups.google.com/forum/?fromgroups#!msg/hamcrest-dev/FsLlyRcGPzs/X0sWHuv8LkkJ