export amount of active queries
[debiancodesearch.git] / index / concatn_test.go
blob84fafc3f8e025aa98cc589f98fc8697016f65ddd
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.
5 package index
7 import (
8 "io/ioutil"
9 "os"
10 "testing"
13 func TestConcatN(t *testing.T) {
14 var mergePaths1 = []string{
15 "/a",
16 "/b",
17 "/c",
20 var mergePaths2 = []string{
21 "/b",
22 "/cc",
25 var mergeFiles1 = map[string]string{
26 "/a/x": "hello world",
27 "/a/y": "goodbye world",
28 "/b/xx": "now is the time",
29 "/b/xy": "for all good men",
30 "/c/ab": "give me all the potatoes",
31 "/c/de": "or give me death now",
34 var mergeFiles2 = map[string]string{
35 "/cc": "come to the aid of his potatoes",
36 "/d/www": "world wide indeed",
37 "/d/xz": "no, not now",
38 "/d/yy": "first potatoes, now liberty?",
41 var mergeFiles3 = map[string]string{
42 "/latest": "ZZZ makes the snoring rabbit",
43 "/latest2": "aaa makes the snoring armadillo",
46 f1, _ := ioutil.TempFile("", "index-test")
47 f2, _ := ioutil.TempFile("", "index-test")
48 f3, _ := ioutil.TempFile("", "index-test")
49 f4, _ := ioutil.TempFile("", "index-test")
50 defer os.Remove(f1.Name())
51 defer os.Remove(f2.Name())
52 defer os.Remove(f4.Name())
54 out1 := f1.Name()
55 out2 := f2.Name()
56 out3 := f3.Name()
57 out4 := f4.Name()
59 buildIndex(out1, mergePaths1, mergeFiles1)
60 buildIndex(out2, mergePaths2, mergeFiles2)
61 buildIndex(out3, []string{}, mergeFiles3)
63 ConcatN(out4, out1, out2, out3)
65 ix1 := Open(out1)
66 ix2 := Open(out2)
67 ix3 := Open(out3)
68 ix4 := Open(out4)
70 nameof := func(ix *Index) string {
71 switch {
72 case ix == ix1:
73 return "ix1"
74 case ix == ix2:
75 return "ix2"
76 case ix == ix3:
77 return "ix3"
78 case ix == ix4:
79 return "ix4"
81 return "???"
84 checkFiles := func(ix *Index, l ...string) {
85 for i, s := range l {
86 if n := ix.Name(uint32(i)); n != s {
87 t.Errorf("%s: Name(%d) = %s, want %s", nameof(ix), i, n, s)
92 checkFiles(ix1, "/a/x", "/a/y", "/b/xx", "/b/xy", "/c/ab", "/c/de")
93 checkFiles(ix2, "/cc", "/d/www", "/d/xz", "/d/yy")
94 checkFiles(ix3, "/latest")
96 checkFiles(ix4, "/a/x", "/a/y", "/b/xx", "/b/xy", "/c/ab", "/c/de", "/cc", "/d/www", "/d/xz", "/d/yy", "/latest")
98 check := func(ix *Index, trig string, l ...uint32) {
99 l1 := ix.PostingList(tri(trig[0], trig[1], trig[2]))
100 if !equalList(l1, l) {
101 t.Errorf("PostingList(%s, %s) = %v, want %v", nameof(ix), trig, l1, l)
105 check(ix1, "wor", 0, 1)
106 check(ix1, "now", 2, 5)
107 check(ix1, "all", 3, 4)
109 check(ix2, "now", 2, 3)
111 check(ix3, "ZZZ", 0)
112 check(ix3, "aaa", 1)
114 check(ix4, "all", 3, 4)
115 check(ix4, "wor", 0, 1, 7)
116 check(ix4, "now", 2, 5, 8, 9)
117 check(ix4, "pot", 4, 6, 9)
118 check(ix4, "ZZZ", 10)
119 check(ix4, "aaa", 11)