Ticket #216: bestpercentbug.patch

File bestpercentbug.patch, 4.2 KB (added by Richard Boulton, 14 years ago)

Updated testcase

  • tests/Makefile.am

     
    8888
    8989noinst_HEADERS = apitest.h
    9090
    91 collated_apitest_sources = api_anydb.cc api_db.cc api_generated.cc api_nodb.cc \
    92  api_posdb.cc api_replicate.cc api_sorting.cc api_transdb.cc api_unicode.cc \
    93  api_valuestats.cc api_wrdb.cc
     91collated_apitest_sources = \
     92 api_anydb.cc \
     93 api_db.cc \
     94 api_generated.cc \
     95 api_nodb.cc \
     96 api_percentages.cc \
     97 api_posdb.cc \
     98 api_replicate.cc \
     99 api_sorting.cc \
     100 api_transdb.cc \
     101 api_unicode.cc \
     102 api_valuestats.cc \
     103 api_wrdb.cc
    94104
    95105apitest_SOURCES = apitest.cc $(collated_apitest_sources) \
    96106 api_all.h api_collated.h $(testharness_sources)
     
    166176        testdata/apitest_allterms4.txt \
    167177        testdata/apitest_poslist.txt \
    168178        testdata/apitest_manydocs.txt \
     179        testdata/apitest_sortconsist.txt \
    169180        testdata/apitest_sortrel.txt \
    170181        testdata/etext.txt \
    171182        testdata/flint-0.9.9/flicklock \
  • tests/testdata/apitest_sortconsist.txt

     
     1A foo
     2
     3A foo
     4
     5B foo foo
  • tests/api_percentages.cc

    Property changes on: tests/testdata/apitest_sortconsist.txt
    ___________________________________________________________________
    Name: svn:eol-style
       + native
    
     
     1/** @file api_percentages.cc
     2 * @brief Tests of percentage calculations.
     3 */
     4/* Copyright 2008 Lemur Consulting Ltd
     5 *
     6 * This program is free software; you can redistribute it and/or modify
     7 * it under the terms of the GNU General Public License as published by
     8 * the Free Software Foundation; either version 2 of the License, or
     9 * (at your option) any later version.
     10 *
     11 * This program is distributed in the hope that it will be useful,
     12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14 * GNU General Public License for more details.
     15 *
     16 * You should have received a copy of the GNU General Public License
     17 * along with this program; if not, write to the Free Software
     18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
     19 */
     20
     21#include <config.h>
     22
     23#include "api_percentages.h"
     24
     25#include <xapian.h>
     26
     27#include "apitest.h"
     28#include "testutils.h"
     29
     30using namespace std;
     31
     32// #######################################################################
     33// # Tests start here
     34
     35// Test that percentages reported are the same regardless of which part of the
     36// mset is returned, for sort-by-value search.  Regression test for a bug in
     37// 1.0.7 and earlier with returned percentages.
     38DEFINE_TESTCASE(consistency3, backend) {
     39    Xapian::Database db(get_database("apitest_sortconsist"));
     40    Xapian::Enquire enquire(db);
     41    enquire.set_query(Xapian::Query("foo"));
     42    enquire.set_sort_by_value(1, 0);
     43    Xapian::doccount lots = 3;
     44    Xapian::MSet bigmset = enquire.get_mset(0, lots);
     45    TEST_EQUAL(bigmset.size(), lots);
     46    for (Xapian::doccount start = 0; start < lots; ++start) {
     47        tout << *bigmset[start] << ":" << bigmset[start].get_weight() << ":" << bigmset[start].get_percent() << "%" << endl;
     48        for (Xapian::doccount size = 0; size < lots - start; ++size) {
     49            Xapian::MSet mset = enquire.get_mset(start, size);
     50            if (mset.size()) {
     51                TEST_EQUAL(start + mset.size(),
     52                           min(start + size, bigmset.size()));
     53            } else if (size) {
     54                TEST(start >= bigmset.size());
     55            }
     56            for (Xapian::doccount i = 0; i < mset.size(); ++i) {
     57                TEST_EQUAL(*mset[i], *bigmset[start + i]);
     58                TEST_EQUAL_DOUBLE(mset[i].get_weight(),
     59                                  bigmset[start + i].get_weight());
     60                TEST_EQUAL_DOUBLE(mset[i].get_percent(),
     61                                  bigmset[start + i].get_percent());
     62            }
     63        }
     64    }
     65    TEST(0);
     66    return true;
     67}