Browse files

Ignore similar reviews if either user has an invalid score. Currently…

…, an invalid score is a number <= 0.0
  • Loading branch information...
1 parent bd32ebd commit 634e90b82c0f83887064359a9d6aa38c81259ad9 @robertgreiner committed Nov 11, 2011
View
16 Recommender.Tests/Common/FindSimilarReviewsTests.cs
@@ -30,5 +30,21 @@ public void ReviewersThatHaveTheSameTasteShouldHaveAllSimilarItems()
var r2 = ReviewerBuilder.BuildReviewer1();
Assert.AreEqual(6, new FindSimilarReviews(r1.Reviews, r2.Reviews).Calculate().Count);
}
+
+ [Test]
+ public void ReviewsWithAScoreOfZeroShouldBeIgnored()
+ {
+ var r1 = ReviewerBuilder.BuildReviewer1();
+ var empty = ReviewerBuilder.BuildReviewerWithInvalidReviews();
+ Assert.AreEqual(0, new FindSimilarReviews(r1.Reviews, empty.Reviews).Calculate().Count);
+ }
+
+ [Test]
+ public void ReviewsWithAScoreOfZeroShouldBeIgnoredSwitchUsers()
+ {
+ var r1 = ReviewerBuilder.BuildReviewer1();
+ var empty = ReviewerBuilder.BuildReviewerWithInvalidReviews();
+ Assert.AreEqual(0, new FindSimilarReviews(empty.Reviews, r1.Reviews).Calculate().Count);
+ }
}
}
View
12 Recommender/Common/FindSimilarReviews.cs
@@ -16,7 +16,17 @@ public FindSimilarReviews(Dictionary<string, double> firstUserReviews, Dictionar
public List<string> Calculate()
{
- return (from r in FirstUserReviews where SecondUserReviews.ContainsKey(r.Key) select r.Key).ToList();
+ return (from r in FirstUserReviews where DoesReviewExistInSecondUserReviews(r) && IsReviewValid(r.Value) && IsReviewValid(SecondUserReviews[r.Key]) select r.Key).ToList();
+ }
+
+ private static bool IsReviewValid(double value)
+ {
+ return value > 0.0;
+ }
+
+ private bool DoesReviewExistInSecondUserReviews(KeyValuePair<string, double> r)
+ {
+ return SecondUserReviews.ContainsKey(r.Key);
}
}
}
View
22 Recommender/Data/ReviewerBuilder.cs
@@ -31,12 +31,12 @@ public static Reviewer BuildAllMidScores()
public static Reviewer BuildAllMinScores()
{
var reviewer = new Reviewer {Name = "Mini"};
- reviewer.AddReview("Code Complete", 0.0);
- reviewer.AddReview("C# in Depth", 0.0);
- reviewer.AddReview("Clean Code", 0.0);
- reviewer.AddReview("Unit Testing", 0.0);
- reviewer.AddReview("Joel on Software", 0.0);
- reviewer.AddReview("Refactoring", 0.0);
+ reviewer.AddReview("Code Complete", 1.0);
+ reviewer.AddReview("C# in Depth", 1.0);
+ reviewer.AddReview("Clean Code", 1.0);
+ reviewer.AddReview("Unit Testing", 1.0);
+ reviewer.AddReview("Joel on Software", 1.0);
+ reviewer.AddReview("Refactoring", 1.0);
return reviewer;
}
@@ -57,7 +57,7 @@ public static Reviewer BuildOneReviewMid()
public static Reviewer BuildOneReviewMin()
{
var reviewer = new Reviewer {Name = "Mini"};
- reviewer.AddReview("C# in Depth", 0.0);
+ reviewer.AddReview("C# in Depth", 1.0);
return reviewer;
}
@@ -141,5 +141,13 @@ public static Reviewer BuildMyReviews()
reviewer.AddReview("Refactoring", 5.0);
return reviewer;
}
+
+ public static Reviewer BuildReviewerWithInvalidReviews()
+ {
+ var reviewer = new Reviewer { Name = "Invalid Reviews" };
+ reviewer.AddReview("Code Complete", 0.0);
+ reviewer.AddReview("C# in Depth", -2.0);
+ return reviewer;
+ }
}
}

0 comments on commit 634e90b

Please sign in to comment.