A well-written Python program, with docstrings including doctests and
a separate test function for other more complete tests that are not
included in the doctests, is pretty close to what we need in our
PyKata data, and has the advantage that it can be tested on the
author's computer before uploading to PyKata. To make it easy for the
import script to parse these files, we could add tags in the comments,
like # name:, # categories:, and # description:.
# name: list123FAIL
# categories: list logic
# description:
'''
Given a list of ints, return True if the sequence .. 1, 2, 3, ..
appears
anywhere in the list.
# .. translated from Nick Parlante's http://javabat.com/prob/p136041
~'''
def list123(nums):
'''Given a list of ints, return True if the sequence .. 1, 2, 3, ..
appears
anywhere in the list.
>>> list123([1, 1, 2, 3, 1])
True
>>> list123([1, 1, 2, 4, 1])
False
>>> list123('12345')
Traceback (most recent call last):
- - -
AssertionError
~'''
assert type(nums) == list
for i in range(len(nums) - 2):
if nums[i:i+3] == [1,2,3]: return True
return False
# skeleton:
'''
def list123(nums):
# Here is a solution that satisfies the example
# tests, but fails the more complete unit tests.
# Fix it.
assert type(nums) == list # make sure the arg is a list
for i in [1, 2, 3]:
if i not in nums: return False
return True
~'''
# other tests:
def tests():
'''
>>> list123([1, 3, 2, 1, 2, 1])
False
~'''
Any suggestions?
-- Dave
--
You received this message because you are subscribed to the Google Groups "PyWhip" group.
To post to this group, send email to pyw...@googlegroups.com.
To unsubscribe from this group, send email to pywhip+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pywhip?hl=en.