示例#1
0
    def test_multi_word_limit_one(self):
        """Dictionary with multiple words"""

        arg1 = {'a': 6, 'b': 5, 'c': 5, 'd': 4}
        arg2 = 1
        exp_arg1 = {'a': 6}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " + "but it was\n {}").format(
            exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
    def test_empty(self):
        '''Empty dictionary.'''

        arg1 = {}
        arg2 = 1
        exp_arg1 = {}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be\n {}, " + "but it was\n {}").format(
            exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
    def test_int_more_than_dict(self):
        '''The integer is larger than the length of the dictionary.'''

        arg1 = {'Yo': 3, 'Yoo': 3, 'Yooo': 2, 'Masheil': 2, 'Sucks': 1}
        arg2 = 7
        exp_arg1 = {'Yo': 3, 'Yoo': 3, 'Yooo': 2, 'Masheil': 2, 'Sucks': 1}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be\n {}, " + "but it was\n {}").format(
            exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
    def test_same(self):
        '''Length of dictionary is the same as the integer.'''

        arg1 = {'hello': 5, 'hi': 4, 'wassup': 3, 'heynmman': 2, 'ok': 1}
        arg2 = 5
        exp_arg1 = {'hello': 5, 'hi': 4, 'wassup': 3, 'heynmman': 2, 'ok': 1}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be\n {}, " + "but it was\n {}").format(
            exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
    def test_exceed(self):
        '''Word count exceeds the length of the dictionary needed.'''

        arg1 = {'Hey': 4, 'Hi': 3, 'Wow': 2, 'Wdym': 2, 'Why': 1}
        arg2 = 3
        exp_arg1 = {'Hey': 4, 'Hi': 3}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be\n {}, " + "but it was\n {}").format(
            exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
    def test_word_smaller_than_limit(self):
        """Dictionary with one word."""

        arg1 = {'hello': 2}
        arg2 = 2
        exp_arg1 = {'hello': 2}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " + "but it was\n {}").format(
            exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
    def test_multi_words_same_freq_1(self):
        """Dictionary with one word."""

        arg1 = {'hello': 2, 'h': 2}
        arg2 = 1
        exp_arg1 = {}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " + "but it was\n {}").format(
            exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
示例#8
0
    def test_multiple_word_limit_less(self):
        """Dictionary with multiple word less limit."""

        arg1 = {'hello': 2, 'How are you': 5, 'Life is good': 5}
        arg2 = 1
        exp_arg1 = {}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " + "but it was\n {}").format(
            exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
    def test_three_word_limit_two_but_tie(self):
        """Dictionary with three word with ."""

        arg1 = {'jesse': 2, 'thomas': 1, 'tie': 1}
        arg2 = 2
        exp_arg1 = {'jesse': 2}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " +
               "but it was\n {}").format(exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)          
示例#10
0
    def test_multiple_word_same(self):
        """Dictionary with multiple words same quantity."""

        arg1 = {'hello': 2, 'i am good': 2, 'hbu': 2}
        arg2 = 3
        exp_arg1 = {'hello': 2, 'i am good': 2, 'hbu': 2}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " + "but it was\n {}").format(
            exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
示例#11
0
    def test_many_words_less_limit(self):
        """Dictionary with many words less limit ."""

        arg1 = {'hello': 2, 'i am good': 2, 'hbu': 2, 'a': 4, 'b': 11, 'v': 20}
        arg2 = 4
        exp_arg1 = {'a': 4, 'b': 11, 'v': 20}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " + "but it was\n {}").format(
            exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
