<div class="gmail_quote">On Fri, May 18, 2012 at 6:24 AM, Jorge Vargas <span dir="ltr"><<a href="mailto:jorge.vargas@gmail.com" target="_blank">jorge.vargas@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thank you all for the answers.<br>
<br>
This got me thinking about my dataset<br>
- The order is irrelevant, however it's good to have.<br>
- There should be only one of each type but it is not really enforced.<br>
Most checks here are in the for of "value in states" so if someone<br>
makes the mistake of adding the same state twice it doesn't really<br>
affect things.<br>
<br>
So a set seems to be the proper construction here. That said I could<br>
stick with a list as there is no real need of the overhead of sets (I<br>
know it's little) but it's really irrelevant to keep it as the only<br>
case where the list will contain the same value twice is by programmer<br>
error. So i believe the sorted(list) solution makes the most sense. It<br>
will catch errors as a state not being "declared" (that's what the<br>
decorator does), catch if the same state is added twice but will not<br>
really care about the order.<br>
<div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div><br></div><div>See also assertItemsEqual (renamed to assertCountEqual in 3.2).</div><div><br></div><div> <a href="http://docs.python.org/library/unittest.html#unittest.TestCase.assertItemsEqual">http://docs.python.org/library/unittest.html#unittest.TestCase.assertItemsEqual</a></div>
<div> <a href="http://docs.python.org/dev/library/unittest.html#unittest.TestCase.assertCountEqual">http://docs.python.org/dev/library/unittest.html#unittest.TestCase.assertCountEqual</a></div><div><br></div><div>-gps</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
On Thu, May 17, 2012 at 7:16 PM, Andrew Dalke <<a href="mailto:dalke@dalkescientific.com">dalke@dalkescientific.com</a>> wrote:<br>
> On May 17, 2012, at 3:30 AM, Jorge Vargas wrote:<br>
>> My question is which will be the proper way to test for this when the<br>
>> "order of the list" is not valid?<br>
><br>
> The right answer depends on what the data set contains. Others have<br>
> already suggested:<br>
><br>
> 1) sorting; but that assumes that the objects can be compared<br>
> by inequality<br>
><br>
> 2) converting to a set, but that assumes that objects are hashable,<br>
> and that duplicates can be ignored<br>
><br>
> You can fix #2 by<br>
><br>
> 3) use a collections.Counter; this still requires hashable objects<br>
> but doesn't have the count problem<br>
><br>
><br>
> The only generic solution is:<br>
><br>
> 4) Do the O(n*m) test of checking each item from one list to see<br>
> if it occurs in the other, removing matches as they are found<br>
><br>
> Most people are uncomfortable with potentially quadratic worst-case<br>
> times, but with only a couple of states, this isn't a problem.<br>
><br>
><br>
> In your case, you can probably use the sets solution without a problem,<br>
> especially if your "next" implementation verifies that there are no<br>
> duplicates in the list. Or as Herman's commented, perhaps your<br>
> implementation is more appropriate with a set in the first place?<br>
><br>
> Cheers,<br>
><br>
> Andrew<br>
> <a href="mailto:dalke@dalkescientific.com">dalke@dalkescientific.com</a><br>
><br>
><br>
><br>
> _______________________________________________<br>
> testing-in-python mailing list<br>
> <a href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a><br>
> <a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
<br>
_______________________________________________<br>
testing-in-python mailing list<br>
<a href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a><br>
<a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
</div></div></blockquote></div><br>