ex12KangYooPark

ex12KangYooPark - # nothing (there is no return value) #...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
# ex12KangYooPark K.Y.Park for CS5NM FALL 2008, UCSB # last updated: 11/12/08 # based on: hasNoETest.py: P.Conrad for CS5NM, Fall 2008, UC Santa Barbara # Incorporates code from Think Python, by Allen B. Downey, from Chapter 9 # Shows how to use check_expect testing with string functions ################################################################ # Here is the function definition from Chapter 9 (section 9.3) ################################################################ def has_no_e(word): for letter in word: if letter == 'e' or letter == 'E': return False return True ##################################### # Here is our check_expect function ##################################### # 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:
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: # 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) ############################################################### # Here are tests to see if has_no_e(word) functions correctly ############################################################### check_expect("has_no_e('Fred')",has_no_e('Fred'),False) check_expect("has_no_e('Jane')",has_no_e('Jane'),False) check_expect("has_no_e('Santa')",has_no_e('Santa'),True) check_expect("has_no_e('Barbara')",has_no_e('Barbara'),True) check_expect("has_no_e('Goleta')",has_no_e('Goleta'),False) check_expect("has_no_e('Edward')",has_no_e('Edward'),False) check_expect("has_no_e('Ice Cream')",has_no_e('Ice Cream'),False)...
View Full Document

Ask a homework question - tutors are online