2 * @brief Xapian-specific test helper functions.
4 /* Copyright 1999,2000,2001 BrightStation PLC
5 * Copyright 2003,2004,2007,2008,2009,2015 Olly Betts
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
25 #include "testutils.h"
27 #include "testsuite.h"
35 operator<<(ostream
&os
, const vector
<Xapian::docid
> &ints
)
37 copy(ints
.begin(), ints
.end(),
38 ostream_iterator
<Xapian::docid
>(os
, ", "));
42 // ######################################################################
43 // Useful comparison operators
46 mset_range_is_same(const Xapian::MSet
&mset1
, unsigned int first1
,
47 const Xapian::MSet
&mset2
, unsigned int first2
,
50 TEST_AND_EXPLAIN(mset1
.size() >= first1
+ count
,
51 "mset1 is too small: expected at least " <<
52 (first1
+ count
) << " items, got " <<
55 TEST_AND_EXPLAIN(mset2
.size() >= first2
+ count
,
56 "mset2 is too small: expected at least " <<
57 (first2
+ count
) << " items, got " <<
60 Xapian::MSetIterator i
= mset1
[first1
];
61 Xapian::MSetIterator j
= mset2
[first2
];
63 for (unsigned int l
= 0; l
< count
; ++l
) {
65 tout
<< "docids differ at item " << (l
+ 1) << " in range: "
66 << *i
<< " != " << *j
<< "\n";
69 // FIXME: don't use internal macro here...
70 if (!TEST_EQUAL_DOUBLE_(i
.get_weight(), j
.get_weight())) {
71 tout
<< "weights differ at item " << (l
+ 1) << " in range: "
72 << i
.get_weight() << " != " << j
.get_weight() << "\n";
82 mset_range_is_same(const Xapian::MSet
& mset
, unsigned int first
,
83 const pair
<Xapian::docid
, double> to_compare
[],
86 TEST_AND_EXPLAIN(mset
.size() >= first
+ count
- 1,
87 "mset is too small: expected at least " <<
88 (first
+ count
- 1) << " items, got " <<
91 Xapian::MSetIterator i
= mset
[first
];
93 for (unsigned int l
= 0; l
< count
; ++l
) {
94 if (*i
!= to_compare
[l
].first
) {
95 tout
<< "docids differ at item " << (l
+ 1) << " in range: "
96 << *i
<< " != " << to_compare
[l
].first
<< "\n";
99 // FIXME: don't use internal macro here...
100 if (!TEST_EQUAL_DOUBLE_(i
.get_weight(), to_compare
[l
].second
)) {
101 tout
<< "weights differ at item " << (l
+ 1) << " in range: "
102 << i
.get_weight() << " != " << to_compare
[l
].second
<< "\n";
111 mset_range_is_same_weights(const Xapian::MSet
&mset1
, unsigned int first1
,
112 const Xapian::MSet
&mset2
, unsigned int first2
,
115 TEST_AND_EXPLAIN(mset1
.size() >= first1
+ count
- 1,
116 "mset1 is too small: expected at least " <<
117 (first1
+ count
- 1) << " items, got " <<
118 mset1
.size() << ".");
120 TEST_AND_EXPLAIN(mset2
.size() >= first2
+ count
- 1,
121 "mset2 is too small: expected at least " <<
122 (first2
+ count
- 1) << " items, got " <<
123 mset2
.size() << ".");
125 Xapian::MSetIterator i
= mset1
[first1
];
126 Xapian::MSetIterator j
= mset2
[first2
];
128 for (unsigned int l
= 0; l
< count
; ++l
) {
129 // FIXME: don't use internal macro here...
130 if (!TEST_EQUAL_DOUBLE_(i
.get_weight(), j
.get_weight())) {
131 tout
<< "weights differ at item " << (l
+ 1) << " in range: "
132 << i
.get_weight() << " != " << j
.get_weight() << "\n";
141 bool operator==(const Xapian::MSet
&first
, const Xapian::MSet
&second
)
143 if ((first
.get_matches_lower_bound() != second
.get_matches_lower_bound()) ||
144 (first
.get_matches_upper_bound() != second
.get_matches_upper_bound()) ||
145 (first
.get_matches_estimated() != second
.get_matches_estimated()) ||
146 (first
.get_max_possible() != second
.get_max_possible()) ||
147 (first
.size() != second
.size())) {
150 if (first
.empty()) return true;
151 return mset_range_is_same(first
, 0, second
, 0, first
.size());
155 mset_expect_order_(const Xapian::MSet
&A
, bool beginning
,
156 Xapian::docid d1
, Xapian::docid d2
, Xapian::docid d3
, Xapian::docid d4
,
157 Xapian::docid d5
, Xapian::docid d6
, Xapian::docid d7
, Xapian::docid d8
,
158 Xapian::docid d9
, Xapian::docid d10
, Xapian::docid d11
, Xapian::docid d12
)
160 vector
<Xapian::docid
> expect
;
162 expect
.push_back(d1
);
164 expect
.push_back(d2
);
166 expect
.push_back(d3
);
168 expect
.push_back(d4
);
170 expect
.push_back(d5
);
172 expect
.push_back(d6
);
174 expect
.push_back(d7
);
176 expect
.push_back(d8
);
178 expect
.push_back(d9
);
180 expect
.push_back(d10
);
182 expect
.push_back(d11
);
184 expect
.push_back(d12
);
200 TEST_AND_EXPLAIN(A
.size() >= expect
.size(),
201 "Mset is of wrong size (" << A
.size()
202 << " < " << expect
.size() << "):\n"
203 << "Full mset was: " << A
<< endl
204 << "Expected order to start: {" << expect
<< "}");
206 TEST_AND_EXPLAIN(A
.size() == expect
.size(),
207 "Mset is of wrong size (" << A
.size()
208 << " != " << expect
.size() << "):\n"
209 << "Full mset was: " << A
<< endl
210 << "Expected order: {" << expect
<< "}");
213 Xapian::MSetIterator j
= A
.begin();
214 for (size_t i
= 0; i
< expect
.size(); ++i
, ++j
) {
215 TEST_AND_EXPLAIN(*j
== expect
[i
],
216 "Mset didn't contain expected result:\n"
217 << "Item " << i
<< " was " << *j
218 << ", expected " << expect
[i
] << endl
219 << "Full mset was: " << A
<< endl
220 << "Expected: {" << expect
<< "}");
225 mset_expect_order(const Xapian::MSet
&A
,
226 Xapian::docid d1
, Xapian::docid d2
, Xapian::docid d3
, Xapian::docid d4
,
227 Xapian::docid d5
, Xapian::docid d6
, Xapian::docid d7
, Xapian::docid d8
,
228 Xapian::docid d9
, Xapian::docid d10
, Xapian::docid d11
, Xapian::docid d12
)
230 mset_expect_order_(A
, false, d1
, d2
, d3
, d4
, d5
, d6
, d7
, d8
, d9
, d10
, d11
, d12
);
234 test_mset_order_equal(const Xapian::MSet
&mset1
, const Xapian::MSet
&mset2
)
236 TEST_AND_EXPLAIN(mset1
.size() == mset2
.size(),
237 "Msets not the same size - "
238 << mset1
.size() << " != " << mset2
.size());
239 Xapian::MSetIterator i
= mset1
.begin();
240 Xapian::MSetIterator j
= mset2
.begin();
241 for (; i
!= mset1
.end(); ++i
, ++j
) {
242 TEST_AND_EXPLAIN(*i
== *j
,
243 "Msets have different contents -\n" <<
244 mset1
<< "\n !=\n" << mset2
);