[TIP] Which is the proper way to test an "unordered list"

Herman Sheremetyev herman at swebpage.com
Thu May 17 00:43:40 PDT 2012

On Thu, May 17, 2012 at 4:10 PM, Michael Rene Armida <me at marmida.com> wrote:
> I find that sets are sufficient for this purpose, so your original:
>> >    assert a_transition.next_states == ["a state","another state"]
>  Would become:
>     assert set(a_transition.next_states) == set(["a state","another state"])

If sets were appropriate for this then the data structure should be a
set to start with. Otherwise the test would happily succeed for
set(['x', 'x']) == set(['x']). The OP's issue might actually call for
sets so this may be fine in this case but is not a good way to test
equality of unordered lists.

> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python

More information about the testing-in-python mailing list