This assignment will make you familiar with unit testing and with object-oriented programming in Python.
Your assignment solution should clearly present:
Upload all source and result files to WebCT and provide links to all of them from your index.html file.
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.
For the assignment to be most effective, please complete the tasks in order.
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.
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.
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.
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.
You can download the Point, Vector, Force and Mass class here.