CSC 148 H1, Winter 2013

Exercise 3

Due: before noon on Friday 1 February 2013

Pre-marking: first run at noon on Wed. 30 Jan.; second run at noon on Thu. 31 Jan.

There are two parts to this exercise. For each part, there is a single file you must submit — make sure that you read the submission instructions carefully!

This exercise is longer than the first two, but don't panic! A lot of the code is "repeated", as you will see. Just take it one step at a time...

Important general advice

BEFORE you begin coding, make sure that you understand everything in this handout. Remember that the point of these exercises is not to get a "working" program by any means necessary — it is to ensure that you understand how to write the desired code. If you succeed in writing something that works but you do not understand why, then you have failed, no matter what grade you receive!

In particular, if there is something you do not quite understand, please, for your own sake, take the time to read the online textbook and the course notes and readings, do some searching on Google and ask on the course forum or during office hours to make sure you find out. Keep in mind that the lab for this week will cover related material, so taking the time to understand the lab (and ask questions of other students and of your TA) should provide good preparation for this exercise!

Part A

Remember that in Python, a class is allowed to have more than one parent class. For example, to make class C be a sub-class of both A and B, you would define class C as follows:

    ...code for classes A and B is up here...
    class C(A, B):
        ...code for class C goes here...

Submit a file "" that defines the following classes to represent various geometrical shapes. Think carefully about the relationships between the different classes: some of these really should be sub-classes of each other.

Part B

Submit a file that contains a suite of unit tests for the classes you wrote in Part A. Your file must contain the following subclassses of unittest.TestCase (one for each one of the classes in Part A):

Each of the test classes above must contain at least the following methods (the strange names were chosen to ensure that the test cases are run in a particular order):

Don't forget to put the statement unittest.main() under the  if __name__ == '__main__':  block at the bottom of your file, to execute the test cases. Now, you can run your test cases yourself to verify your Part A. (But don't worry: we will also run our own suite of test cases on your!)