def checker():
    """
    Test for the update_word_pattern function
    Prints a result for all test
    :return: Boolean value, if the test succeeded
    """
    flag = True

    if update_word_pattern("word", "__r_", 'h') != "__r_":
        flag = False

    elif update_word_pattern("aaaa", "____", 'a') != "aaaa":
        flag = False

    elif update_word_pattern("nnxaxsfx", "___a____", 'x') != "__xax__x":
        flag = False

    elif update_word_pattern("abcde", "a_c_e", 'c') != "a_c_e":
        flag = False

    if flag:  # Check if everything is succeeded
        print('Function "update_word_pattern" test success')
    else:
        print('Function "update_word_pattern" test fail')

    return flag
def check_fu_update_word_pattern():
    """This function check the function update_word_pattern"""

    flag = [False, False, False, False, False]
    if update_word_pattern("hello", "_____", "l") == "__ll_":
        flag[0] = True

    if update_word_pattern("h", "_", "l") == "_":
        flag[1] = True

    if update_word_pattern("python", "______", "l") == "______":
        flag[2] = True

    if update_word_pattern("python", "______", "n") == "_____n":
        flag[3] = True

    if update_word_pattern("python", "python", "n") == "python":
        flag[4] = True

    if all(flag):
        print("Test succeed")
        return True
    else:
        print("Test failed")
        return False
Esempio n. 3
0
def test_for_update_word_pattern():
    """A function that tests the function update_word_pattern from hangman.py.
    It runs 4 extrema inputs and if all the outputs is as expected the test
    will print 'Function 'update_word_pattern' test success' and returns True,
    if the test failed it will print 'Function 'update_word_pattern' test fail'
    and returns False"""
    counter = 0
    new_pattern = update_word_pattern("anachronistic", "a_a__________", "c")
    if new_pattern == "a_ac________c":
        counter += 1
    new_pattern = update_word_pattern("panacea", "p_n_ce_", "a")
    if new_pattern == "panacea":
        counter += 1
    new_pattern = update_word_pattern("python", "__th__", "w")
    if new_pattern == "__th__":
        counter += 1
    new_pattern = update_word_pattern("avadakedavra", "_v___k______", "a")
    if new_pattern == "ava_ak__a__a":
        counter += 1
    if counter == 4:
        print("Function 'update_word_pattern' test success")
        return True
    else:
        print("Function 'update_word_pattern' test fail")
        return False
def test_update_word_pattern():
    """a function that tests the function "update_word_pattern" in hangman.py."""
    if (update_word_pattern('revive', '______', 'e') == '_e___e') and\
    (update_word_pattern('revive', '_e___e', 'e') == '_e___e') and \
    (update_word_pattern('fffff','_____','f') == 'fffff') and\
    (update_word_pattern('victory', '_______', 'b') == '_______'):
        print('Function "update_word_pattern" test success')
        return True
    print('Function "update_word_pattern" test fail')
    return False
def check_update_word_pattern():
    """This function test the check&update function"""

    # checks if pattern updated in multiple indexes if needed
    if update_word_pattern("door", '____', 'o') == '_oo_':
        # make sure pattern doesnt changed when the letter isnt in the word
        if update_word_pattern('apple', '_____', 'z') == '_____':
            # make sure pattern doesnt changed when the chosen letter already uncovered
            if update_word_pattern('b', 'b__k', 'b') == 'b__k':
                # still works when the pattern consist of single letter
                if update_word_pattern('xxx', '___', 'x') == 'xxx':
                    print("The function passed the test")
                    return True

    print("There was a problem , fuction faild")
    return False
def check_update_word_pattern():
    """
    Checks the update_word_pattern
    for 4 different inputs.
    :return:
    """

    valid = True

    if update_word_pattern('banana', 'b_____', 'n') != 'b_n_n_':
        valid = False

    if update_word_pattern('banana', '______', 'f') != '______':
        valid = False

    if update_word_pattern('', '', 'n') != '':
        valid = False

    if update_word_pattern('aaa', '___', 'a') != 'aaa':
        valid = False

    return valid
Esempio n. 7
0
def test_update_word_pattern():
    """Function that test several inputs for the
    function "update_word_pattern from hangman.py"""
    words = ['hello', 'hello', 'hello', 'hello']
    patterns = ['_____', 'hell_', 'hell_', 'h____']
    letters = ['h', 'h', 'o', 'd']
    results = ["h____", "hell_", "hello", "h____"]
    for i in range(len(words)):
        if update_word_pattern(words[i], patterns[i],
                               letters[i]) != results[i]:
            print("Test failed")
            return False
    print("Test done!")
    return True
def update_word_pattern_checker():
    flag = True
    """
    the function checks the function update word pattern in 4 different
    edge situations.
    :return: if all tests are correct. True will return. If one or more of
    the tests fail, the function will return False.
    """
    if update_word_pattern('cooperate','c__p_rat_','o') != 'coop_rat_':
        flag = False
        print('test 1 has failed')
    if update_word_pattern('pattern','_______','t') != '__tt___':
        flag = False
        print('test 2 has failed')
    if update_word_pattern('coop'+'erate','c__p_rat_','o') != 'coop_rat_':
        flag = False
        print('test 3 has failed')
    if update_word_pattern('hangman','hangman','a') != 'hangman':
        flag = False
        print('test 4 has failed')
    else:
        print('Tests passed successfully!')
    return flag
def test_updtae_word_pattern():
    """testing update word pattern"""
    check_list = [['aaa', '___', 'a'], ['lol', '___', 'a'],
                  ['bbq', '__q', 'b'],['booob','_____','b']]
    answer_list = ['aaa', '___', 'bbq','b___b']
    count = 0  # for counting right answers should be 4
    # run over check list and check if the the function return the answer list
    for i in range(len(check_list)):
        if update_word_pattern(check_list[i][0], check_list[i][1],
                               check_list[i][2]) == answer_list[i]:
            count += 1
    if count == 4:
        print("test success")
        return True
    else:
        print('test failed')
        return False
Esempio n. 10
0
def test_update_pattern():
    input1 = ("coffee", "______", "f")
    pattern1 = "__ff__"
    input2 = ("tea", "___", "a")
    pattern2 = "__a"
    input3 = ("cookie", "coo_ie", "k")
    pattern3 = "cookie"
    input4 = ("zzzzzz", "______", "z")
    pattern4 = "zzzzzz"
    input_lst = [input1, input2, input3, input4]
    pattern_lst = [pattern1, pattern2, pattern3, pattern4]

    for test_input_index, test_input in enumerate(input_lst):
        word, pattern, letter = test_input
        if update_word_pattern(word, pattern, letter) != pattern_lst[test_input_index]:
            print("function \"update_word_pattern\" test FAIL")
            return False
    print("function \"update_word_pattern\" test SUCCESS")
    return True