예제 #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)