[Rubytests-devel] assert_set_equal problematic !?

Charles O Nutter headius at gmail.com
Wed Nov 10 10:02:43 EST 2004

It seems like an ok assertion to me, but I agree it's a little odd.
There's two possibilities I can see:

1. It is supposed to test whether the sorted contents of two arrays
are equivalent
2. It issupposed to test whether the two arrays contain the same
elements, ignoring duplicates

It's probably worth a look around the whole of rubicon to see how it's
being used and if it's actually serving any useful purpose. I would
vote in favor of removing it, moving the sort into the tests
themselves (using assert_equal(a.sort, b.sort) as Johan suggests), and
then creating a second assertion for #2 if it's needed. The key is
understanding *why* this assertion is being used and if it's really
doing anything more useful than assert_equal.

We could name the new assertion for #2 assert_same_set perhaps?

- Charlie

On Wed, 10 Nov 2004 09:59:36 +0100 (MET), Johan Holmberg
<holmberg at iar.se> wrote:
> Hi !
> Quite often a test wants to make sure that two arrays contain the
> same elements, but not necessarily in the same order.
> In "rubicon_tests.rb" there is a method "assert_set_equal" that at
> first sight seem to do the right thing. But it seems to have a too
> much "set-like" behaviour (it removes duplicates before comparing).
> See the following example:
>      def test_not_working
>        a = ["x", "y", "z"]
>        b = ["y", "z", "x", "z"]
>        assert_set_equal(a,b)             # misses the error
>        assert_equal(a.sort, b.sort)      # catches the errror
>      end
> What do you think would be the right way to proceed:
> 1) change the semantics of "assert_set_equal" to *not* remove
>     duplicates before comparing
> 2) add another method, something like "assert_equal_after_sort"
>     (but with a better name)
> 3) use calls to "sort" inside the testcases in cases when the order
>     of elements in an array doesn't matter
> 4) use assertion ???? from test/unit.
>     I haven't found any suitable such method, but maybe there is some
>     I have missed.
> 5) continue to use "assert_set_equal" even if it misses certain
>     kinds of errors
> /Johan
> _______________________________________________
> Rubytests-devel mailing list
> Rubytests-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rubytests-devel

More information about the Rubytests-devel mailing list