示例#12
0
    def test_six_word_repitition_limit_three(self):
        '''Dictionary with six words each having different counts'''

        arg1 = {'hello': 4, 'bye': 3, 'cats': 2, 'test': 2, 'case': 2, 'yes': 2}
        arg2 = 3
        exp_arg1 = {'hello': 4, 'bye': 3}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " +
               "but it was\n {}").format(exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
示例#13
0
    def test_two_word_repition_limit_one(self):
        '''Dictionary with two words which have same counts'''

        arg1 = {'hello': 3, 'bye': 3}
        arg2 = 1
        exp_arg1 = {}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " +
               "but it was\n {}").format(exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
    def test_one_word_limit_greater_than_one(self):
        '''Dictionary with one word limit greater than one'''

        arg1 = {'hello': 2}
        arg2 = 2
        exp_arg1 = {'hello': 2}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " + "but it was\n {}").format(
            exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
    def test_two_word_limit_one(self):
        '''Dictionary with two words and binding word limit.'''

        arg1 = {'hello': 2, 'bye': 1}
        arg2 = 1
        exp_arg1 = {'hello': 2}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " +
               "but it was\n {}").format(exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
    def test_same_count(self):
        '''The dictionary is full of the same word count.'''

        arg1 = {'Hi': 2, 'Hey': 2, 'What': 2, 'Is': 2, 'Up': 2}
        arg2 = 3
        exp_arg1 = {}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be\n {}, " + "but it was\n {}").format(
            exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
    def test_multiple_word_limit_small(self):
        '''Dictionary with multiple words and a small word limit.'''

        arg1 = {'Naruto': 5, 'Sasuke': 7, 'Itachi': 9, 'Madara': 11}
        arg2 = 1
        exp_arg1 = {'Madara': 11}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " + "but it was\n {}").format(
            exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
    def test_multiple_word_limit_large(self):
        '''Dictionary with multiple words and a large word limit.'''

        arg1 = {'UTSC': 12, 'UTM': 9, 'UTSG': 14}
        arg2 = 20
        exp_arg1 = {'UTSC': 12, 'UTM': 9, 'UTSG': 14}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " + "but it was\n {}").format(
            exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
示例#19
0
    def test_all_duplicates_one(self):
        """Dictionary with only duplicates"""

        arg1 = {'a': 5, 'b': 5, 'c': 5}
        arg2 = 1
        exp_arg1 = {}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " + "but it was\n {}").format(
            exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
    def test_multiple_word_limit(self):
        '''Dictionary with multiple words.'''

        arg1 = {'jason': 0, 'hu': 1, 'is': 2, 'cool': 3}
        arg2 = 3
        exp_arg1 = {'cool': 3, 'is': 2, 'hu': 1}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " + "but it was\n {}").format(
            exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
    def test_multiple_word_limit_zero(self):
        '''Dictionary with multiple words and a zero-word limit.'''

        arg1 = {'rolf': 1, 'lmao': 4, 'lolz': 7}
        arg2 = 0
        exp_arg1 = {}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " + "but it was\n {}").format(
            exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
    def test_one_word_limit_large(self):
        '''Dictionary with one word and a large word limit.'''

        arg1 = {'LeBron James': 3}
        arg2 = 10
        exp_arg1 = {'LeBron James': 3}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " + "but it was\n {}").format(
            exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
    def test_multiple_word_limit_tied_omit_all(self):
        '''Dictionary with multiple words and a tie-inducing limit, removing \
        all words.'''

        arg1 = {'Samsung': 3, 'Apple': 3, 'Google': 3, 'OnePlus': 1}
        arg2 = 2
        exp_arg1 = {}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " + "but it was\n {}").format(
            exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
    def test_multiple_word_limit_tied_omit_tied(self):
        '''Dictionary with multiple words and a tie-inducing limit, removing \
        tied words.'''

        arg1 = {'Nike': 6, 'adidas': 4, 'UA': 4, 'Puma': 0}
        arg2 = 2
        exp_arg1 = {'Nike': 6}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " + "but it was\n {}").format(
            exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
    def test_non_affecting_tied_counts_border_case(self):
        '''Dictionary with words with same counts but still 
        len(exp_arg1) == arg2.'''

        arg1 = {'a': 9, 'b': 9, 'c': 8, 'd': 8, 'e': 7, 'f': 6}
        arg2 = 4
        exp_arg1 = {'a': 9, 'b': 9, 'c': 8, 'd': 8}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " +
               "but it was\n {}").format(exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
    def test_non_binding_word_limit(self):
        '''Dictionary with words less than the word limit resulting in no change
        in the dictionary'''

        arg1 = {'a': 9, 'b': 9, 'c': 8, 'd': 8, 'e': 7, 'f': 6}
        arg2 = 10
        exp_arg1 = {'a': 9, 'b': 9, 'c': 8, 'd': 8, 'e': 7, 'f': 6}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " +
               "but it was\n {}").format(exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)    
    def test_affecting_tied_counts_extreme_case(self):
        '''Dictionary with words with tied counts resulting in an empty
        dictionary.''' 
        
        arg1 = {'a': 9, 'b': 9, 'c': 8, 'd': 8, 'e': 7, 'f': 6}
        arg2 = 1
        exp_arg1 = {}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " +
               "but it was\n {}").format(exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)    
    def test_multiple_words_limit_less_than_num_words_some_valid_words(self):
        '''Dictionary with many words where the limit is less then the num words 
        where some of the words remain'''

        arg1 = {'hello': 2, 'hi': 3, 'hey': 4, 'sup': 3}
        arg2 = 2
        exp_arg1 = {'hey': 4}
        act_return = tweets.common_words(arg1, arg2)
        exp_return = None

        msg = "Expected {}, but returned {}".format(exp_return, act_return)
        self.assertEqual(act_return, exp_return, msg)

        msg = ("Expected dictionary to be {}\n, " + "but it was\n {}").format(
            exp_arg1, arg1)
        self.assertEqual(arg1, exp_arg1, msg)
