Ejemplo n.º 1
0
def get_computer_guess(view):
    """(str) -> str

    Return a line from the file named pf.DATA_FILE that contains string that
    could be represented by view, or, if no such line exists, the empty
    string.

    This function and get_player_guess must have the same type contract.
    """

    data_file = open(pf.DATA_FILE)
    for line in data_file:
        if pf.is_match(line.strip(), view):
            return line.strip()

    return ''
Ejemplo n.º 2
0
       .format(type(result))

# Type check pf.guess_letter
result = pf.guess_letter('bcd', pf.HARD)
assert isinstance(result, str), \
       """pf.guess_letter should return a str, but returned {0}.""" \
       .format(type(result))

# Type check pf.half_revealed
result = pf.half_revealed('a^^l^')
assert isinstance(result, bool), \
       """pf.half_revealed should return a bool, but returned {0}.""" \
       .format(type(result))

# Type check pf.is_match
result = pf.is_match('apple', 'a^^l^')
assert isinstance(result, bool), \
       """pf.is_match should return a bool, but returned {0}.""" \
       .format(type(result))

# Get the final values of the constants
constants_after = [pf.DATA_FILE, pf.HIDDEN, pf.VOWEL_PRICE, 
                   pf.CONSONANT_BONUS, pf.HUMAN, pf.HUMAN_HUMAN, 
                   pf.HUMAN_COMPUTER, pf.EASY, pf.HARD, pf.PLAYER_ONE,
                   pf.PLAYER_TWO, pf.CONSONANTS, pf.VOWELS, pf.CONSONANT,
                   pf.VOWEL, pf.SOLVE, pf.QUIT, pf.PRIORITY_CONSONANTS]

# Check whether the constants are unchanged.
assert constants_before == constants_after, \
       """Your function(s) modified the value of a constant(s). Edit your code
        so that the values of constants are unchanged by your functions."""