COMP 304B Object-Oriented Software Design -- Assignment 1

COMP 304B Object-Oriented Software Design - Assignment 1

Practical information

Goals

This assignment will make you familiar with unit testing and with object-oriented programming in Python.

Your assignment solution should clearly present:

  1. The tests corresponding to the requirements listed below.
  2. Your implementations and improvements on the provided classes.
  3. The results of the tests on your implementation.

Upload all source and result files to WebCT and provide links to all of them from your index.html file.

Specifications

This assignment is Part 1 of a series of assignments. Ultimately (by Assignment 6), you will have developed a tool that allows you to simulate the movement of masses in a 2D environment.

In this assignment, you will be working on the core classes of the simulator, namely, the point, vector, force and mass classes.

Tasks

For the assignment to be most effective, please complete the tasks in order.

Task 1

Implements a reasonable number of unit tests for the Point, Vector, Force and Mass classes. Each function should be tested for success and failure. Tests for sanity should be added where appropriate. Note that you will need to verify type checking of method arguments as Python does not do static type checking.

Task 2

Fix any bug I might have inserted in the code. These bugs are typos, usually involving one or two characters. If a method does something mathematically impossible (division by zero, for example), it should throw a ArithmeticError exception. You will need to add those checks and test for them.

Task 3

Implement the following functions in the Vector class : dotProduct, unit. Also, implement the equals function in the Force and Mass classes. You can use the unit tests from Task 1 to help you implement these functions (as done in XP Programming). You don't need to implement the crossProduct method in the Vector class.

Task 4

The Force class is poorly implemented. When adding two forces, the class will simply store the attributes of both forces. This means that the total force must be calcuted using the getMagnitudeAtTime function everytime it is needed. Rewrite the Force class so that the total force is calculated when the Force object is created. Thus, the getMagnitudeAtTime function should return in constant time. Again, you can use the unit tests from Task 1 to help you determine when you have successfully re-written the Force class.

Files

You can download the Point, Vector, Force and Mass class here.


Alexandre Denault, January 2006.