Skip to content

Commit

Permalink
Improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
jtibshirani committed Apr 16, 2024
1 parent 8618bfa commit 0ea969e
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions build/scoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,42 @@ func TestBM25(t *testing.T) {

cases := []scoreCase{
{
// Matches on both filename and content
fileName: "example.java",
query: &query.Substring{Pattern: "example"},
content: exampleJava,
language: "Java",
// keyword-score:1.63 (sum-tf: 6.00, length-ratio: 2.00)
wantScore: 1.629,
wantScore: 1.63,
}, {
// Matches only on content
fileName: "example.java",
query: &query.And{Children: []query.Q{
&query.Substring{Pattern: "inner"},
&query.Substring{Pattern: "static"},
&query.Substring{Pattern: "interface"},
}},
content: exampleJava,
language: "Java",
// keyword-score:5.75 (sum-tf: 56.00, length-ratio: 2.00)
wantScore: 5.75,
},
{
// Matches only on filename
fileName: "example.java",
query: &query.Substring{Pattern: "java"},
content: exampleJava,
language: "Java",
// keyword-score:1.07 (sum-tf: 2.00, length-ratio: 2.00)
wantScore: 1.073,
wantScore: 1.07,
},
{
// Matches only on filename, and content is missing
fileName: "a/b/c/config.go",
query: &query.Substring{Pattern: "config.go"},
language: "Go",
// keyword-score:1.91 (sum-tf: 2.00, length-ratio: 0.00)
wantScore: 1.913,
wantScore: 1.91,
},
}

Expand Down Expand Up @@ -608,7 +624,10 @@ func checkScoring(t *testing.T, c scoreCase, keywordScoring bool, parserType cta
}
defer ss.Close()

srs, err := ss.Search(context.Background(), c.query, &zoekt.SearchOptions{UseKeywordScoring: keywordScoring, DebugScore: true})
srs, err := ss.Search(context.Background(), c.query, &zoekt.SearchOptions{
UseKeywordScoring: keywordScoring,
ChunkMatches: true,
DebugScore: true})
if err != nil {
t.Fatal(err)
}
Expand All @@ -618,7 +637,7 @@ func checkScoring(t *testing.T, c scoreCase, keywordScoring bool, parserType cta
}

if got := srs.Files[0].Score; math.Abs(got-c.wantScore) > epsilon {
t.Fatalf("score: want %f, got %f\ndebug: %s\ndebugscore: %s", c.wantScore, got, srs.Files[0].Debug, srs.Files[0].LineMatches[0].DebugScore)
t.Fatalf("score: want %f, got %f\ndebug: %s\ndebugscore: %s", c.wantScore, got, srs.Files[0].Debug, srs.Files[0].ChunkMatches[0].DebugScore)
}

if got := srs.Files[0].Language; got != c.language {
Expand Down

0 comments on commit 0ea969e

Please sign in to comment.