feat(recommendation): extend Score with SimilarityScore + SimilarityWeight
This commit is contained in:
@@ -182,3 +182,37 @@ func TestScore_ContextualMatch_ZeroNoEffect(t *testing.T) {
|
||||
t.Errorf("score-with-zero-ctx = %v, score-without = %v; should be equal", withCtx, withoutCtx)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore_SimilarityScore_PerfectMatchAtWeight2(t *testing.T) {
|
||||
w := defaultWeights()
|
||||
w.SimilarityWeight = 2.0
|
||||
in := ScoringInputs{SimilarityScore: 1.0}
|
||||
got := Score(in, w, time.Now(), fixedRNG(0.5))
|
||||
// base 1.0 + recency 1.0 (never played) + similarity 2.0 = 4.0
|
||||
want := 4.0
|
||||
if math.Abs(got-want) > 1e-9 {
|
||||
t.Errorf("score = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore_SimilarityScore_HalfMatchAtWeight2(t *testing.T) {
|
||||
w := defaultWeights()
|
||||
w.SimilarityWeight = 2.0
|
||||
in := ScoringInputs{SimilarityScore: 0.5}
|
||||
got := Score(in, w, time.Now(), fixedRNG(0.5))
|
||||
// base 1.0 + recency 1.0 + similarity 1.0 = 3.0
|
||||
want := 3.0
|
||||
if math.Abs(got-want) > 1e-9 {
|
||||
t.Errorf("score = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore_SimilarityScore_ZeroNoEffect(t *testing.T) {
|
||||
wWithSim := defaultWeights()
|
||||
wWithSim.SimilarityWeight = 2.0
|
||||
withSim := Score(ScoringInputs{SimilarityScore: 0}, wWithSim, time.Now(), fixedRNG(0.5))
|
||||
withoutSim := Score(ScoringInputs{}, defaultWeights(), time.Now(), fixedRNG(0.5))
|
||||
if math.Abs(withSim-withoutSim) > 1e-9 {
|
||||
t.Errorf("score-with-zero-sim = %v, score-without = %v; should be equal", withSim, withoutSim)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user