~jpakkane/libcolumbus/hud-rework

« back to all changes in this revision

Viewing changes to test/MatcherTest.cc

  • Committer: Jussi Pakkanen
  • Date: 2014-02-28 13:33:09 UTC
  • Revision ID: jussi.pakkanen@canonical.com-20140228133309-zdlgoq1p6okl72l4
Test that the perfect match gets picked first.

Show diffs side-by-side

added added

removed removed

Lines of Context:
264
264
    assert(matches.getDocumentID(0) == correct);
265
265
}
266
266
 
 
267
void testPerfect() {
 
268
    Corpus c;
 
269
    DocumentID correct = 1;
 
270
    DocumentID wrong = 0;
 
271
    Document d1(wrong);
 
272
    Document d2(correct);
 
273
    Word fieldName("name");
 
274
    Matcher m;
 
275
    MatchResults matches;
 
276
    WordList q = splitToWords("save");
 
277
    d1.addText(fieldName, "Save as");
 
278
    d2.addText(fieldName, "Save");
 
279
    c.addDocument(d1);
 
280
    c.addDocument(d2);
 
281
 
 
282
    m.index(c);
 
283
    matches = m.onlineMatch(q, fieldName);
 
284
    assert(matches.size() >= 1);
 
285
    assert(matches.getDocumentID(0) == correct);
 
286
}
 
287
 
267
288
int main(int /*argc*/, char **/*argv*/) {
268
289
    try {
269
290
        testMatcher();
275
296
        noCommonMatch();
276
297
        emptyMatch();
277
298
        testMatchCount();
 
299
        testPerfect();
278
300
    } catch(const std::exception &e) {
279
301
        fprintf(stderr, "Fail: %s\n", e.what());
280
302
        return 666;