Permalink
Browse files

Renamed methods and added some tests.

  • Loading branch information...
robertgreiner committed Nov 14, 2011
1 parent 540643b commit a1c4a26891d90d4ad47523fbd37ecfd37b6c1828
@@ -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>
@@ -21,6 +21,14 @@ public void TwoReviewersWithSomeSimilarReviewsShouldHaveAScoreBetweenZeroAndOne(
Assert.AreEqual(0.037, euclideanDistance.Score());
}
+ [Test]
+ public void ReviewersWithIdenticalReviewsShouldHaveASimilarityScoreOfOne()
+ {
+ var r = ReviewerBuilder.BuildReviewer1();
+ euclideanDistance = new EuclideanDistance(r, r);
+ Assert.AreEqual(1.0, euclideanDistance.Score());
+ }
+
[Test]
public void TwoReviewersWithSomeSimilarReviewsShouldHaveAPositiveScore()
{
@@ -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());
+ }
}
}
@@ -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>
@@ -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;
}
@@ -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.