Assignment 11
Problems
-
Split into groups of two and draw a UML class diagram for the updated version of Hunt the Wumpus (with the Hazard class). The diagram should include both the is-a and has-a relationships. If your added feature is a class include it in the diagram. You can do this by hand or using software (for example MS Visio or Gliffy), it's up to you. Submit you UML document.
-
Add a docstring containing a sufficient set of doctest tests and a call to run those tests to the module below. Write some of your own tests and then ask an AI (chatGPT) to write some additional doctests. Which set do you feel is more thorough/appropriate for our function?
# 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':2, '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 -
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. You can fill it in with your assignment 5 or you can see how AI does and run your tests on that.
# 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
-
Use the following naming scheme for your program files:
aassignment#pproblem#yourname.py. So your code for the the first problen of this assignment will be nameda11p1bob.py(adjusted obviously to use your name). -
Please submit your
.pyfile to the Moodle dropbox.