feat(recommendation): extend Score with ContextualMatchScore + ContextWeight
This commit is contained in:
@@ -148,3 +148,37 @@ func TestSkipRatio_Half(t *testing.T) {
|
||||
t.Errorf("skipRatio(4,2) = %v, want 0.5", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore_ContextualMatch_PerfectMatchAtWeight2(t *testing.T) {
|
||||
w := defaultWeights()
|
||||
w.ContextWeight = 2.0
|
||||
in := ScoringInputs{ContextualMatchScore: 1.0}
|
||||
got := Score(in, w, time.Now(), fixedRNG(0.5))
|
||||
// base 1.0 + recency 1.0 (never played) + contextual 2.0 = 4.0
|
||||
want := 4.0
|
||||
if math.Abs(got-want) > 1e-9 {
|
||||
t.Errorf("score = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore_ContextualMatch_HalfMatchAtWeight2(t *testing.T) {
|
||||
w := defaultWeights()
|
||||
w.ContextWeight = 2.0
|
||||
in := ScoringInputs{ContextualMatchScore: 0.5}
|
||||
got := Score(in, w, time.Now(), fixedRNG(0.5))
|
||||
// base 1.0 + recency 1.0 + contextual 1.0 = 3.0
|
||||
want := 3.0
|
||||
if math.Abs(got-want) > 1e-9 {
|
||||
t.Errorf("score = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScore_ContextualMatch_ZeroNoEffect(t *testing.T) {
|
||||
wWithCtx := defaultWeights()
|
||||
wWithCtx.ContextWeight = 2.0
|
||||
withCtx := Score(ScoringInputs{ContextualMatchScore: 0}, wWithCtx, time.Now(), fixedRNG(0.5))
|
||||
withoutCtx := Score(ScoringInputs{}, defaultWeights(), time.Now(), fixedRNG(0.5))
|
||||
if math.Abs(withCtx-withoutCtx) > 1e-9 {
|
||||
t.Errorf("score-with-zero-ctx = %v, score-without = %v; should be equal", withCtx, withoutCtx)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user