arashja / hamcrest

Automatically exported from code.google.com/p/hamcrest
0 stars 0 forks source link

IsIterableContainingInOrder matches the elements of a collection exactly but -InAnyOrder does not #59

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I found this inconsistency between the -InOrder and -InAnyOrder versions a
bit confusing, and I had to study the code to be sure of the behavior.
IsIterableContainingInOrder checks the elements in lock-step and fails if
one iteration runs out before the other. However,
IsIterableContainingInAnyOrder does not fail if the Iterable being tested
contains elements that are not matched. Essentially, it is saying, "are
these items in the collection", not "are these the same collections, just
in different orders".

I can see the value of both, but I think the first case is already covered
by IsCollectionContaining.hasItems (if I read that correctly), which reads
better to me anyway. "hasItems" says that the collection contains the items
listed, but may have more. "containsInAnyOrder" could also mean this, but I
think it should be consistent with "containsInOrder", meaning one or the
other should change.

In the meantime, I've written a custom matcher that I've called
"containsInAnyOrderExactly", which is quite a mouthful, but makes the
distinction clear. Any suggestions on better naming would be welcome,
though. The attached file contains demonstrations of the behavior described
and that of the custom matcher.

If you decide that you want to make this change, I can supply a patch.
However, you may prefer to make naming changes instead, to clarify the
expected behavior of the matchers, instead of changing behavior.

Original issue reported on code.google.com by mhack...@kanayo.com on 13 Jan 2009 at 10:15

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by smgfree...@gmail.com on 27 Feb 2009 at 10:52

GoogleCodeExporter commented 8 years ago

Original comment by smgfree...@gmail.com on 27 Feb 2009 at 10:54

GoogleCodeExporter commented 8 years ago

Original comment by smgfree...@gmail.com on 21 Mar 2009 at 11:49

GoogleCodeExporter commented 8 years ago

Original comment by smgfree...@gmail.com on 21 May 2009 at 10:44

GoogleCodeExporter commented 8 years ago

Original comment by smgfree...@gmail.com on 21 May 2009 at 10:45