示例#29
0
  def test_many_words_mixed_value_limit_less_geq_greater(self):
      '''Dictionary with more than one word a few with same values and a
      few with unique values and limit is less than the keys in the dictionary
      and the limit is equal to the amount of words with the same values where
      the unique values and one key contains a maximum value'''
 
      arg1 = {'hello': 2, 'bye': 2, 'ok': 1, 'big': 3}
      arg2 = 2
      exp_arg1 = {'big': 3}
      act_return = tweets.common_words(arg1, arg2)
      exp_return = None
 
      msg = "Expected {}, but returned {}".format(exp_return, act_return)
      self.assertEqual(act_return, exp_return, msg)
 
      msg = ("Expected dictionary to be {}\n, " +
             "but it was\n {}").format(exp_arg1, arg1)
      self.assertEqual(arg1, exp_arg1, msg)                    
示例#30
0
        '''.format(type(result[0]))
except IndexError:
    assert False, \
        '''The list returned by extract_hashtags was empty and should have contained data.\n'''

# tweets.count_words
word_d = {'statement': 1, 'regarding': 1}
result = tweets.count_words('Statement Regarding British Referendum', word_d)
assert isinstance(result, type(None)), \
    '''tweets.count_words should return None, but returned {0}\n'''.format(type(result))
assert len(word_d) == 4, \
    '''tweets.count_words should modify the argument dictionary\n'''

# tweets.common_words
word_d = {'statement': 10, 'regarding': 1}
result = tweets.common_words(word_d, 1)
assert isinstance(result, type(None)), \
    '''tweets.common_words should return None, but returned {0}\n'''.format(type(result))
assert len(word_d) == 1, \
    '''tweets.common_words should modify the argument dictionary'''

# tweets.read_tweets
try:
    tweet_file = open('short_data.txt')
    result = tweets.read_tweets(tweet_file)
    tweet_file.close()
    assert isinstance(result, dict), \
        '''tweets.read_tweets should return a dict, but returned {0}\n'''.format(type(result))
    key = list(result.keys())[0]
    assert isinstance(key, str), \
        '''tweets.read_tweets should contains strings as keys, but the key we checked was a {0}