00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <config.h>
00023
00024 #include "testutils.h"
00025
00026 #include "testsuite.h"
00027
00028 #include <fstream>
00029 #include <vector>
00030
00031 using namespace std;
00032
00033 ostream &
00034 operator<<(ostream &os, const vector<unsigned int> &ints)
00035 {
00036 copy(ints.begin(), ints.end(),
00037 ostream_iterator<unsigned int>(os, ", "));
00038 return os;
00039 }
00040
00041
00042
00043
00044 bool
00045 mset_range_is_same(const Xapian::MSet &mset1, unsigned int first1,
00046 const Xapian::MSet &mset2, unsigned int first2,
00047 unsigned int count)
00048 {
00049 TEST_AND_EXPLAIN(mset1.size() >= first1 + count - 1,
00050 "mset1 is too small: expected at least " <<
00051 (first1 + count - 1) << " items, got " <<
00052 mset1.size() << ".");
00053
00054 TEST_AND_EXPLAIN(mset2.size() >= first2 + count - 1,
00055 "mset2 is too small: expected at least " <<
00056 (first2 + count - 1) << " items, got " <<
00057 mset2.size() << ".");
00058
00059 Xapian::MSetIterator i = mset1[first1];
00060 Xapian::MSetIterator j = mset2[first2];
00061
00062 for (unsigned int l = 0; l < count; ++l) {
00063 if (*i != *j) {
00064 tout << "docids differ at item " << (l + 1) << " in range: "
00065 << *i << " != " << *j << "\n";
00066 return false;
00067 }
00068
00069 if (!TEST_EQUAL_DOUBLE_(i.get_weight(), j.get_weight())) {
00070 tout << "weights differ at item " << (l + 1) << " in range: "
00071 << i.get_weight() << " != " << j.get_weight() << "\n";
00072 return false;
00073 }
00074 ++i;
00075 ++j;
00076 }
00077 return true;
00078 }
00079
00080 bool
00081 mset_range_is_same_weights(const Xapian::MSet &mset1, unsigned int first1,
00082 const Xapian::MSet &mset2, unsigned int first2,
00083 unsigned int count)
00084 {
00085 TEST_AND_EXPLAIN(mset1.size() >= first1 + count - 1,
00086 "mset1 is too small: expected at least " <<
00087 (first1 + count - 1) << " items, got " <<
00088 mset1.size() << ".");
00089
00090 TEST_AND_EXPLAIN(mset2.size() >= first2 + count - 1,
00091 "mset2 is too small: expected at least " <<
00092 (first2 + count - 1) << " items, got " <<
00093 mset2.size() << ".");
00094
00095 Xapian::MSetIterator i = mset1[first1];
00096 Xapian::MSetIterator j = mset2[first2];
00097
00098 for (unsigned int l = 0; l < count; ++l) {
00099
00100 if (!TEST_EQUAL_DOUBLE_(i.get_weight(), j.get_weight())) {
00101 tout << "weights differ at item " << (l + 1) << " in range: "
00102 << i.get_weight() << " != " << j.get_weight() << "\n";
00103 return false;
00104 }
00105 ++i;
00106 ++j;
00107 }
00108 return true;
00109 }
00110
00111 bool
00112 mset_range_is_same_percents(const Xapian::MSet &mset1, unsigned int first1,
00113 const Xapian::MSet &mset2, unsigned int first2,
00114 unsigned int count)
00115 {
00116 TEST_AND_EXPLAIN(mset1.size() >= first1 + count - 1,
00117 "mset1 is too small: expected at least " <<
00118 (first1 + count - 1) << " items, got " <<
00119 mset1.size() << ".");
00120
00121 TEST_AND_EXPLAIN(mset2.size() >= first2 + count - 1,
00122 "mset2 is too small: expected at least " <<
00123 (first2 + count - 1) << " items, got " <<
00124 mset2.size() << ".");
00125
00126 Xapian::MSetIterator i = mset1[first1];
00127 Xapian::MSetIterator j = mset2[first2];
00128
00129 for (unsigned int l = 0; l < count; ++l) {
00130 if (i.get_percent() != j.get_percent()) {
00131 tout << i.get_percent() << "% != " << j.get_percent() << "%\n";
00132 return false;
00133 }
00134 ++i;
00135 ++j;
00136 }
00137 return true;
00138 }
00139
00140 bool operator==(const Xapian::MSet &first, const Xapian::MSet &second)
00141 {
00142 if ((first.get_matches_lower_bound() != second.get_matches_lower_bound()) ||
00143 (first.get_matches_upper_bound() != second.get_matches_upper_bound()) ||
00144 (first.get_matches_estimated() != second.get_matches_estimated()) ||
00145 (first.get_max_possible() != second.get_max_possible()) ||
00146 (first.size() != second.size())) {
00147 return false;
00148 }
00149 if (first.empty()) return true;
00150 return mset_range_is_same(first, 0, second, 0, first.size());
00151 }
00152
00153 static void
00154 mset_expect_order_(const Xapian::MSet &A, bool beginning,
00155 Xapian::docid d1, Xapian::docid d2, Xapian::docid d3, Xapian::docid d4,
00156 Xapian::docid d5, Xapian::docid d6, Xapian::docid d7, Xapian::docid d8,
00157 Xapian::docid d9, Xapian::docid d10, Xapian::docid d11, Xapian::docid d12)
00158 {
00159 vector<Xapian::docid> expect;
00160 if (d1) {
00161 expect.push_back(d1);
00162 if (d2) {
00163 expect.push_back(d2);
00164 if (d3) {
00165 expect.push_back(d3);
00166 if (d4) {
00167 expect.push_back(d4);
00168 if (d5) {
00169 expect.push_back(d5);
00170 if (d6) {
00171 expect.push_back(d6);
00172 if (d7) {
00173 expect.push_back(d7);
00174 if (d8) {
00175 expect.push_back(d8);
00176 if (d9) {
00177 expect.push_back(d9);
00178 if (d10) {
00179 expect.push_back(d10);
00180 if (d11) {
00181 expect.push_back(d11);
00182 if (d12) {
00183 expect.push_back(d12);
00184 }
00185 }
00186 }
00187 }
00188 }
00189 }
00190 }
00191 }
00192 }
00193 }
00194 }
00195 }
00196
00197
00198 if (beginning) {
00199 TEST_AND_EXPLAIN(A.size() >= expect.size(),
00200 "Mset is of wrong size (" << A.size()
00201 << " < " << expect.size() << "):\n"
00202 << "Full mset was: " << A << endl
00203 << "Expected order to start: {" << expect << "}");
00204 } else {
00205 TEST_AND_EXPLAIN(A.size() == expect.size(),
00206 "Mset is of wrong size (" << A.size()
00207 << " != " << expect.size() << "):\n"
00208 << "Full mset was: " << A << endl
00209 << "Expected order: {" << expect << "}");
00210 }
00211
00212 Xapian::MSetIterator j = A.begin();
00213 for (size_t i = 0; i < expect.size(); i++, j++) {
00214 TEST_AND_EXPLAIN(*j == expect[i],
00215 "Mset didn't contain expected result:\n"
00216 << "Item " << i << " was " << *j
00217 << ", expected " << expect[i] << endl
00218 << "Full mset was: " << A << endl
00219 << "Expected: {" << expect << "}");
00220 }
00221 }
00222
00223 void
00224 mset_expect_order(const Xapian::MSet &A,
00225 Xapian::docid d1, Xapian::docid d2, Xapian::docid d3, Xapian::docid d4,
00226 Xapian::docid d5, Xapian::docid d6, Xapian::docid d7, Xapian::docid d8,
00227 Xapian::docid d9, Xapian::docid d10, Xapian::docid d11, Xapian::docid d12)
00228 {
00229 mset_expect_order_(A, false, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12);
00230 }
00231
00232 void
00233 test_mset_order_equal(const Xapian::MSet &mset1, const Xapian::MSet &mset2)
00234 {
00235 TEST_AND_EXPLAIN(mset1.size() == mset2.size(),
00236 "Msets not the same size - "
00237 << mset1.size() << " != " << mset2.size());
00238 Xapian::MSetIterator i = mset1.begin();
00239 Xapian::MSetIterator j = mset2.begin();
00240 for (; i != mset1.end(); i++, j++) {
00241 TEST_AND_EXPLAIN(*i == *j,
00242 "Msets have different contents -\n" <<
00243 mset1 << "\n !=\n" << mset2);
00244 }
00245 }