I''ve had a matcher in my head for a couple months, that I frequently want but never get around to writing because I can''t think of the name for it. Here''s how it would look [1, 2, 3, 4, 1].should ... [1, 3, 1, 4, 2] I have a couple ideas for names, but I''ll hold off on them so I don''t influence anyone''s opinion. btw, I realize that .sort works in this case. But that''s slightly less clear than I''d like, and it doesn''t work for non-Comparable objects (like activerecords). Pat
Jonathan Linowes
2008-Aug-06 18:06 UTC
[rspec-users] Someone please name this matcher for me
perhaps verbose but how about foo.should equal_in_any_order [1, 3, 1, 4, 2] On Aug 6, 2008, at 1:50 PM, Pat Maddox wrote:> I''ve had a matcher in my head for a couple months, that I frequently > want but never get around to writing because I can''t think of the name > for it. Here''s how it would look > > [1, 2, 3, 4, 1].should ... [1, 3, 1, 4, 2] > > I have a couple ideas for names, but I''ll hold off on them so I don''t > influence anyone''s opinion. > > btw, I realize that .sort works in this case. But that''s slightly > less clear than I''d like, and it doesn''t work for non-Comparable > objects (like activerecords). > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
On Wed, Aug 6, 2008 at 12:50 PM, Pat Maddox <pergesu at gmail.com> wrote:> I''ve had a matcher in my head for a couple months, that I frequently > want but never get around to writing because I can''t think of the name > for it. Here''s how it would look > > [1, 2, 3, 4, 1].should ... [1, 3, 1, 4, 2][1, 2, 3, 4, 1].should include_all [1, 3, 1, 4, 2]
On Wed, Aug 6, 2008 at 1:50 PM, Pat Maddox <pergesu at gmail.com> wrote:> I''ve had a matcher in my head for a couple months, that I frequently > want but never get around to writing because I can''t think of the name > for it. Here''s how it would look > > [1, 2, 3, 4, 1].should ... [1, 3, 1, 4, 2] > > I have a couple ideas for names, but I''ll hold off on them so I don''t > influence anyone''s opinion. > > btw, I realize that .sort works in this case. But that''s slightly > less clear than I''d like, and it doesn''t work for non-Comparable > objects (like activerecords).[1, 2, 3, 4, 1].should consist_of([1, 3, 1, 4, 2]) Since consist means "to be composed or made up of", which matches the usage. To me it reads like, this thing should be made up of these other things. WDYT? -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com
Consider: should_have_the_same_members_as -----Original Message----- From: rspec-users-bounces at rubyforge.org [mailto:rspec-users-bounces at rubyforge.org] On Behalf Of Zach Dennis Sent: Wednesday, August 06, 2008 11:15 AM To: rspec-users Subject: Re: [rspec-users] Someone please name this matcher for me On Wed, Aug 6, 2008 at 1:50 PM, Pat Maddox <pergesu at gmail.com> wrote:> I''ve had a matcher in my head for a couple months, that I frequently > want but never get around to writing because I can''t think of the name > for it. Here''s how it would look > > [1, 2, 3, 4, 1].should ... [1, 3, 1, 4, 2] > > I have a couple ideas for names, but I''ll hold off on them so I don''t > influence anyone''s opinion. > > btw, I realize that .sort works in this case. But that''s slightly > less clear than I''d like, and it doesn''t work for non-Comparable > objects (like activerecords).[1, 2, 3, 4, 1].should consist_of([1, 3, 1, 4, 2]) Since consist means "to be composed or made up of", which matches the usage. To me it reads like, this thing should be made up of these other things. WDYT? -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
On Wed, 6 Aug 2008 13:50:27 -0400, you wrote:>I''ve had a matcher in my head for a couple months, that I frequently >want but never get around to writing because I can''t think of the name >for it. Here''s how it would look > >[1, 2, 3, 4, 1].should ... [1, 3, 1, 4, 2]An unordered collection with possibly multiple occurrences of its members is known in mathematics as a "multiset," or, informally, a "bag." -Steve
How about [1, 2, 3, 4, 1].should contain([1, 3, 1, 4, 2]) [1, 2, 3, 4, 1].should contain_only([1, 3, 1, 4, 2]) or (riffing off Zach) [1, 2, 3, 4, 1].should be_composed_from([1, 3, 1, 4, 2]) Matt -- Posted via http://www.ruby-forum.com/.
Jonathan Linowes
2008-Aug-06 19:04 UTC
[rspec-users] Someone please name this matcher for me
.should be_bag_of( [1, 3, 1, 4, 2] ) On Aug 6, 2008, at 2:33 PM, Steve Schafer wrote:> On Wed, 6 Aug 2008 13:50:27 -0400, you wrote: > >> I''ve had a matcher in my head for a couple months, that I frequently >> want but never get around to writing because I can''t think of the >> name >> for it. Here''s how it would look >> >> [1, 2, 3, 4, 1].should ... [1, 3, 1, 4, 2] > > An unordered collection with possibly multiple occurrences of its > members is known in mathematics as a "multiset," or, informally, a > "bag." > > -Steve > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
2008-08-06 14:33, Steve Schafer:> An unordered collection with possibly multiple occurrences of its > members is known in mathematics as a "multiset," or, informally, a > "bag."I (standing knee-deep in mathematics) was about to offer the following be_multiset_equal_to be_set_equal_to Set equality is slightly (imo not fatally) incorrect, and multiset might be alien to majority of hackers out there. I''d prefer either of these or modifications. -- Tero Tilus ## 050 3635 235 ## http://www.tilus.net/koti/tero/
2008-08-06 13:11, Mike Vincent:> > [1, 2, 3, 4, 1].should ... [1, 3, 1, 4, 2] > [1, 2, 3, 4, 1].should include_all [1, 3, 1, 4, 2]I''d then think that [1, 1, 1, 2, 3, 4].should include_all [1, 3, 1, 4, 2] [1, 2, 3, 4, 5, 6].should include_all [1, 3, 1, 4, 2] Which afaik was not what Pat had in mind. Or was it? And include_all_and_nothing_but is a bit verbose. :) -- Tero Tilus ## 050 3635 235 ## http://www.tilus.net/koti/tero/
On 07/08/2008, at 05:04 , Jonathan Linowes wrote:> .should be_bag_of( [1, 3, 1, 4, 2] )FWIW, I am in favour of this naming. Now back to lurking :)
Kyle Hargraves
2008-Aug-07 15:17 UTC
[rspec-users] Someone please name this matcher for me
On Wed, Aug 6, 2008 at 1:25 PM, Cohen, Joseph <JDCOHEN at stoel.com> wrote:> > Consider: > should_have_the_same_members_asSimilarly, I have a have_same_elements_as(arr) matcher. k
Lots of good, interesting suggestions. If you don''t mind its length, for the non-mathematically inclined something like has_same_members_as may be easier to remember and corresponds to Ruby''s member? predicate. -----Original Message----- From: rspec-users-bounces at rubyforge.org [mailto:rspec-users-bounces at rubyforge.org] On Behalf Of Kyle Hargraves Sent: Thursday, August 07, 2008 8:17 AM To: rspec-users Subject: Re: [rspec-users] Someone please name this matcher for me On Wed, Aug 6, 2008 at 1:25 PM, Cohen, Joseph <JDCOHEN at stoel.com> wrote:> > Consider: > should_have_the_same_members_asSimilarly, I have a have_same_elements_as(arr) matcher. k _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
is_permutation_of would be technically correct, but it doesn''t really express equality to me, which is the intent of the match. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080808/67530a73/attachment.html>
i wrote this matcher myself for a project i''m working on and have been calling it `equals_without_regard_to_order''. it''s an unwieldy name and i''ve never really been comfortable with it but i''ve continued to use it, mostly because i''m dim. very curious to find a winning replacement on this list! -- Dhruv Bansal http://www.infochimps.org || http://www.dhruvbansal.com || dhruv at infochimps.org "Mark Wilden" <mark at mwilden.com> writes:> is_permutation_of would be technically correct, but it doesn''t > really express equality to me, which is the intent of the match. > > ///ark > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Zach Dennis wrote:> > [1, 2, 3, 4, 1].should consist_of([1, 3, 1, 4, 2])+1
Would such a matcher also work in this instance: Car.should_receive(:find).with(bag_of[@ford.id, @fiat.id]) Such that if I don''t know (or care) what order the IDs will be passed to the find method, this will pass? Or is there already some other way to achieve that? -- Posted via http://www.ruby-forum.com/.