Permalink
Browse files

Added a method to Reviewer that returns a list of similar reviews fro…

…m a second reviewer.
  • Loading branch information...
1 parent fd57025 commit 7e3dd267fda4acc2758e37e3c2b793d0e7a9ebf7 @robertgreiner committed Nov 2, 2011
Showing with 31 additions and 1 deletion.
  1. +26 −1 Recommender.Tests/Reviews/ReviewerTests.cs
  2. +5 −0 Recommender/Reviews/Reviewer.cs
@@ -1,4 +1,6 @@
-using NUnit.Framework;
+using System.Linq;
+using NUnit.Framework;
+using Recommender.Data;
using Recommender.Reviews;
namespace Recommender.Tests.Reviews
@@ -32,5 +34,28 @@ public void ReviewerShouldHaveAValidReview()
reviewer.AddReview("Clean Code", 5);
Assert.IsNotEmpty(reviewer.Reviews);
}
+
+ [Test]
+ public void ShouldHaveASingleMaximumReview()
+ {
+ var max = ReviewerBuilder.BuildOneReviewMax();
+ Assert.AreEqual(5, max.Reviews.First().Value);
+ }
+
+ [Test]
+ public void TwoSimilarReviewersShouldHaveOneLikeReview()
+ {
+ var r1 = ReviewerBuilder.BuildOneReviewMax();
+ var r2 = ReviewerBuilder.BuildOneReviewMin();
+ Assert.AreEqual(1, r1.SimilarItems(r2.Reviews).Count);
+ }
+
+ [Test]
+ public void ReviewersThatHaveTheSameTasteShouldHaveAllSimilarItems()
+ {
+ var r1 = ReviewerBuilder.BuildReviewer1();
+ var r2 = ReviewerBuilder.BuildReviewer1();
+ Assert.AreEqual(6, r1.SimilarItems(r2.Reviews).Count);
+ }
}
}
@@ -19,5 +19,10 @@ public void AddReview(string title, double score)
{
Reviews.Add(title, score);
}
+
+ public List<string> SimilarItems(Dictionary<string, double> compareTo)
+ {
+ return (from r in Reviews where compareTo.ContainsKey(r.Key) select r.Key).ToList();
+ }
}
}

0 comments on commit 7e3dd26

Please sign in to comment.