Specifications are not just comments; they are the contract that defines what a function (or module) is supposed to do and how it should be used. When we implement a function, we must write the function according to the specifications. When we call a function, we must obey the specifications, i.e., provide arguments that are valid according to the specifications.
Testing is the first step in making sure that our functions are correct--meet specifications. It is important to make a test plan--choose appropriate test cases--based on the specifications only, not based on the function code.
Optionally, Read: 4.9 and 9.5 ( html version )
Slides:
individual slides for viewing
,
6-up layout for printing
Examples: welcome.py, campus.py, name.py (incomplete!), nametest.py, name_campus_test.py,
Module to support testing:
cornellasserts.py
(for use the rest of the semester)
To download the above files, right-click (Windows) or command-click (Macs) on the filename and then select "Save link as". This way you choose where the files will be saved, instead of having your computer save to the default folder (from which you will later have to move your files for organization).
Questions and Answers: check the answers — after you try them on your own!
Did you
debug
function
last_name_first
,
perhaps by adding the print statements shown on the last lecture slide?
After
you have done your own debugging, take a look at
our solution.