Closed pjritee closed 9 years ago
The best solution would be to just require the student to return the list in any order, but only test for unordered equality.
You could either do
self.assertEqual(sorted(expected), sorted(student_result))
or
self.assertEqual(set(expected), set(student_result))
Yes - I was coming to that conclusion - thanks
Note - I suggest sorted()
over set()
for checking unordered equality, since it preserves any incorrect duplicates.
Yes - I did that (for the same reason)
I am fixing up the duplication in the dictionary problems and rewrote the dictionary iteration example. It's the same as the old one - find the keys whose values are bigger than another value. Given that the hashing of strings seems to be different on different OSs I decided that the function should return the sorted list. However, an interesting problem arose (at least under Linux) I wrote a solution that didn't sort before returning and the test big_keys({'a':24, 'x':30, 't':12, 'n':10}, 15) -> ['a', 'x'] works but the hidden alt test big_keys({'a':24, 'e':30, 't':12, 'n':10}, 40) -> ['a', 'e', 'n', 't']
doesn't work and I get
Make sure your code also works for similar inputs
Unfortunately this doesn't give any hints to the student as to what went wrong - it was just a fluke that the first test generated the list in sorted order itself. Any suggestions on what to do?