ex14KangYooPark

ex14KangYooPark - # # # # # # # # # # # # ex14KangYooPark:...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
# ex14KangYooPark: Kang Yoo Park 11/21/08 # based on: ex14PhillConrad.py; Starting point for ex14, CS5nm, 11/19/2008 # Exercises with checking type # check_expect checks whether a function produces the expected result # consumes: # test: a string describing the test # check: the value we are testing (typically result of a function call) # expect: the value we are expecting (typically a literal value) # produces: # nothing (there is no return value) # side effect: # prints a message indicating whether the test passed or failed def check_expect(test,check,expect): if (check == expect): print "Test " + test + " passed." else: print "Test " + test + " failed: expected " + str(expect) + \ " but I got " + str(check) # consumes: a parameter of any type # produces: boolean, True if the parameter is of type list def isList(x): return ( type(x) == type([1,2,3]) ) # True if the type of x is a list check_expect("isList([])", isList([]), True) # empty list check_expect("isList([1])", isList([1]), True) # singleton list
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

ex14KangYooPark - # # # # # # # # # # # # ex14KangYooPark:...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online