1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 var postFiles
= map[string]string{
15 "file1": "Google Code Search",
16 "file2": "Google Code Project Hosting",
17 "file3": "Google Web Search",
20 func tri(x
, y
, z
byte) uint32 {
21 return uint32(x
)<<16 |
uint32(y
)<<8 |
uint32(z
)
24 func TestTrivialPosting(t
*testing
.T
) {
25 f
, _
:= ioutil
.TempFile("", "index-test")
26 defer os
.Remove(f
.Name())
28 buildIndex(out
, nil, postFiles
)
30 if l
:= ix
.PostingList(tri('S', 'e', 'a')); !equalList(l
, []uint32{1, 3}) {
31 t
.Errorf("PostingList(Sea) = %v, want [1 3]", l
)
33 if l
:= ix
.PostingList(tri('G', 'o', 'o')); !equalList(l
, []uint32{1, 2, 3}) {
34 t
.Errorf("PostingList(Goo) = %v, want [1 2 3]", l
)
36 if l
:= ix
.PostingAnd(ix
.PostingList(tri('S', 'e', 'a')), tri('G', 'o', 'o')); !equalList(l
, []uint32{1, 3}) {
37 t
.Errorf("PostingList(Sea&Goo) = %v, want [1 3]", l
)
39 if l
:= ix
.PostingAnd(ix
.PostingList(tri('G', 'o', 'o')), tri('S', 'e', 'a')); !equalList(l
, []uint32{1, 3}) {
40 t
.Errorf("PostingList(Goo&Sea) = %v, want [1 3]", l
)
42 if l
:= ix
.PostingOr(ix
.PostingList(tri('S', 'e', 'a')), tri('G', 'o', 'o')); !equalList(l
, []uint32{1, 2, 3}) {
43 t
.Errorf("PostingList(Sea|Goo) = %v, want [1 2 3]", l
)
45 if l
:= ix
.PostingOr(ix
.PostingList(tri('G', 'o', 'o')), tri('S', 'e', 'a')); !equalList(l
, []uint32{1, 2, 3}) {
46 t
.Errorf("PostingList(Goo|Sea) = %v, want [1 2 3]", l
)
50 func equalList(x
, y
[]uint32) bool {
54 for i
, xi
:= range x
{