Browse files

added code to sum the squares of the scores of similar reviews for a …

…single reviewer.
  • Loading branch information...
1 parent 6e6e593 commit 101da36be21b606e0b5c1e780a27ab445d4afef2 @robertgreiner committed Nov 7, 2011
View
1 Recommender.Tests/Recommender.Tests.csproj
@@ -52,6 +52,7 @@
<Compile Include="PearsonCorrelationTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Reviews\ReviewerTests.cs" />
+ <Compile Include="Steps\SumSquaresOfSimilarScoresTests.cs" />
<Compile Include="Steps\SumDifferenceSquaresTests.cs" />
<Compile Include="Steps\SumSimilarScoresTests.cs" />
</ItemGroup>
View
42 Recommender.Tests/Steps/SumSquaresOfSimilarScoresTests.cs
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using Recommender.Common;
+using Recommender.Data;
+using Recommender.Reviews;
+using Recommender.Steps;
+
+namespace Recommender.Tests.Steps
+{
+ [TestFixture]
+ class SumSquaresOfSimilarScoresTests
+ {
+
+ private Reviewer r1;
+ private Reviewer r2;
+ private List<String> similarReviews;
+
+ [SetUp]
+ public void SetUp()
+ {
+ r1 = ReviewerBuilder.BuildReviewer1();
+ r2 = ReviewerBuilder.BuildReviewer2();
+ similarReviews = new FindSimilarReviews(r1.Reviews, r2.Reviews).Calculate();
+ }
+
+ [Test]
+ public void ShouldSumTheSquaresOfAllOfTheScoresFromTheFirstUser()
+ {
+ Assert.AreEqual(55.0, new SumSquaresOfSimilarScores(similarReviews, r1.Reviews).Calculate());
+ }
+
+ [Test]
+ public void ShouldSumTheSquaresOfAllOfTheScoresFromTheSecondUser()
+ {
+ Assert.AreEqual(69.75, new SumSquaresOfSimilarScores(similarReviews, r2.Reviews).Calculate());
+ }
+
+ }
+}
View
1 Recommender/Recommender.csproj
@@ -52,6 +52,7 @@
<Compile Include="SimilarityScoreRunner.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Steps\SimilarityScoreCommand.cs" />
+ <Compile Include="Steps\SumSquaresOfSimilarScores.cs" />
<Compile Include="Steps\SumDifferenceSquares.cs" />
<Compile Include="Steps\SumSimilarScores.cs" />
</ItemGroup>
View
24 Recommender/Steps/SumSquaresOfSimilarScores.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Recommender.Steps
+{
+ public class SumSquaresOfSimilarScores : SimilarityScoreCommand
+ {
+ private readonly List<string> SimilarReviews;
+ private readonly Dictionary<string, double> UserReviews;
+
+ public SumSquaresOfSimilarScores(List<string> similarReviews, Dictionary<string, double> userReviews)
+ {
+ SimilarReviews = similarReviews;
+ UserReviews = userReviews;
+ }
+
+ public double Calculate()
+ {
+ return SimilarReviews.Sum(title => Math.Pow(UserReviews[title], 2));
+ }
+ }
+}

0 comments on commit 101da36

Please sign in to comment.