Class Notes (835,600)
Canada (509,275)
CSC108H1 (113)
Lecture

november 09 notes

1 Page
59 Views
Unlock Document

Department
Computer Science
Course
CSC108H1
Professor
Michelle Craig
Semester
Fall

Description
 Carrying on w/ testing o Write your header and doctstring o Plan your test cases  most important o Implement your code o Implement your tests  Example function 1. def insert_after (L, n1, n2): 2. ‘’’L is a list of ints, n1 and n2 are ints. After each occurrence of n1 in L, insert the 3. int n2.’’’ 4. # rest of function o good test casese/examples:  Lists that has/doesn’t have n1; empty list; 1 itemed list, small # of items, large # of items  Occurrence of n1: 0, once, small # of times, large # of times, first item of list, last item of list, middle item of list, If n1 = n2  L = [1, 2, 3, 4] n1 = 1 n2 = 1 expected output: [ 1, 1, 2, 3, 4]  L = [1, 2, 3, 4] n1 = 99 n2 = 0 expected output: [ 7, 5, 2, 4, 9, 14]  L = [7, 5, 2, 9, 14] n1 = 2 n2 = 4 expected output: [ 7, 5, 99, 5, 99, 9, 14]  L = [7, 5, 5, 9, 14] n1 = 5 n2 = 99 expected output: [7, 5, 99, 5, 99, 9, 14]  L = [17, 9, 8, 9, 4, 12]n1 = 17 n2 = -1 expected output: [17, -1, 9, 8, 9, 4, 12]  L = [] n1 = 7 n2 = 14 expected output: []  L = [3, 4, 5] n1 = 8 n2 = -2 expected output: [3, 4, 5]  Implementing test cases o Use a program to help be organed and efficient about testing o Nose is a module written for this  Testing w/ nose – suppose you are testing module called mod. Then create a new module called test_mod and in it: o Import nose and mod o Write a function for each test case o Name each function test_condition where condition describes the test case ex. test_empty_dict o In the main, have the single line: >>> nose.runmodule() o It will cause each test function to be called  The test functions – in each test function: o 1. Set up variables, if necessary o 2. call the function being tested o 3. Make one assetion: asset value1 ==
More Less

Related notes for CSC108H1

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit