moll-dev/Data-Structure-Zoo

__contains__() isn't working for test ???

nucle0tides opened this issue · 2 comments

see test_contains_sucess. test fails when trying to see if singleLinkListData contains "Watson"

This test fails because the contains() method does not check the last item of a list.
The condition:
while cur.next is not None:
evaluates to false at the last before item, not the last item.

Editing this to:
while cur is not None
fixes this bug.

Also, the same method has an else: section which is almost never executed; the method fails to return False when an item is not present in the list; this is fixed by removing the line containing else: and just returning False.

Thanks for working that one out!