COMP 304 Assignment 1 -- Solution


CellFormula

The requirements for this assignment are described on a separate page.

Implementation

Our solution is in file FHierarchy.py. The code is well-documented, and respects the proposed design. A few notes:

Testing

The testing suite for our code is TestTree.py. We define no test suite, so by default all the methods that will be executed are those whose name starts with text. For your test to be readable, it is important to put an informative documentation string in each test.

There is a one-to-one correspondence between the requirements and the tests.

Below is a trace of a succesful series of tests.

$python2.2 TestTree.py -v

CellRef shall raise Type and Value errors on bad inputs ... ok
An attempt to instantiate FNode shall raise a NotImplementedError ... ok
Inverse(Sum,Product) shall raise Type and Value errors on bad inputs ... ok
Number shall raise Type errors on bad inputs ... ok
An attempt to instantiate Operator shall raise a NotImplementedError ... ok
Sum and Product shall raise Type and Value errors on bad inputs ... ok
x=Number(n) ; x.evaluate() is x ... ok
Number(n).getValue == n ... ok
InverseProduct(n)*n == 1 for all n ... ok
InverseProduct(InverseProduct(n)) == n for all n ... ok
InverseSum(InverseSum(n)) == n for all n ... ok
InverseSum(n) + n == 0 for all n ... ok
Any concrete evaluate function shall return an instance of a Number ... ok
Any evaluation of a tree shall return the expected answer ... ok

----------------------------------------------------------------------
Ran 14 tests in 7.068s

OK