def problem7():
    if check_doctest('group_tweets_by_state', trends):
        return True

    def test_groups():
        tweets = pirate_tweets(trends.make_tweet)
        expected = {
          'MI': [tweets[0], tweets[4]],
          'MT': [tweets[1], tweets[5]],
          'ND': [tweets[2], tweets[6]],
          'FL': [tweets[3], tweets[7]],
        }
        tests = ( ((tweets,), expected), )
        if check_func(trends.group_tweets_by_state, tests, comp=comp_group):
            return True

    if test_groups():
        return True
    print("Testing abstraction barriers.")
    try:
        trends.swap_tweet_representation()
        if test_groups():
            return True
    finally:
        trends.swap_tweet_representation()
Example #2
0
def problem7(grades):
    """Test group_tweets_by_state."""
    if check_doctest('group_tweets_by_state', trends):
        return True

    def test_groups():
        tweets = pirate_tweets(trends.make_tweet)
        expected = {
            'MI': [tweets[0], tweets[4]],
            'MT': [tweets[1], tweets[5]],
            'ND': [tweets[2], tweets[6]],
            'FL': [tweets[3], tweets[7]],
        }
        tests = (((tweets, ), expected), )
        if check_func(trends.group_tweets_by_state, tests, comp=comp_group):
            return True

    if test_groups():
        return True

    print("Testing abstraction barriers.")
    try:
        trends.swap_tweet_representation()
        if test_groups():
            return True
    finally:
        trends.swap_tweet_representation()
Example #3
0
def problem8(grades):
    """Test average_sentiments."""
    def test_average():
        tweets = pirate_tweets(trends.make_tweet) + (
            trends.make_tweet('This tweet is without a sentiment', None, None,
                              None),
            trends.make_tweet('This tweet is also without a sentiment', None,
                              None, None),
        )
        tweets_by_state = {
            'MT': [tweets[1], tweets[5]],
            'MI': [tweets[0], tweets[4]],
            'FL': [tweets[3], tweets[7]],
            'ND': [tweets[2], tweets[6]],
            'AA': [tweets[8], tweets[9]],
        }
        expected = {
            'MT': -0.08333333333333333,
            'MI': 0.325,
            'FL': 0.5,
            'ND': 0.020833333333333332
        }
        tests = (((tweets_by_state, ), expected), )
        if check_func(trends.average_sentiments, tests, comp=comp_dict):
            return True

    if test_average():
        return True

    print("Testing abstraction barriers.")
    try:
        trends.swap_tweet_representation()
        original_make_sentiment = trends.make_sentiment
        original_sentiment_value = trends.sentiment_value
        original_has_sentiment = trends.has_sentiment
        trends.make_sentiment = lambda s: lambda: s
        trends.has_sentiment = lambda s: s() is not None
        trends.sentiment_value = lambda s: s()

        if test_average():
            return True
    finally:
        trends.swap_tweet_representation()
        trends.make_sentiment = original_make_sentiment
        trends.sentiment_value = original_sentiment_value
        trends.has_sentiment = original_has_sentiment
Example #4
0
def problem8(grades):
    """Test average_sentiments."""
    def test_average():
        tweets = pirate_tweets(trends.make_tweet) + (
          trends.make_tweet('This tweet is without a sentiment', None, None, None),
          trends.make_tweet('This tweet is also without a sentiment', None, None, None),
        )
        tweets_by_state = {
            'MT': [ tweets[1], tweets[5] ],
            'MI': [ tweets[0], tweets[4] ],
            'FL': [ tweets[3], tweets[7] ],
            'ND': [ tweets[2], tweets[6] ],
            'AA': [ tweets[8], tweets[9] ],
        }
        expected = {
            'MT': -0.08333333333333333,
            'MI': 0.325,
            'FL': 0.5,
            'ND': 0.020833333333333332
        }
        tests = ( ((tweets_by_state,),expected) ,)
        if check_func(trends.average_sentiments, tests, comp=comp_dict):
            return True

    if test_average():
        return True

    print("Testing abstraction barriers.")
    try:
        trends.swap_tweet_representation()
        original_make_sentiment = trends.make_sentiment
        original_sentiment_value = trends.sentiment_value
        original_has_sentiment = trends.has_sentiment
        trends.make_sentiment = lambda s: lambda: s
        trends.has_sentiment = lambda s: s() is not None
        trends.sentiment_value = lambda s: s()

        if test_average():
            return True
    finally:
        trends.swap_tweet_representation()
        trends.make_sentiment = original_make_sentiment
        trends.sentiment_value = original_sentiment_value
        trends.has_sentiment = original_has_sentiment