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:
Design the functional interfaces for the program. (Congratulations! You're already done with this step. See below.)
Come up with a collection of test cases for the program.
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).
Implement the test cases in unittest.TestCase form.
Implement the program. Make sure the tests pass.
Swap test cases with one or more classmates and run their tests on your program.
Write a short report describing whether the test cases helped you find bugs, how your code ran with somebody else's tests, etc.
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
Everything in a sub-directory called unittest in your Courses Hand-in directory.
Your WordFinder class, in a file called wordfinder.py. (Feel free to put anything you want inside "if __name__ == '__main__'" to help you debug your code, but you might find it just as helpful to use your unit tests directly while debugging.)
Your unit tests in wordfindertests.py.
Any supporting files (e.g. short legal word files) your code requires.
A short readme.txt describing your experience trading unit tests with a classmate.
Here's a big file of English words in case you want to use it.