-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheval_test.go
More file actions
65 lines (60 loc) · 1.65 KB
/
Copy patheval_test.go
File metadata and controls
65 lines (60 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package contexting
import (
"path/filepath"
"testing"
"time"
)
func TestEvaluateSearchMetrics(t *testing.T) {
root := t.TempDir()
index := &ContextIndex{
RootPath: root,
GeneratedAt: time.Now().UTC(),
Tree: &Node{
FullPath: root,
Type: "directory",
Children: map[string]*Node{
"config": {
FullPath: filepath.Join(root, "config"),
Type: "directory",
Children: map[string]*Node{
"local_store.go": {
FullPath: filepath.Join(root, "config", "local_store.go"),
Type: "file",
Synonyms: []string{"local storage", "settings"},
Children: map[string]*Node{},
},
},
},
"auth": {
FullPath: filepath.Join(root, "auth"),
Type: "directory",
Children: map[string]*Node{},
},
},
},
}
cases := []EvalCase{
{Query: "check local storage", ExpectAny: []string{"config/local_store.go"}},
{Query: "authorization", ExpectAny: []string{"auth"}},
}
summary, results := EvaluateSearch(index, cases, SearchOptions{Limit: 5, MinScore: 1})
if len(results) != 2 {
t.Fatalf("expected 2 eval results, got %d", len(results))
}
if summary.Cases != 2 || summary.ScoredCases != 2 {
t.Fatalf("unexpected summary counters: %+v", summary)
}
if summary.Top1Hits < 1 {
t.Fatalf("expected at least one top1 hit, got %+v", summary)
}
if summary.MRR <= 0 {
t.Fatalf("expected positive MRR, got %+v", summary)
}
}
func TestFirstMatchRank(t *testing.T) {
results := []SearchResult{{Path: "src/main.go"}, {Path: "config/local_store.go"}}
rank := firstMatchRank(results, []string{"config/local_store.go"})
if rank != 2 {
t.Fatalf("expected rank 2, got %d", rank)
}
}