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 2.6.
The grading scheme is as follows:

Upload all source and result files to WebCT and provide links to all of them from your index.html file.
Your source code should consist of three distinct modules: Task1.py, Task2.py, and Task3.py.

Assignment

Task 1: Column Name Conversion

Suppose you have to design an spreadsheet application. Your team is assigned to develop a utility library that will be used in the project. Your first task is to implement a class named ColumnNameConversionUtility which provides conversion of column names to integers and vice-versa.

  def columnNameToColumnNumber(self, columnName):
    """
      Transform strings used as cell column names (e.g., "A" in the cell reference "A5") to integers (for efficiency reasons).
      Requirements:
       - "A" is converted to 0
       - "Z" is converted to 25
       - "AA" follows "Z" and is converted to 26, and so on
       - only strings in the range "A" to "ZZZZ" are accepted
       - column names should be upper case
       - in case of an improper columnName input, the InvalidColumnName exception should be raised
    """

  def columnNumberToColumnName(self, columnNumber):
    """
      Requirements:
       - inverse of columnNameToColumnNumber
       - only integer numbers in the range 0 .. columnNameToColumnNumber("ZZZZ") are allowed as input
       - output must be upper case strings: in case of an improper columnNumber input, the InvalidColumnNumber exception should be raised
    """
  1. Implement the conversion routines corresponding to the requirements above in a class ColumnNameConversionUtility.
  2. Provide appropriate tests (for success, failure, and sanity) for this utility class.

Task 2: Points, Vectors, and Masses

Suppose you have to develop a tool that allows you to simulate the movement of masses in a 2D environment. For your second task, you will be working on the core classes of the simulator, namely, the point, vector, force and mass classes. You can download the Point, Vector, Force and Mass classes here.

  1. Implement 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.
  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.
  3. Implement the following functions in the Vector class : dotProduct, crossProduct, normalize. Also, implement the equals function in the Force and Mass classes. You can use the unit tests from question 1 to help you implement these functions (as done in XP). Correction: as the cross product of 2 vectors does not exist in 2D, then you cannot actually compute it. You can either throw an exception (if the input vectors do not have sufficient dimensions) or not implement it at all. In any case, it will not be counted in the grading.

Task 3: Metro Ticket Distribution Machine

Suppose you are to design a ticket distributor for the metro of Montreal. In the software development process, the use case for purchasing tickets PurchaseTicket is already written and accepted by the client (the STM?). It describes a "normal" interaction between a Passenger and the Distibutor:

 Use case name		PurchaseTicket
Entry condition		The Passenger is standing in front of the ticket distributor.
			The Passenger has sufficient money to purchase a ticket.
Flow of events		1. Passenger selects a number of zones to be traveled. If he presses multiple zone buttons, only the last button pressed is considered by the Distributor.
			2. The Distributor displays the amount due.
			3. The Passenger inserts money.
			4. If the Passenger selects a new zone before inserting sufficient money, the Distributor returns all coins and bills already inserted.
			5. If Passenger inserted more money than the amount due, the Distributor returns excess change.
			6. The Distributor issues the ticket.
			7. The Passenger picks up the change and the ticket.
Exit condition		The Passenger has picked up the selected ticket.
  1. Describe at least 3 boundary cases where features of the Distibutor are likely to fail.
  2. Provide a test case for this use case that covers the special cases you have identified. Your answer can either be written in pseudocode or in formal plain english. If you choose the latter option, follow the same template as the use case. (NO IMPLEMENTATION IS NEEDED!)

References


Eugene Syriani Winter Term 2010.