Saint Louis University |
Computer Science 150
|
Dept. of Math & Computer Science |
The goal of this assignment is to add extra functionality to our previously defined Television class. In particular, we wish to add support for maintaining and manipulating a list of favorite channels.
For this assignment you must work individually in regard to the design and implementation of your project.
Please make sure you adhere to the policies on academic integrity in this regard.
From the user's perspective, the state of the television should include a list of select channels which we refer to as favorites. Internally, the favorites list can easily be maintained as an instance variable of type list. Your redesigned television should support the following three additional behaviors:
addFavorite()
When called, the television's current
channel should be added to the list of favorites, if it is not
already present on that list.
removeFavorite()
When called, the television's current
channel should be removed from the list of favorites, if it had been
on that list.
jumpFavorite()
When called, this behavior should have
the end result of changing the current channel to a particular
channel from the favorite list. Specifically, that favorite which
is the next higher in value when compared to the current channel
should be chosen. If no favorites exists which are higher in value
than the current channel, the lowest of the favorite channels should
be used. To inform the user of the new setting, this function
should provide the chosen channel number as a return value.
In the case that the favorite list is empty, the channel should not be changed, and nothing need be returned.
Take care to ensure that jumpFavorite() properly maintains the prevChannel attribute for use in conjunction with subsequent calls to jumpPrevChannel().
We will provide you with our previously developed Television.py code. You may make your own personal copy of it by typing the following command from a terminal on turing:
cp /home/home0/goldwasser/lib/Television.py .
With this assignment, we would like to start enforcing two good practices in software engineering, namely documenting your work and testing your work. Python offers a conventional form of support for each of these efforts.
Providing Documentation
Python supports a special form of documentation for each class and
method you define, known as a docstring. Specifically, if the
very first line of any class definition or within the body of any
method is a string literal, python interprets that string as a form of
documentation. It can be examined by a user of an object by typing
help(obj) for a given obj, or help(obj.method) for a
given method supported by that obj.
(See Zelle pp. 315-317 for further discussion).
You will find that our original Television.py code already contains docstrings describing the existing functionality. You are required to provide sufficient docstrings for the three new functions you are writing.
Unit Testing
Locating and correcting mistakes becomes quite challenging on large
software projects. One approach to handling this complexity is to
individually test smaller portions of code. Therefore, for any class
we write, it makes sense to provide some sample sequence of
instructions to test the various behaviors and ideally demonstrate the
correctness for a variety of settings. It becomes most convenient to
write such test code in the same file as the original class
definition. Of course, when we later want to use the class in a
larger context, we need to import the class definition but presumably
do not want to execute any of the test code.
The conventional way we will accomplish this in Python is by writing a separate testing block starting with a command:
Such a test block should be placed at the end of the source file, following the actual class defintiions.if __name__ == '__main__': # perform sequence of tests...
You will find that our original Television.py code already contains (brief) unit testing of the existing functionality. You should extend such tests to adequately demonstrate your new functionality. Make sure not just to test one specific case, but a broad variety of scenarios and special cases which may arise.
In the end, you should submit two files: your modified version of Television.py and a readme text file briefly discussing your efforts.
Please see details regarding the submission process from the general programming web page, as well as a discussion of the late policy.
You will be graded based upon the correctness of your added functionality regarding the favorites list, as well as on your documentation and testing of the new functionality.
To be announced...