LCOV - code coverage report
Current view: top level - home/olly/git/atia-xapian/xapian-core/tests - api_stem.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core r Lines: 22 24 91.7 %
Date: 2011-08-21 Functions: 6 8 75.0 %
Branches: 13 42 31.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file api_stem.cc
       2                 :            :  * @brief Test the stemming API
       3                 :            :  */
       4                 :            : /* Copyright (C) 2010 Olly Betts
       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_stem.h"
      24                 :            : 
      25                 :            : #include <xapian.h>
      26                 :            : 
      27                 :            : #include "apitest.h"
      28                 :            : #include "testsuite.h"
      29                 :            : #include "testutils.h"
      30                 :            : 
      31                 :            : using namespace std;
      32                 :            : 
      33 [ +  - ][ #  # ]:          2 : class MyStemImpl : public Xapian::StemImplementation {
      34                 :          3 :     string operator()(const string & word) {
      35                 :          3 :         return word.substr(0, 3);
      36                 :            :     }
      37                 :            : 
      38                 :          0 :     string get_description() const {
      39                 :          0 :         return "MyStem()";
      40                 :            :     }
      41                 :            : };
      42                 :            : 
      43                 :            : /// Test user stemming algorithms.
      44                 :          1 : DEFINE_TESTCASE(stem1, !backend) {
      45                 :          1 :     Xapian::Stem st(new MyStemImpl);
      46                 :            : 
      47 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(st("a"), "a");
      48 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(st("foo"), "foo");
      49 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(st("food"), "foo");
      50                 :            : 
      51                 :          1 :     return true;
      52                 :            : }
      53                 :            : 
      54                 :            : /// New feature in 1.0.21/1.2.1 - "nb" and "nn" select the Norwegian stemmer.
      55                 :          1 : DEFINE_TESTCASE(stem2, !backend) {
      56                 :          1 :     Xapian::Stem st_norwegian("norwegian");
      57 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(st_norwegian.get_description(),
      58                 :            :                Xapian::Stem("nb").get_description());
      59 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(st_norwegian.get_description(),
      60                 :            :                Xapian::Stem("nn").get_description());
      61 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(st_norwegian.get_description(),
      62                 :            :                Xapian::Stem("no").get_description());
      63 [ -  + ][ #  # ]:          1 :     TEST_NOT_EQUAL(st_norwegian.get_description(),
      64                 :            :                    Xapian::Stem("en").get_description());
      65                 :          1 :     return true;
      66                 :            : }
      67                 :            : 
      68                 :            : // Provides coverage for the switch in api/stem.cc.
      69                 :          1 : DEFINE_TESTCASE(stemlangs2, !backend) {
      70                 :          1 :     string lang("xdummy");
      71         [ +  + ]:        257 :     for (unsigned ch = 0; ch <= 255; ++ch) {
      72                 :        256 :         lang[0] = ch;
      73 [ +  - ][ -  + ]:        512 :         TEST_EXCEPTION(Xapian::InvalidArgumentError, Xapian::Stem stem(lang));
         [ #  # ][ -  + ]
      74                 :            :     }
      75                 :          1 :     return true;
      76                 :            : }

Generated by: LCOV version 1.8