Пример #1
0
 def test_word_count(self):
     '''
     Test whether the word count is correct
     '''
     word_stats = text_stats.text_stats()
     word_stats.extract_stats('Hello there this is a long sentence')
     self.assertEqual(word_stats.get_total_words(), 7)
Пример #2
0
 def test_word_count(self):
     '''
     Test whether the word count is correct
     '''
     word_stats = text_stats.text_stats()
     word_stats.extract_stats('Hello there this is a long sentence')
     self.assertEqual(word_stats.get_total_words(), 7)
Пример #3
0
    def test_removal_of_dots(self):
        '''
        Test whether dots are removed
        '''
        word_stats = text_stats.text_stats()
        word_stats.extract_stats('Hello. There.')

        self.assertEqual(word_stats.freq_table, dict(hello = 1, there = 1))
Пример #4
0
    def test_add_excluded_words(self):
        '''
        Test whether adding a new excluded word works internally
        '''
        word_stats = text_stats.text_stats()
        word_stats.add_excluded_words(['one','two','three'])

        self.assertEqual(word_stats.excluded_words, set(['one','two','three']) )
Пример #5
0
    def test_unique_word_count(self):
        '''
        Test whether the unique word count is correct
        '''
        word_stats = text_stats.text_stats()
        word_stats.extract_stats('Hello hello hello')

        self.assertEqual(word_stats.get_unique_word_count(), 1)
Пример #6
0
    def test_removal_of_dots(self):
        '''
        Test whether dots are removed
        '''
        word_stats = text_stats.text_stats()
        word_stats.extract_stats('Hello. There.')

        self.assertEqual(word_stats.freq_table, dict(hello=1, there=1))
Пример #7
0
    def test_exclusion(self):
        '''
        Test whether excluding a word works
        '''
        word_stats = text_stats.text_stats()
        word_stats.extract_stats('Hello there', ['there'])

        self.assertEqual(word_stats.freq_table, dict(hello=1))
Пример #8
0
    def test_unique_word_count(self):
        '''
        Test whether the unique word count is correct
        '''
        word_stats = text_stats.text_stats()
        word_stats.extract_stats('Hello hello hello')

        self.assertEqual(word_stats.get_unique_word_count(), 1)
Пример #9
0
    def test_exclusion(self):
        '''
        Test whether excluding a word works
        '''
        word_stats = text_stats.text_stats()
        word_stats.extract_stats('Hello there', ['there'])

        self.assertEqual(word_stats.freq_table, dict(hello=1))
Пример #10
0
    def test_excluded_word_case(self):
        '''
        Test whether the excluded words are converted into lowercase
        '''
        word_stats = text_stats.text_stats()
        word_stats.add_excluded_words(['One','Two','ThrEe'])

        self.assertEqual(word_stats.excluded_words, set(['one','two','three']) )
Пример #11
0
    def test_one_word_string(self):
        '''
        Test with input of 1 word
        Please note that all of the input words are turned to lowercase
        '''
        word_stats = text_stats.text_stats()
        word_stats.extract_stats("Hello")

        self.assertEqual(word_stats.freq_table, dict(hello=1))
Пример #12
0
    def test_empty_string(self):
        '''
        When an empty string is passed, an empty dictionary should
        be returned
        '''
        word_stats = text_stats.text_stats()
        word_stats.extract_stats("")

        self.assertEqual(len(word_stats.freq_table), 0)
Пример #13
0
    def test_excluded_word_case(self):
        '''
        Test whether the excluded words are converted into lowercase
        '''
        word_stats = text_stats.text_stats()
        word_stats.add_excluded_words(['One', 'Two', 'ThrEe'])

        self.assertEqual(word_stats.excluded_words,
                         set(['one', 'two', 'three']))
Пример #14
0
 def test_append_excluded_words(self):
     '''
     Test whether extending the excluded word set works appropriately
     '''
     word_stats = text_stats.text_stats()
     word_stats.add_excluded_words(['one', 'two', 'three'])
     word_stats.add_excluded_words(['four', 'five', 'six'])
     self.assertEqual(word_stats.excluded_words,
                      set(['one', 'two', 'three', 'four', 'five', 'six']))
Пример #15
0
    def test_add_excluded_words(self):
        '''
        Test whether adding a new excluded word works internally
        '''
        word_stats = text_stats.text_stats()
        word_stats.add_excluded_words(['one', 'two', 'three'])

        self.assertEqual(word_stats.excluded_words,
                         set(['one', 'two', 'three']))
Пример #16
0
    def test_one_word_string(self):
        '''
        Test with input of 1 word
        Please note that all of the input words are turned to lowercase
        '''
        word_stats = text_stats.text_stats()
        word_stats.extract_stats("Hello")

        self.assertEqual(word_stats.freq_table, dict(hello = 1))
Пример #17
0
    def test_empty_string(self):
        '''
        When an empty string is passed, an empty dictionary should
        be returned
        '''
        word_stats = text_stats.text_stats()
        word_stats.extract_stats("")

        self.assertEqual(len(word_stats.freq_table), 0)
Пример #18
0
 def test_append_excluded_words(self):
     '''
     Test whether extending the excluded word set works appropriately
     '''
     word_stats = text_stats.text_stats()
     word_stats.add_excluded_words(['one','two','three'])
     word_stats.add_excluded_words(['four','five','six'])
     self.assertEqual(word_stats.excluded_words,
                      set(['one','two','three','four','five','six']) )
Пример #19
0
    def test_append_to_existing(self):
        '''
        Test whether more results can be appended after processing a string
        '''
        word_stats = text_stats.text_stats()
        word_stats.extract_stats('Hello')

        word_stats.extract_stats('hello')

        self.assertEqual(word_stats.freq_table, dict(hello=2))
Пример #20
0
    def test_append_to_existing(self):
        '''
        Test whether more results can be appended after processing a string
        '''
        word_stats = text_stats.text_stats()
        word_stats.extract_stats('Hello')

        word_stats.extract_stats('hello')

        self.assertEqual(word_stats.freq_table, dict(hello = 2))
Пример #21
0
def main():
    word_stats = text_stats.text_stats()
    word_stats.extract_stats(wiki_text)
    word_stats.print_sorted_dictionary(word_stats.freq_table)
Пример #22
0
def main():
    word_stats = text_stats.text_stats()
    word_stats.extract_stats(wiki_text)
    word_stats.print_sorted_dictionary(word_stats.freq_table)