CSC108H1 Study Guide - Final Guide: Memory Address, Init, Linear Search

231 views35 pages
28 Feb 2018
School
Course
yifanyang and 39659 others unlocked
CSC108H1 Full Course Notes
21
CSC108H1 Full Course Notes
Verified Note
21 documents

Document Summary

Unit test allows us to write test separately from function being tested: don"t want to write all tests in docstrings -> overwhelms it. Ex: for the following code, write a unit test. The unit test can be written as: import unittest: to do unittest famework. Def test_divisors_example_1: need to begin with the name test for it method to be tested. For each example, write a separate method. Unittest. main(exit = false) looks through all the test case subclasses (defined by what is written under class. Testdivisiors(unittest. testcase):) in current module for methods that begin with test. E. g. def test_divisors_example_2(self): calls each of them and reports unexpected results. We run this unittest and this is the result in the python shell: If error is shown: f or e instead of . Can run many tests without affecting readability of code. Typically write 1 testcase subclass for each function we want to test. Write 1 test method for each function call.