-
Notifications
You must be signed in to change notification settings - Fork 85
/
score_test.go
51 lines (46 loc) · 988 Bytes
/
score_test.go
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
package zoekt
import (
"maps"
"testing"
)
func TestCalculateTermFrequency(t *testing.T) {
cases := []struct {
cands []*candidateMatch
wantDF termDocumentFrequency
wantTermFrequencies map[string]int
}{{
cands: []*candidateMatch{
{substrLowered: []byte("foo")},
{substrLowered: []byte("foo")},
{substrLowered: []byte("bar")},
{
substrLowered: []byte("bas"),
fileName: true,
},
},
wantDF: termDocumentFrequency{
"foo": 1,
"bar": 1,
"bas": 1,
},
wantTermFrequencies: map[string]int{
"foo": 2,
"bar": 1,
"bas": 5,
},
},
}
for _, c := range cases {
t.Run("", func(t *testing.T) {
fm := FileMatch{}
df := make(termDocumentFrequency)
tf := calculateTermFrequency(c.cands, df)
if !maps.Equal(df, c.wantDF) {
t.Errorf("got %v, want %v", df, c.wantDF)
}
if !maps.Equal(tf, c.wantTermFrequencies) {
t.Errorf("got %v, want %v", fm, c.wantTermFrequencies)
}
})
}
}