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 operator==(const Xapian::MSet &first, const Xapian::MSet &second)
00112 {
00113 if ((first.get_matches_lower_bound() != second.get_matches_lower_bound()) ||
00114 (first.get_matches_upper_bound() != second.get_matches_upper_bound()) ||
00115 (first.get_matches_estimated() != second.get_matches_estimated()) ||
00116 (first.get_max_possible() != second.get_max_possible()) ||
00117 (first.size() != second.size())) {
00118 return false;
00119 }
00120 if (first.empty()) return true;
00121 return mset_range_is_same(first, 0, second, 0, first.size());
00122 }
00123
00124 static void
00125 mset_expect_order_(const Xapian::MSet &A, bool beginning,
00126 Xapian::docid d1, Xapian::docid d2, Xapian::docid d3, Xapian::docid d4,
00127 Xapian::docid d5, Xapian::docid d6, Xapian::docid d7, Xapian::docid d8,
00128 Xapian::docid d9, Xapian::docid d10, Xapian::docid d11, Xapian::docid d12)
00129 {
00130 vector<Xapian::docid> expect;
00131 if (d1) {
00132 expect.push_back(d1);
00133 if (d2) {
00134 expect.push_back(d2);
00135 if (d3) {
00136 expect.push_back(d3);
00137 if (d4) {
00138 expect.push_back(d4);
00139 if (d5) {
00140 expect.push_back(d5);
00141 if (d6) {
00142 expect.push_back(d6);
00143 if (d7) {
00144 expect.push_back(d7);
00145 if (d8) {
00146 expect.push_back(d8);
00147 if (d9) {
00148 expect.push_back(d9);
00149 if (d10) {
00150 expect.push_back(d10);
00151 if (d11) {
00152 expect.push_back(d11);
00153 if (d12) {
00154 expect.push_back(d12);
00155 }
00156 }
00157 }
00158 }
00159 }
00160 }
00161 }
00162 }
00163 }
00164 }
00165 }
00166 }
00167
00168
00169 if (beginning) {
00170 TEST_AND_EXPLAIN(A.size() >= expect.size(),
00171 "Mset is of wrong size (" << A.size()
00172 << " < " << expect.size() << "):\n"
00173 << "Full mset was: " << A << endl
00174 << "Expected order to start: {" << expect << "}");
00175 } else {
00176 TEST_AND_EXPLAIN(A.size() == expect.size(),
00177 "Mset is of wrong size (" << A.size()
00178 << " != " << expect.size() << "):\n"
00179 << "Full mset was: " << A << endl
00180 << "Expected order: {" << expect << "}");
00181 }
00182
00183 Xapian::MSetIterator j = A.begin();
00184 for (size_t i = 0; i < expect.size(); i++, j++) {
00185 TEST_AND_EXPLAIN(*j == expect[i],
00186 "Mset didn't contain expected result:\n"
00187 << "Item " << i << " was " << *j
00188 << ", expected " << expect[i] << endl
00189 << "Full mset was: " << A << endl
00190 << "Expected: {" << expect << "}");
00191 }
00192 }
00193
00194 void
00195 mset_expect_order(const Xapian::MSet &A,
00196 Xapian::docid d1, Xapian::docid d2, Xapian::docid d3, Xapian::docid d4,
00197 Xapian::docid d5, Xapian::docid d6, Xapian::docid d7, Xapian::docid d8,
00198 Xapian::docid d9, Xapian::docid d10, Xapian::docid d11, Xapian::docid d12)
00199 {
00200 mset_expect_order_(A, false, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12);
00201 }
00202
00203 void
00204 test_mset_order_equal(const Xapian::MSet &mset1, const Xapian::MSet &mset2)
00205 {
00206 TEST_AND_EXPLAIN(mset1.size() == mset2.size(),
00207 "Msets not the same size - "
00208 << mset1.size() << " != " << mset2.size());
00209 Xapian::MSetIterator i = mset1.begin();
00210 Xapian::MSetIterator j = mset2.begin();
00211 for (; i != mset1.end(); i++, j++) {
00212 TEST_AND_EXPLAIN(*i == *j,
00213 "Msets have different contents -\n" <<
00214 mset1 << "\n !=\n" << mset2);
00215 }
00216 }