lecture09

lecture09 - Lecture 9: October 25, 2010 Testing and...

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

View Full Document Right Arrow Icon
Caltech CS 1: Fall 2010 Lecture 9 : October 25, 2010 Testing and G r a p h i c s
Background image of page 1

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

View Full DocumentRight Arrow Icon
Caltech CS 1: Fall 2010 Binary and hexadecimal numbers Dictionaries
Background image of page 2
Caltech CS 1: Fall 2010 Testing your code Introduction to computer graphics continued next class Keyword arguments
Background image of page 3

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

View Full DocumentRight Arrow Icon
Caltech CS 1: Fall 2010 Code that has never been tested should be considered wrong by definition Once code is written, the first thing that should be done is to test it Different ways to go about this informally systematically
Background image of page 4
Caltech CS 1: Fall 2010 Informal testing means to run the code interactively on whatever examples come to mind Once you're done, what can you say? "It seems to work OK" This is rarely good enough
Background image of page 5

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

View Full DocumentRight Arrow Icon
Caltech CS 1: Fall 2010 Systematic testing means to have some set of test cases that you run to test your code automatically If you change your code, can re-run the test cases easily to see if you broke anything
Background image of page 6
Caltech CS 1: Fall 2010 No amount of testing can guarantee that your code is 100% free of bugs "Exhaustive testing" (testing for every single possible bug) has been called "Exhausting testing" Better strategy: when a bug comes up, write a new test case So it won't come up again! Get better code coverage over time
Background image of page 7

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

View Full DocumentRight Arrow Icon
Caltech CS 1: Fall 2010 Tests that apply to a particular module are usually called unit tests They test the code in a module in isolation to all other code These are the easiest tests to write
Background image of page 8
Caltech CS 1: Fall 2010 Tests that check if multiple modules work properly in combination are usually called integration tests These are more complicated, and we won't cover them in this course But with good enough unit tests, you can still eliminate huge numbers of bugs!
Background image of page 9

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

View Full DocumentRight Arrow Icon
Caltech CS 1: Fall 2010 Testing code in Python is easy With the nose module, it's really easy! Need to understand: the assert statement if __name__ == '__main__': . .. How to write individual tests How to write and run test modules
Background image of page 10
Caltech CS 1: Fall 2010 assert is a special Python statement which is useful for both debugging and testing It tests whether a boolean expression is True or False If it's True , nothing happens If it's False , an error occurs
Background image of page 11

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

View Full DocumentRight Arrow Icon
Caltech CS 1: Fall 2010 Examples: >>> assert True >>> assert False AssertionError >>> assert 1 + 1 == 2 >>> assert 2 + 2 == 5 AssertionError
Background image of page 12
Caltech CS 1: Fall 2010 Can also add a message to an assert : >>> assert 1 + 1 == 2, 'addition test 1' >>> assert 2 + 2 == 5, 'addition test 2' AssertionError: addition test 2 This is useful as documentation
Background image of page 13

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

View Full DocumentRight Arrow Icon
assert is often used as a way to make functions self-checking: def square_root(x): # code to compute the square root root = . .. assert (abs(x - root * root) < 0.001)
Background image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/22/2011 for the course CS 1 taught by Professor Pinkston,d during the Fall '08 term at Caltech.

Page1 / 74

lecture09 - Lecture 9: October 25, 2010 Testing and...

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

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