Skip to content
Browse files

Renamed methods and added some tests.

  • Loading branch information...
1 parent 540643b commit a1c4a26891d90d4ad47523fbd37ecfd37b6c1828 @robertgreiner committed
View
3 Recommender.Tests/Recommender.Tests.csproj
@@ -32,6 +32,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="Moq">
+ <HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
+ </Reference>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.5.10.11092\lib\nunit.framework.dll</HintPath>
</Reference>
View
16 Recommender.Tests/SimilarityScore/EuclideanDistanceTests.cs
@@ -22,6 +22,14 @@ public void TwoReviewersWithSomeSimilarReviewsShouldHaveAScoreBetweenZeroAndOne(
}
[Test]
+ public void ReviewersWithIdenticalReviewsShouldHaveASimilarityScoreOfOne()
+ {
+ var r = ReviewerBuilder.BuildReviewer1();
+ euclideanDistance = new EuclideanDistance(r, r);
+ Assert.AreEqual(1.0, euclideanDistance.Score());
+ }
+
+ [Test]
public void TwoReviewersWithSomeSimilarReviewsShouldHaveAPositiveScore()
{
euclideanDistance = new EuclideanDistance(ReviewerBuilder.BuildReviewer6(), ReviewerBuilder.BuildReviewer7());
@@ -51,5 +59,13 @@ public void ReviewersThatHaveTheSameTasteShouldHaveAPerfectScore()
euclideanDistance = new EuclideanDistance(r1, r1);
Assert.AreEqual(1.0, euclideanDistance.Score());
}
+
+ [Test]
+ public void ShouldReturnASimilarityScoreOfZeroWhenBothUsersHaveNoSimilarReviews()
+ {
+ var r = ReviewerBuilder.BuildReviewerWithNoReviews();
+ euclideanDistance = new EuclideanDistance(r, r);
+ Assert.AreEqual(0.0, euclideanDistance.Score());
+ }
}
}
View
1 Recommender.Tests/packages.config
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
+ <package id="Moq" version="4.0.10827" />
<package id="NUnit" version="2.5.10.11092" />
</packages>
View
4 Recommender/SimilarityScore/EuclideanDistance.cs
@@ -22,7 +22,7 @@ public double Score()
{
SimilarReviews = new FindSimilarReviews(R1.Reviews, R2.Reviews).Calculate();
- if (DoReviewersHaveSimilarReviews())
+ if (ReviewersHaveNoSimilarReviews())
{
return 0.0;
}
@@ -36,7 +36,7 @@ private static double NormalizeAnswer(double sumDifferenceSquares)
return Math.Round(1 / (1 + sumDifferenceSquares), 3);
}
- private bool DoReviewersHaveSimilarReviews()
+ public bool ReviewersHaveNoSimilarReviews()
{
return SimilarReviews.Count == 0;
}
View
7 Recommender/SimilarityScore/PearsonCorrelation.cs
@@ -22,7 +22,7 @@ public double Score()
{
SimilarReviews = new FindSimilarReviews(R1.Reviews, R2.Reviews).Calculate();
- if (DoReviewersHaveSimilarReviews())
+ if (ReviewersHaveNoSimilarReviews())
{
return 0.0;
}
@@ -31,8 +31,7 @@ public double Score()
var sumR1 = new SumScores(SimilarReviews, R1.Reviews).Calculate();
var sumR2 = new SumScores(SimilarReviews, R2.Reviews).Calculate();
-
-
+
var sumR1Sq = new SumSquares(SimilarReviews, R1.Reviews).Calculate();
var sumR2Sq = new SumSquares(SimilarReviews, R2.Reviews).Calculate();
@@ -51,7 +50,7 @@ public double Score()
return Math.Round(answer, 3);
}
- private bool DoReviewersHaveSimilarReviews()
+ private bool ReviewersHaveNoSimilarReviews()
{
return SimilarReviews.Count == 0;
}

0 comments on commit a1c4a26

Please sign in to comment.
Something went wrong with that request. Please try again.