コード例 #1
0
def test_task5_api5():
    '''
    Test end-to-end functionality
    '''
    tweets = [{
        'text': 'the cat in the hat'
    }, {
        'text': "don't let the cat on the hat"
    }, {
        'text': "the cat's hat"
    }, {
        'text': "the hat cat"
    }]
    assert find_min_count_ngrams(tweets, 2, 2) == [(('cat', 'hat'), 2)]
    assert find_min_count_ngrams(tweets, 3, 2) == []
    assert (find_min_count_ngrams(tweets, 4,
                                  1) == [(("don't", 'let', 'cat', 'hat'), 1)])
コード例 #2
0
def test_find_min_count_ngrams(params):
    '''
    test code for find_min_count_ngrams
    '''

    # fix the type of expected
    params["expected"] = [(tuple(k), v) for (k, v) in params["expected"]]

    recreate_msg = setup_tweets(params)

    call_str = "  analyze.find_min_count_ngrams(tweets, {}, {})"
    recreate_msg += call_str.format(params["n"], params["min_count"])
    try:
        actual = analyze.find_min_count_ngrams(params["tweets"], params["n"],
                                               params["min_count"])
    except Exception as e:
        msg = str(e) + "\n" + recreate_msg
        pytest.fail(msg)

    compare_tuple_lists(actual, params, recreate_msg)
コード例 #3
0
def test_task5_api4():
    '''
    Test emoji removal
    '''
    tweets = [{'text': ';)'}]
    assert find_min_count_ngrams(tweets, 2, 1) == []
コード例 #4
0
def test_task5_api3():
    '''
    Test to see if prefix filtering is done properly
    '''
    tweets = [{'text': '@Dog dog'}]
    assert find_min_count_ngrams(tweets, 2, 1) == []
コード例 #5
0
def test_task5_api2():
    '''
    Test upper and lower case handling
    '''
    tweets = [{'text': 'Dog dog'}]
    assert find_min_count_ngrams(tweets, 2, 1) == [(('dog', 'dog'), 1)]
コード例 #6
0
def test_task5_api1():
    '''
    Test punctuation removal
    '''
    tweets = [{'text': 'the dog, a dog'}]
    assert find_min_count_ngrams(tweets, 2, 1) == [(('dog', 'dog'), 1)]