-
Notifications
You must be signed in to change notification settings - Fork 5
/
index_test.go
75 lines (69 loc) · 1.7 KB
/
index_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package stalefish
import (
"fmt"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestPushBack(t *testing.T) {
t.Parallel()
cases := []struct {
postings *Postings
inserted *Postings
expected *Postings
}{
{
postings: NewPostings(1, []uint64{}, NewPostings(2, []uint64{}, NewPostings(3, []uint64{}, NewPostings(4, []uint64{}, nil)))),
inserted: NewPostings(0, []uint64{}, nil),
expected: NewPostings(1, []uint64{}, NewPostings(0, []uint64{}, NewPostings(2, []uint64{}, NewPostings(3, []uint64{}, NewPostings(4, []uint64{}, nil))))),
},
}
for _, tt := range cases {
t.Run(fmt.Sprintf("postings = %v, inserted = %v, expected = %v,", tt.postings, tt.inserted, tt.expected), func(t *testing.T) {
// When
tt.postings.PushBack(tt.inserted)
// Then
if diff := cmp.Diff(tt.postings, tt.expected); diff != "" {
t.Errorf("Diff: (-got +want)\n%s", diff)
}
})
}
}
func TestAppearanceCountInDocument(t *testing.T) {
ps := NewPostings(1, []uint64{0}, NewPostings(2, []uint64{1, 2}, NewPostings(3, []uint64{3, 4, 5}, nil)))
tests := []struct {
postings *Postings
docID DocumentID
want int
}{
{
postings: ps,
docID: 1,
want: 1,
},
{
postings: ps,
docID: 2,
want: 2,
},
{
postings: ps,
docID: 3,
want: 3,
},
{
postings: ps,
docID: 4,
want: 0,
},
}
for _, tt := range tests {
t.Run(fmt.Sprintf("postings = %v, docID = %v, want = %v", tt.postings, tt.docID, tt.want), func(t *testing.T) {
p := PostingList{
Postings: tt.postings,
}
if got := p.AppearanceCountInDocument(tt.docID); got != tt.want {
t.Errorf("PostingList.AppearanceCountInDocument() = %v, want %v", got, tt.want)
}
})
}
}