Permalink
Browse files

Test everything in scoring.Score

  • Loading branch information...
1 parent 030d622 commit 91e2adde79058d1f4ed8f63bb46297cc1e39a59e @gsamokovarov committed Mar 12, 2017
Showing with 31 additions and 12 deletions.
  1. +31 −12 scoring/score_test.go
View
@@ -1,17 +1,11 @@
package scoring
-import "testing"
+import (
+ "fmt"
+ "testing"
+)
-func TestNewScore(t *testing.T) {
- score := NewScore()
-
- if score.Age != Now && score.Weight != 1 {
- t.Errorf("Expected age to be %s and weight to be %d", score.Age, score.Weight)
- }
-
-}
-
-func TestCalculateScore(t *testing.T) {
+func TestScoreCalculate(t *testing.T) {
score1 := Score{2, Now}
score2 := Score{4, Now}
@@ -20,7 +14,15 @@ func TestCalculateScore(t *testing.T) {
}
}
-func TestUpdate(t *testing.T) {
+func TestScoreRelevance(t *testing.T) {
+ score := Score{2, Now}
+
+ if !inDelta(score.Relevance(), 2) {
+ t.Errorf("Expected relevance %v to be 0", score.Relevance())
+ }
+}
+
+func TestScoreUpdate(t *testing.T) {
score := Score{2, Now}
score.Update()
@@ -29,6 +31,23 @@ func TestUpdate(t *testing.T) {
}
}
+func TestScoreString(t *testing.T) {
+ score := Score{2, Now}
+
+ if score.String() == "" {
+ t.Errorf("Expected string representation to be ")
+ }
+}
+
+func TestNewScore(t *testing.T) {
+ score := NewScore()
+ str := fmt.Sprintf("{1 %s}", score.Age)
+
+ if str != score.String() {
+ t.Errorf("Expected %v to be %v", str, score.String())
+ }
+}
+
func inDelta(delta, expr float64) bool {
return delta-0.01 < expr && expr < delta+0.01
}

0 comments on commit 91e2add

Please sign in to comment.