Assignment 12 (The last one!)

Problems

  1. Draw a UML class diagram for the following code (it will be a little thin in places because the code is not complete). You can do this by hand or using software (for example MS Visio or Gliffy), it's up to you.

    class Date:
        def __init__(...):
            self.year = ... # Of type int.
            self.month = ... # Of type str.
            self.day = ... # Of type int.
        ...
    class CourseList:
        ...
    class Person:
        def __init__(...):
            self.birthdate = ... # Of type Date.
            self.id = ... # Of type int.
        def eat(...):
            ...
        def sleep(...):
            ...
    class Student(Person):
        def __init__(...):
            self.courses = ... # Of type CourseList.
        def study(...):
            ...
    class Employee(Person):
        def __init__(...):
            self.salary = ... # Of type float.
    class Instructor(Employee):
        def __init__(...):
            self.courses = ... # Of type CourseList.
        def teach(...):
            ...
    class Administrator(Employee):
        def administer(...):
            ...
  2. Draw a UML class diagram for your final Hunt the Wumpus program. You can do this by hand or using software (for example MS Visio or Gliffy), it's up to you.

  3. Add a docstring containing a sufficient set of doctest tests and a call to run those tests to the module below,

    # ScrabbleScoring.py
    LETTER_VALUES = {'A':1, 'B':3, 'C':3, 'D':2, 'E':1, 'F':4, 'G':2,
                     'H':4, 'I':1, 'J':8, 'K':5, 'L':1, 'M':3, 'N':1,
                     'O':1, 'P':3, 'Q':10, 'R':1, 'S':1, 'T':1, 'U':1,
                     'V':4, 'W':4, 'X':8, 'Y':4, 'Z':10}
    def scrabble_value(s):
       'Returns the Scrabble score for the letters in the string s.'
        total_value = 0
        for letter in s:
            total_value = total_value + LETTER_VALUES[letter]
        return total_value
  4. Replace the code below that tests the function isStraight with an equivalent set of doctests. Fill in the body of isStraight and run the tests on it.

    # is_straight_doctest.py
    def isStraight(hand):
        pass
    if __name__ == '__main__':
        # TEST_HANDS is a list containing the hands of cards to use in testing
        # the function isStraight, and the correct result for each hand.
        # Note that not all hands have five cards, and some are straights,
        # while some are not.
        TEST_HANDS = [
            [[ 1, 2, 3, 4, 5 ], True],
            [[ 5, 4, 3, 2, 1 ], True],
            [[ 14, 0, 28, 42, 4 ], True],
            [[ 1, 2, 3, 4, 5, 6 ], True],
            [[ 5 ], True],
            [[ 1, 2, 2, 4, 5 ], False],
            [[ 1, 2, 2, 5, 5 ], False],
            [[ 1, 3, 5, 7, 9 ], False]
        ]
        print 'Testing isStraight ... '
        # Loop through the list of TEST_HANDS, to test each sample hand.
        for test in TEST_HANDS:
            # If the function isStraight does not return the correct
            # result...
            if isStraight(test[0]) != test[1]:
                # ... display an error message
                print 'isStraight fails on', test[0]

Logistics