summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorGeir Storli <geirstorli@yahoo.no>2019-01-10 08:36:36 +0100
committerGitHub <noreply@github.com>2019-01-10 08:36:36 +0100
commitbc78c77b555be488b9d7be155b6190a4bfe2283f (patch)
treebbf0e366f3bec766337a2013b13d3d6b0712c5d9 /searchlib
parent777e079cba9f5126e210c6e807683d86ecf3444b (diff)
parent97dabeae20fe08e2d0513d654a912ff8f8e72635 (diff)
Merge pull request #8076 from vespa-engine/arnej/fix-comparator
add test
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/fef/termfieldmodel/termfieldmodel_test.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/searchlib/src/tests/fef/termfieldmodel/termfieldmodel_test.cpp b/searchlib/src/tests/fef/termfieldmodel/termfieldmodel_test.cpp
index e689e613886..ca9e331bb62 100644
--- a/searchlib/src/tests/fef/termfieldmodel/termfieldmodel_test.cpp
+++ b/searchlib/src/tests/fef/termfieldmodel/termfieldmodel_test.cpp
@@ -286,4 +286,32 @@ TEST("require that MatchData soft_reset retains appropriate state") {
EXPECT_EQUAL(new_term->getDocId(), TermFieldMatchData::invalidId());
}
+TEST("require that compareWithExactness implements a strict weak ordering") {
+ TermFieldMatchDataPosition a(0, 1, 100, 1);
+ TermFieldMatchDataPosition b(0, 2, 100, 1);
+ TermFieldMatchDataPosition c(0, 2, 100, 1);
+ TermFieldMatchDataPosition d(0, 3, 100, 3);
+ TermFieldMatchDataPosition e(0, 3, 100, 3);
+ TermFieldMatchDataPosition f(0, 4, 100, 1);
+
+ d.setMatchExactness(0.75);
+ e.setMatchExactness(0.5);
+
+ bool (*cmp)(const TermFieldMatchDataPosition &a,
+ const TermFieldMatchDataPosition &b) = TermFieldMatchDataPosition::compareWithExactness;
+
+ EXPECT_EQUAL(true, cmp(a, b));
+ EXPECT_EQUAL(false, cmp(b, c));
+ EXPECT_EQUAL(true, cmp(c, d));
+ EXPECT_EQUAL(true, cmp(d, e));
+ EXPECT_EQUAL(true, cmp(e, f));
+
+ EXPECT_EQUAL(false, cmp(b, a));
+ EXPECT_EQUAL(false, cmp(c, b));
+ EXPECT_EQUAL(false, cmp(d, c));
+ EXPECT_EQUAL(false, cmp(e, d));
+ EXPECT_EQUAL(false, cmp(f, e));
+}
+
+
TEST_MAIN() { TEST_RUN_ALL(); }