fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

1package zoekt 2 3import ( 4 "maps" 5 "testing" 6) 7 8func TestCalculateTermFrequency(t *testing.T) { 9 cases := []struct { 10 cands []*candidateMatch 11 wantDF termDocumentFrequency 12 wantTermFrequencies map[string]int 13 }{{ 14 cands: []*candidateMatch{ 15 {substrLowered: []byte("foo")}, 16 {substrLowered: []byte("foo")}, 17 {substrLowered: []byte("bar")}, 18 { 19 substrLowered: []byte("bas"), 20 fileName: true, 21 }, 22 }, 23 wantDF: termDocumentFrequency{ 24 "foo": 1, 25 "bar": 1, 26 "bas": 1, 27 }, 28 wantTermFrequencies: map[string]int{ 29 "foo": 2, 30 "bar": 1, 31 "bas": 5, 32 }, 33 }, 34 } 35 36 for _, c := range cases { 37 t.Run("", func(t *testing.T) { 38 fm := FileMatch{} 39 df := make(termDocumentFrequency) 40 tf := calculateTermFrequency(c.cands, df) 41 42 if !maps.Equal(df, c.wantDF) { 43 t.Errorf("got %v, want %v", df, c.wantDF) 44 } 45 46 if !maps.Equal(tf, c.wantTermFrequencies) { 47 t.Errorf("got %v, want %v", fm, c.wantTermFrequencies) 48 } 49 }) 50 } 51}