示例#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)