CS 204: Software Design

Unit test construction with unittest/PyUnit

Do this project without a partner

This assignment will introduce you to the construction of unit tests using PyUnit (also known as the unittest module).

Your process for this assignment will be, roughly:

  1. Design the functional interfaces for the program. (Congratulations! You're already done with this step. See below.)

  2. Come up with a collection of test cases for the program.

  3. Get an introduction to PyUnit/unittest from the official unittest documentation and/or any of the many unittest tutorials (looks like somebody even put together a video tutorial).

  4. Implement the test cases in unittest.TestCase form.

  5. Implement the program. Make sure the tests pass.

  6. Swap test cases with one or more classmates and run their tests on your program.

  7. Write a short report describing whether the test cases helped you find bugs, how your code ran with somebody else's tests, etc.

The program

Your program is going to be a small utility that performs word identification for games like Text Twist. In this game and its variants (both digital and paper & pencil), you are presented with a word or phrase and asked to find all the words that can be spelled with letters from the word. For example, if the given phrase is "charging moose", you might generate the list of words "rag", "ram", "moo", "gracing", etc. Like any tool worth creating, your program will be usable for good (e.g. as the "AI" part of the implementation of Text Twist or a related game) or evil (e.g. to help you cheat at Text Twist).

To support the sharing of test cases, you will need to write your program to include a class called WordFinder, with at least the following pair of methods:

class WordFinder:
    def __init__(self, legalWordFileName):
        ''' The word file, which you may assume to be encoded in UTF-8,
            consists of one lower-case word per line. These words will be
            the complete list of legal words for this instance of WordFinder. '''
        pass

    def getWordsInString(self, s):
        ''' Returns a list of Unicode strings, sorted using the built-in Python
            list sort() method, representing all the legal words found in the
            specified string. Note that letters found in s may only be used once
            apiece in the discovered words. For example, if s = "proper", the
            resulting word list should include "pop" and "err", but not "peer". ''' 
        pass

    def getWordsInStringWithRepetitionAllowed(self, s):
        ''' Returns a list of Unicode strings, sorted using the built-in Python
            list sort() method, representing all the legal words found in the
            specified string. Letters found in s may be used once as many times
            as needed in the discovered words. For example, if s = "proper", the
            resulting word list should include "popper", "error", "peer", etc. ''' 
        pass

What to hand in

One more thing...

Here's a big file of English words in case you want to use it.