Matcher that ensures 2 iterables have same elements

4 views
Skip to first unread message

Rodrigo Manhães

unread,
Apr 18, 2011, 10:45:35 PM4/18/11
to should-...@googlegroups.com
Hi,

currently, we don't have a matcher for ensuring 2 iterables have same
elements, ignoring the order.

We have include_in_any_order and include_all_of, but they check if
actual have all elements that expected has, but actual itself may have
other different elements.

Maybe include_in_any_order can be changed to match this need.
Regardless the name, I think we need this kind of matcher. For
example,currently we have to do:

configurable |should| have(2).states
configurable.states |should| include_all_of(['start', 'created'])

With that matcher we could write:

configurable.states |should| have_same_elements_to(['start', 'created'])


Ok to add this matcher to Should-DSL?

[]'s
-------
Rodrigo S. Manhães
-------
Núcleo de Pesquisa em Sistemas de Informação/IFF
Laboratório de Ciências Matemáticas/UENF
-------
Github: https://github.com/rodrigomanhaes
Lattes: http://lattes.cnpq.br/9851240805895558

Rogerio De Carvalho

unread,
Apr 19, 2011, 10:11:26 AM4/19/11
to should-...@googlegroups.com
In my opinion, yes.
I also faced this necessity sometime ago and had to do some workaround to test.

Bye

2011/4/18 Rodrigo Manhães <rman...@gmail.com>:

--
Rogerio Atem de Carvalho

Gabriel Lima de Oliveira

unread,
Apr 19, 2011, 5:22:38 PM4/19/11
to should-...@googlegroups.com
I think I did'nt get your point.

Isn't it resolved with

configurable.states |should| equal_to(['start', 'created'])

?

 Att,
Gabriel L. Oliveira

Rodrigo Manhães

unread,
Apr 19, 2011, 5:41:54 PM4/19/11
to should-...@googlegroups.com
2011/4/19 Gabriel Lima de Oliveira <cibe...@gmail.com>:

> I think I did'nt get your point.
>
> Isn't it resolved with
>
> configurable.states |should| equal_to(['start', 'created'])
>
> ?

No, since configurable can be ['created', 'start'] and python lists are ordered.

[]'s
Rodrigo

Hugo Lopes Tavares

unread,
Apr 24, 2011, 4:34:32 PM4/24/11
to should-...@googlegroups.com, Rodrigo Manhães
Sorry for joining the conversation today..
I don't know if it is the best option we have.

What about duplicated elements? For instance:

mylist = [1, 2, 1]

I need some minutes to think about this new matcher.


Talk to you later!

Rodrigo Manhães

unread,
Apr 25, 2011, 7:16:43 AM4/25/11
to Hugo Lopes Tavares, should-...@googlegroups.com
Since lists allow duplicate elements, I think the matcher must consider that.

[1, 2, 1] should not equal [1, 2] ignoring order

[1, 2, 1] should equal [2, 1, 1] ignoring order

[]'s
Rodrigo


2011/4/24 Hugo Lopes Tavares <hlt...@gmail.com>:

Hugo Lopes Tavares

unread,
Apr 27, 2011, 10:18:28 PM4/27/11
to Rodrigo Manhães, should-...@googlegroups.com
Okay. I agree with the matcher idea, but I am -1 for the matcher name.
Isn't it a bad grammar (the `to` in the end)?

Isn't it `have_same_elements_as`?

Rogerio De Carvalho

unread,
Apr 28, 2011, 12:20:14 PM4/28/11
to should-...@googlegroups.com
Is it possible to use as syntax sugar?
Something like should equal_to(some_set).in_any_order

Regards
2011/4/27 Hugo Lopes Tavares <hlt...@gmail.com>:

--
Rogerio Atem de Carvalho

Hugo Lopes Tavares

unread,
Apr 28, 2011, 1:07:21 PM4/28/11
to should-...@googlegroups.com
Nice, Rogerio!

If I would think about another possibility it would be using named
parameters. Like:

foo |should| equal_to(some_set, ignore_sort=True)

foo |should| equal_to(some_set, sorted=False)


Just spreading some ideas... The problem with these alternatives is we
loose some natural readability.


Later!

Rogerio De Carvalho

unread,
Apr 28, 2011, 1:46:27 PM4/28/11
to should-...@googlegroups.com
Yes, I think it |should| stick to the readability.

bye


2011/4/28 Hugo Lopes Tavares <hlt...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages