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.
def __init__(self, x, y): """ Point's constructor. Takes an x and a y coordinate. @param x: the x coordinate of this point. @param y: the y coordinate of this point. @type x: int, float @type y: int, float """ def getX(self): """ Return the point's x coordinate @rtype: float """ def setX(self, x): """ Set the point's x coordinate @param x: the value to set as this point's x coordinate. @type x: int, float """ def getY(self): """ Return the point's y coordinate @rtype: float """ def setY(self, y): """ Set the point's y coordinate @param y: the value to set as this point's y coordinate. @type y: int, float """ def clone(self): """ Returns a copy of this object. @rtype: L{Point} """ def __str__(self): """ Overloading string representation to (x, y) """
def __init__(self, name): """ Trajectory's constructor. @param name: the trajectory's name @type name: str """ def getName(self): """ Returns the trajectory's name. @rtype: str """ def setName(self, name): """ Set the trajectory's name. @param name: the value to which to set the trajectory's name. @type name: str """ def getPoints(self): """ Returns the trajectory's points. @rtype: list[L{Point}] """ def getPoint(self, x, y): """ Returns the first instance of a point in this trajectory which has the given coordinates. @param x: the x coordinate of the point to retrieve. @param y: the y coordinate of the point to retrieve. @type x: int, float @type y: int, float @rtype: L{Point} """ def addPoint(self, x, y): """ Adds a point to this trajectory, according to given coordinates, and returns it. @param x: the x coordinate of the point to add to this trajectory. @param y: the y coordinate of the point to add to this trajectory. @type x: int, float @type y: int, float @rtype: L{Point} """ def removePoint(self, x, y): """ Removes a point from this trajectory, according to given coordinates, and returns it. @param x: the x coordinate of the point to remove from this trajectory. @param y: the y coordinate of the point to remove from this trajectory. @type x: int, float @type y: int, float @rtype: L{Point} """ def modifyPoint(self, x, y, newX, newY): """ Modifies a point in this trajectory, according to given coordinates, and returns the modified point. @param x: the x coordinate of the point to modify. @param y: the y coordinate of the point to modify. @param newX: the new x coordinate to give to the point to modify. @param newY: the new y coordinate to give to the point to modify. @type x: int, float @type y: int, float @type newX: int, float @type newY: int, float @rtype: L{Point} """ def clear(self): """ Removes all the points from this trajectory. """ def clone(self): """ Returns a copy of this object. @rtype: L{Trajectory} """ def __str__(self): """ Overloading string representation to (x1, y1) .. (xn, yn) """
You must come up with a reasonable (don't go overboard !) list of tests (mention their type!) to check the correct implementation of the above classes/methods. Note that you will have to define the requirements yourself based on the comment given in the classes above.
Note that you will need to do type checking of method arguments as Python does not do static type checking.
These test should be implemented in a file testsuite.py using the PyUnit testing framework.