示例#1
0
def test_words_containing():
    """Return True/False if the test of words_containing passes/fails"""
    # Test 1 make sure it matches upper and lower case
    sentence = "The cow jumped over the moon"
    result = words_containing(sentence, 't')
    expected = ['The', 'the']
    if result != expected:
        return False

    # Test 2 make sure it gets all the words
    expected = ['cow', 'over', 'moon']
    result = words_containing(sentence, 'o')
    if result != expected:
        return False

    # Test 3 Return empty string if no matches
    expected = []
    result = words_containing(sentence, 'x')
    if result != expected:
        return False

    # Test 4 No error if sentence is empty
    if words_containing('', 'a') != []:
        return False

    # All tests passed if we get here
    return True
示例#2
0
def test_words_containing():
    """Return True/False if the test of words_containing passes/fails"""
    sentence = "Anyone who has never made a mistake has never tried anything"
    sentence2 = "The cow jumped over the moon"
    new_list = words_containing(sentence, 'a')
    new_list2 = words_containing(sentence, 'x')
    new_list3 = words_containing('', 'x')
    new_list4 = words_containing(sentence2, 't')

    if new_list == [
            'Anyone', 'has', 'made', 'a', 'mistake', 'has', 'anything'
    ]:
        if new_list2 == []:
            if new_list3 == []:
                if new_list4 == ['The', 'the']:
                    return True
    else:
        return False
示例#3
0
def test_words_containing():
    """Return True or False if the test of len_safe passes/fails"""
    TEST_PASSED = True  # Assume the test will succeed
    SENTENCE_TEST = '''Anyone who has never made
     a mistake has never tried anything new'''
    result = words_containing(SENTENCE_TEST, 'a')
    if result != ['Anyone', 'has', 'made', 'a', 'mistake', 'has', 'anything']:
        TEST_PASSED = False
    SENTENCE_TEST = ""
    result = words_containing(SENTENCE_TEST, 'x')
    if result != []:
        TEST_PASSED = False
    SENTENCE_TEST = "The cow jumped over the moon"
    result = words_containing(SENTENCE_TEST, 't')
    if result != ['The', 'the']:
        TEST_PASSED = False
    SENTENCE_TEST = "The cow jumped over the moon"
    result = words_containing(SENTENCE_TEST, 'o')
    if result != ['cow', 'over', 'moon']:
        TEST_PASSED = False
    return TEST_PASSED
示例#4
0
def test_words_containing():
    # Test 1
    # If test1 passed, head to test2
    # If test1 failed, return False immidiately
    sentenses = "The people who get on in this world are the people who get up and look for circumstances they want,'\
                 and if they cannot find them, make them.——Bernara Shaw"

    letter = 'o'
    list1 = words_containing(sentenses, letter)
    list2 = [
        "people", "who", "on", "world", "people", "who", "look", "for",
        "cannot"
    ]
    i = 0
    while (i < len(list1)):
        if list1[i] == list2[i]:
            i = i + 1
            continue
        else:
            return False
    if (len(list1) == len(list2)):
        test1 = True
    else:
        return False
    # Test2 empty list
    sentenses = ""
    letter = 'a'
    list1 = words_containing(sentenses, letter)
    list2 = []
    if list1 == list2:
        test2 = True
    else:
        return False
    if test1 is True and test2 is True:
        return True
    """Return True/False if the test of words_containing passes/fails"""
示例#5
0
        for txt in args.texts:
            print(len(txt), end='')
            print(' ', end='')
        print('\n', end='')

    # If you prefer to call a single main() function written above the
    # if __name__ == "__main__":
    # statement, that is OK with me.
    # The important thing is to make it work correctly. ;-)
    # But don't overthink things.

    ### Part1: words_containing

    sentence = "Anyone who has never made a mistake has never tried anything new"

    result = words_containing(sentence, 'a')
    result.sort()
    gt = ['Anyone', 'has', 'made', 'a', 'mistake', 'has', 'anything']
    gt.sort()
    assert (result == gt)

    result = words_containing(sentence, 'x')
    result.sort()
    gt = []
    assert (result == gt)

    result = words_containing('', 'x')
    result.sort()
    gt = []
    assert (result == gt)