Index: tests/Makefile.am
===================================================================
--- tests/Makefile.am	(revision 11137)
+++ tests/Makefile.am	(working copy)
@@ -88,9 +88,19 @@
 
 noinst_HEADERS = apitest.h
 
-collated_apitest_sources = api_anydb.cc api_db.cc api_generated.cc api_nodb.cc \
- api_posdb.cc api_replicate.cc api_sorting.cc api_transdb.cc api_unicode.cc \
- api_valuestats.cc api_wrdb.cc
+collated_apitest_sources = \
+ api_anydb.cc \
+ api_db.cc \
+ api_generated.cc \
+ api_nodb.cc \
+ api_percentages.cc \
+ api_posdb.cc \
+ api_replicate.cc \
+ api_sorting.cc \
+ api_transdb.cc \
+ api_unicode.cc \
+ api_valuestats.cc \
+ api_wrdb.cc
 
 apitest_SOURCES = apitest.cc $(collated_apitest_sources) \
  api_all.h api_collated.h $(testharness_sources)
@@ -166,6 +176,7 @@
 	testdata/apitest_allterms4.txt \
 	testdata/apitest_poslist.txt \
 	testdata/apitest_manydocs.txt \
+	testdata/apitest_sortconsist.txt \
 	testdata/apitest_sortrel.txt \
 	testdata/etext.txt \
 	testdata/flint-0.9.9/flicklock \
Index: tests/testdata/apitest_sortconsist.txt
===================================================================
--- tests/testdata/apitest_sortconsist.txt	(revision 0)
+++ tests/testdata/apitest_sortconsist.txt	(revision 0)
@@ -0,0 +1,5 @@
+A foo
+
+A foo
+
+B foo foo

Property changes on: tests/testdata/apitest_sortconsist.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Index: tests/api_percentages.cc
===================================================================
--- tests/api_percentages.cc	(revision 0)
+++ tests/api_percentages.cc	(revision 0)
@@ -0,0 +1,67 @@
+/** @file api_percentages.cc
+ * @brief Tests of percentage calculations.
+ */
+/* Copyright 2008 Lemur Consulting Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include <config.h>
+
+#include "api_percentages.h"
+
+#include <xapian.h>
+
+#include "apitest.h"
+#include "testutils.h"
+
+using namespace std;
+
+// #######################################################################
+// # Tests start here
+
+// Test that percentages reported are the same regardless of which part of the
+// mset is returned, for sort-by-value search.  Regression test for a bug in
+// 1.0.7 and earlier with returned percentages.
+DEFINE_TESTCASE(consistency3, backend) {
+    Xapian::Database db(get_database("apitest_sortconsist"));
+    Xapian::Enquire enquire(db);
+    enquire.set_query(Xapian::Query("foo"));
+    enquire.set_sort_by_value(1, 0);
+    Xapian::doccount lots = 3;
+    Xapian::MSet bigmset = enquire.get_mset(0, lots);
+    TEST_EQUAL(bigmset.size(), lots);
+    for (Xapian::doccount start = 0; start < lots; ++start) {
+	tout << *bigmset[start] << ":" << bigmset[start].get_weight() << ":" << bigmset[start].get_percent() << "%" << endl;
+	for (Xapian::doccount size = 0; size < lots - start; ++size) {
+	    Xapian::MSet mset = enquire.get_mset(start, size);
+	    if (mset.size()) {
+		TEST_EQUAL(start + mset.size(),
+			   min(start + size, bigmset.size()));
+	    } else if (size) {
+		TEST(start >= bigmset.size());
+	    }
+	    for (Xapian::doccount i = 0; i < mset.size(); ++i) {
+		TEST_EQUAL(*mset[i], *bigmset[start + i]);
+		TEST_EQUAL_DOUBLE(mset[i].get_weight(),
+				  bigmset[start + i].get_weight());
+		TEST_EQUAL_DOUBLE(mset[i].get_percent(),
+				  bigmset[start + i].get_percent());
+	    }
+	}
+    }
+    TEST(0);
+    return true;
+}

Property changes on: tests/api_percentages.cc
___________________________________________________________________
Name: svn:eol-style
   + native

