-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpostings_test.go
46 lines (35 loc) · 889 Bytes
/
postings_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
package postings
import (
"reflect"
"testing"
)
func TestIntersect(t *testing.T) {
a := Postings{1, 1, 2, 4, 6}
b := Postings{1, 1, 3, 3, 4, 6, 10}
got := intersect(nil, newIter(a), newIter(b))
want := Postings{1, 4, 6}
if !reflect.DeepEqual(want, got) {
t.Errorf("intersect()=%v, want=%v", got, want)
}
}
func TestQuery(t *testing.T) {
idx := NewIndex(nil)
docs := []DocID{}
docs = append(docs, idx.AddDocument([]TermID{1, 2, 3}))
docs = append(docs, idx.AddDocument([]TermID{1, 2, 4}))
docs = append(docs, idx.AddDocument([]TermID{1, 2, 5}))
tests := []struct {
q []TermID
want Postings
}{
{[]TermID{2}, Postings{0, 1, 2}},
{[]TermID{3}, Postings{0}},
{[]TermID{1, 4}, Postings{1}},
}
for _, tt := range tests {
got := Query(idx, tt.q)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Query(%v)=%v, want %v", tt.q, got, tt.want)
}
}
}