-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindexer_test.go
More file actions
53 lines (46 loc) · 1.11 KB
/
indexer_test.go
File metadata and controls
53 lines (46 loc) · 1.11 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
package tinysearch
import (
"reflect"
"strings"
"testing"
)
func TestUpdate(t *testing.T) {
collection := []string{
"Do you quarrel, sir?",
"Quarrel sir! no, sir!",
"No better.",
"Well, sir",
}
indexer := NewIndexer(NewTokenizer()) // ❶ インデックス構築器の初期化
for i, doc := range collection {
// ❷ インデックスにドキュメントを追加
indexer.update(DocumentID(i), strings.NewReader(doc))
}
actual := indexer.index
expected := &Index{
Dictionary: map[string]PostingsList{
"better": NewPostingsList(
NewPosting(2, 1)),
"do": NewPostingsList(
NewPosting(0, 0)),
"no": NewPostingsList(
NewPosting(1, 2),
NewPosting(2, 0)),
"quarrel": NewPostingsList(
NewPosting(0, 2),
NewPosting(1, 0)),
"sir": NewPostingsList(NewPosting(0, 3),
NewPosting(1, 1, 3),
NewPosting(3, 1)),
"well": NewPostingsList(
NewPosting(3, 0)),
"you": NewPostingsList(
NewPosting(0, 1)),
},
TotalDocsCount: 4,
}
if !reflect.DeepEqual(actual, expected) {
t.Errorf("wrong index. \n\nwant: \n%v\n\n got:\n%v\n",
expected, actual)
}
}