reset password
Author Message
emagsin
Posts: 4
Posted 23:19 Oct 10, 2012 |

So, I've got my filter methods working properly, but for some reason, it doesn't seem to work with tweets that have been retweeted more than 321 times (weird). Now, here's the code for filter, which works as it should, now I'm just trying to pinpoint why exactly I'm running errors with tweets that have been "retweeted more than 321 times".

 

Here's the error messages:

 

======== LOG OF FAILED TESTS ========

Your solution achieved a testing score of 80 out of 110.
Below you can see a short feedback for every test that failed, indicating the reason
for the test failure and how many points you lost for each individual test.

[Test Description] filter: tweet with 321 retweets
[Observed Error] org.scalatest.exceptions.TestFailedException: exactly one such tweet
  [exception was thrown] detailed error message in debug output section below
[Lost Points] 10

[Test Description] filter and union: tweets with 321 and 205 retweets
[Observed Error] org.scalatest.exceptions.TestFailedException: exactly one such tweet
  [exception was thrown] detailed error message in debug output section below
[Lost Points] 10

[Test Description] filter and trending: tweets with 321 and 205 retweets
[Observed Error] org.scalatest.exceptions.TestFailedException: exactly two such tweets
  [exception was thrown] detailed error message in debug output section below
[Lost Points] 10

Here's the filter and filter0 code:

Under abstract:
     def filter(p: Tweet => Boolean): TweetSet = filter0(p, new Empty)
     def filter0(p: Tweet => Boolean, accu: TweetSet): TweetSet

  Under Empty:
     def filter0(p: Tweet => Boolean, accu: TweetSet): TweetSet = accu

  Under NonEmpty
       def filter0(p: Tweet => Boolean, accu: TweetSet): TweetSet = {
         if (p(elem)) this.tail.filter0(p, accu.incl(elem))
         else this.tail.filter0(p, accu)
       }

For empty:
Since the set is now empty, it returns the accumulator, which is a new set of tweets.

For nonempty:
It checks to see if the predicate is true for this element, if true the method calls itself with
the remaining elements (tweets -> this.tail) in the set and adds this tweet
(includes -> accu.incl(elem)), the current element, to the accumulator.
If the predicate is NOT true for this element, the method calls itself but does NOT add the
element to the accumulator.

Now how come I keep getting an error, specifically, "tweet with 321 retweets"?
I notice that union and trending may have issues as well, but of all the three error messages, they
all have filter in common, so I'm guessing this is the root cause.

Additionally, my trending and union methods seem to work fine.

Last edited by emagsin at 23:21 Oct 10, 2012.
rkjc
Posts: 61
Posted 05:10 Oct 11, 2012 |

I'm getting almost the same error:

[Test Description] filter and trending: tweets with 321 and 205 retweets
[Observed Error] org.scalatest.exceptions.TestFailedException: 321 did not equal 205
  [exception was thrown] detailed error message in debug output section below
[Lost Points] 10

still not sure.
rabbott
Posts: 1649
Posted 15:09 Oct 11, 2012 |

I wouldn't focus on the number 321. That's probably just one of the data points they use.

 

We talked about Elvin's problem earlier today. Can't say much about the second one without knowing more.

emagsin
Posts: 4
Posted 22:37 Oct 11, 2012 |

Quick update:

 

Replaced this chunk of code:

 

Under NonEmpty
       def filter0(p: Tweet => Boolean, accu: TweetSet): TweetSet = {
         if (p(elem)) this.tail.filter0(p, accu.incl(elem))
         else this.tail.filter0(p, accu)
       }

With this:

def filter0(p: Tweet => Boolean, accu: TweetSet): TweetSet = {
     this.tail.filter0(p, if (p(head)) accu.incl(head) else accu)
  }

And it works!

Thanks prof.

 

 

[For those that may still be confused, the logic behind the new filter0 is as follows:  Recursively call the filter function with the tail (that is, the elements left of) the set containing the tweets.  the body of the filter contains the predicate, which checks to see if the head of this set of tweets satisfies the predicate.  If the predicate is satisfied, add the head to the accumulator, if the predicate is NOT satisfied, do NOT add the predicate to the accumulator and simply pass the accumulator by itself.]

 

Hope this helps some people out.