COMP 304B Object-Oriented Software Design -- Assignment 1\\\ Due date: Wednesday January 29, 2002 before 23:55

COMP 304B Object-Oriented Software Design - Assignment 1
  Due date: Wednesday January 29, 2002 before 23:55

 

[printable version of this document (pdf)]| [COMP 304B Home]


Practical information

Goals

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

You will test and implement classes to represent formulas used in spreadsheet cells. This is the very first step towards a simple spreadsheet application.

For testing, you will use the unittest framework in Python.

Your assignment should clearly present:

  1. The tests corresponding to the requirements listed below.
  2. An implementation of the design given below.
  3. The results of the tests on your implementation.

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

Design

In Figure 1, the design for this assignment is given in the form of a UML Class Diagram.

design.png

Figure 1: The spreadsheet cell formula node UML Class Diagram

You must test and implement all classes. The structure of the classes is given in the design. You must adhere strictly to the given design.

Note how the design specifies describe the abstract class FNode with its concrete realizations in the form of sub-classes. The Operator class is linked to the FNode class denoting the fact that an Operator node refers to its children. Actually, the design already specifies that the reference to the children will be through an attribute _children of type List_Of_FNodes.

Although a Number can be instantiated with either an Integer or a Float, internally, storage is as a Float. Furthermore, you are required to perform all arithmetic on Floats only. Using Integer arithmetic would complicate matters when dealing with division.
A side-effect of using Floats is that 1/1/x is usually not equal to x. This is due to the internal representation of floating point numbers and errors made during calculations. Hence, equality of two floating point numbers a and b will have to be tested by checking whether |a-b| < e with e a tolerance.

You will implement the evaluate() method for all classes except CellRef. The latter will only be possible at the level of the overall spreadsheet (in a later assignment). Note how evaluate() does not return a Float, but in true object-oriented fashion, returns an object, instance of the Number class !

Requirements

1. Test for Success

  1. Calling any concrete evaluate method must return an instance of class Number.
  2. Build some tree data structures containing instances of classes Operator and Number (ignore class CellRef for now). Make sure ``evaluating'' the root node returns the expected result. For instance, if a is the root node of a tree representing the operation 2+4-5, make sure that a.evaluate.getValue() returns 1.

2. Test for Failure

3. Test for Sanity

  1. Do some sanity checks with classes InverseSum and InverseProduct. That is (for instance),
    x + (-x)
    =
    0,
    - (-x)
    =
    x.
  2. Make sure the value returned by Number.getValue is consistent with the value stored in the attribute Number.__value.
  3. Make sure the method Number.evaluate returns the caller object itself (use Python's is operator as in a is b).

References




Translated from TEX by TTH, version 3.02 (minor customizations by HV). On 16 Jan 2003, 21:46.