[Pharo-users] [Pharo-dev] TestAsserter>>assertCollection:hasSameElements:

Christophe Demarey Christophe.Demarey at inria.fr
Sat Oct 24 16:14:59 EDT 2015


Hi Peter,

Le 24 oct. 2015 à 20:36, Peter Uhnák a écrit :

> bump? :)
> 
> On Tue, Sep 29, 2015 at 12:57 AM, Peter Uhnák <i.uhnak at gmail.com> wrote:
> How practical it is to do set-based comparison in TestAsserter>>assertCollection:hasSameElements: ?
> 
> For example #(1 1 2) has same elements as #(1 2) which may make sense for sets, but not for bags.
> 
> The main reason I was using it is that in tests the expected collection may be created by hand,
> which means it is very often an array #(...), { ... }, while models very often return OrderedCollections (at least in my case).


I introduced #assertCollection:hasSameElements:  for this reason.
The problem with using sets is that I do not expect that  #(1 1 2) has same elements as #(1 2)

> 
> So my question is --- how to compare collections irrespective of type, and possibly of order?
> 
> A) always convert the actual collection toanArray
> 
> B) change difference: behavior for non-sets (ton of work with catastrophic consequences)
> 
> C) extend TAssertable with new methods like 
> 
> #assertElementsOf: actualCollection equals: expectedCollection
> #assertUnorderedElementsOf: actualCollection equals: expectedCollection

This solution has my preference

> C.a) directly in Pharo/SUnit

yes, for me, it is a very basic assertion that should be available as default.

> C.b) in independend SUnit-Extensions repository/project
> C.c) just in my project
> 
> D) stop discussing non-problems
> 
> Thanks,
> Peter
> 

Christophe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-users_lists.pharo.org/attachments/20151024/dbc9f2a3/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4302 bytes
Desc: not available
URL: <http://lists.pharo.org/pipermail/pharo-users_lists.pharo.org/attachments/20151024/dbc9f2a3/attachment.p7s>


More information about the Pharo-users mailing list