def test_word_count():
    """Test the counting of words.
    
    The example poem is Risk, by Anais Nin.
    """
    risk_poem_counts = {
        'the': 3,
        'risk': 2,
        'to': 2,
        'and': 1,
        'then': 1,
        'day': 1,
        'came': 1,
        'when': 1,
        'remain': 1,
        'tight': 1,
        'in': 1,
        'a': 1,
        'bud': 1,
        'was': 1,
        'more': 1,
        'painful': 1,
        'than': 1,
        'it': 1,
        'took': 1,
        'blossom': 1
    }
    expected_result = Counter(risk_poem_counts)
    with open('test_data/risk.txt', 'r') as reader:
        actual_result = countwords.count_words(reader)
    assert actual_result == expected_result
示例#2
0
def test_regression():
    """Regression test for Dracula."""
    with open('data/dracula.txt', 'r') as reader:
        word_counts_dict = countwords.count_words(reader)
    counts_array = np.array(list(word_counts_dict.values()))
    actual_alpha = plotcounts.get_power_law_params(counts_array)
    expected_alpha = pytest.approx(1.087, abs=0.001)
    assert actual_alpha == expected_alpha
示例#3
0
def test_integration():
    """Test the full word count to alpha parameter workflow."""
    with open('test_data/random_words.txt', 'r') as reader:
        word_counts_dict = countwords.count_words(reader)
    counts_array = np.array(list(word_counts_dict.values()))
    actual_alpha = plotcounts.get_power_law_params(counts_array)
    expected_alpha = pytest.approx(1.0, abs=0.01)
    assert actual_alpha == expected_alpha
 def test_if_words_are_unique(self):
     input = ["python", "apple", "ruby"]
     output = {'python': 1, 'apple': 1, 'ruby': 1}
     result = count_words(input)
     self.assertEqual(output, result)
 def test_if_dictionary_is_empty(self):
     input = []
     output = {}
     result = count_words(input)
     self.assertEqual(output, result)
示例#6
0
    assert actual_alpha == expected_alpha


def test_word_count():
    """Test the counting of words.

    The example poem is Risk, by Anais Nin.
    """
   risk_poem_counts = {'the': 3, 'risk': 2, 'to': 2, 'and': 1,
     'then': 1, 'day': 1, 'came': 1, 'when': 1, 'remain': 1,
     'tight': 1, 'in': 1, 'a': 1, 'bud': 1, 'was': 1,
     'more': 1, 'painful': 1, 'than': 1, 'it': 1, 'took': 1,
     'blossom': 1}
    expected_result = Counter(risk_poem_counts)
    with open('test_data/risk.txt', 'r') as reader:
        actual_result = countwords.count_words(reader)
    assert actual_result == expected_result


def test_integration():
    """Test the full word count to alpha parameter workflow."""
    with open('test_data/random_words.txt', 'r') as reader:
        word_counts_dict = countwords.count_words(reader)
    counts_array = np.array(list(word_counts_dict.values()))
    actual_alpha = plotcounts.get_power_law_params(counts_array)
    expected_alpha = pytest.approx(1.0, abs=0.01)
    assert actual_alpha == expected_alpha


def test_regression():
    """Regression test for Dracula."""