aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/common/matching_elements
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2019-09-19 12:26:33 +0000
committerHåvard Pettersen <havardpe@oath.com>2019-09-19 12:31:57 +0000
commit2a8c7760f9035b81302c94a88a6b754c792eb87c (patch)
treefdbc27ef8f4965e0174433fa646cfa3384144558 /searchlib/src/tests/common/matching_elements
parentd082531b8c6244de5bc99ed887f706be3a1084df (diff)
added function identifying which elements matched
only a skeleton for now; outlines the interface between the summary generator and the matcher.
Diffstat (limited to 'searchlib/src/tests/common/matching_elements')
-rw-r--r--searchlib/src/tests/common/matching_elements/CMakeLists.txt9
-rw-r--r--searchlib/src/tests/common/matching_elements/matching_elements_test.cpp45
2 files changed, 54 insertions, 0 deletions
diff --git a/searchlib/src/tests/common/matching_elements/CMakeLists.txt b/searchlib/src/tests/common/matching_elements/CMakeLists.txt
new file mode 100644
index 00000000000..cd1d3560c15
--- /dev/null
+++ b/searchlib/src/tests/common/matching_elements/CMakeLists.txt
@@ -0,0 +1,9 @@
+# Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(searchlib_common_matching_elements_test_app TEST
+ SOURCES
+ matching_elements_test.cpp
+ DEPENDS
+ searchlib
+ gtest
+)
+vespa_add_test(NAME searchlib_common_matching_elements_test_app COMMAND searchlib_common_matching_elements_test_app)
diff --git a/searchlib/src/tests/common/matching_elements/matching_elements_test.cpp b/searchlib/src/tests/common/matching_elements/matching_elements_test.cpp
new file mode 100644
index 00000000000..e23460b83af
--- /dev/null
+++ b/searchlib/src/tests/common/matching_elements/matching_elements_test.cpp
@@ -0,0 +1,45 @@
+// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include <vespa/vespalib/gtest/gtest.h>
+#include <vespa/searchlib/common/matching_elements.h>
+
+using namespace search;
+
+namespace {
+
+std::vector<uint32_t> vec(const std::initializer_list<uint32_t> list) {
+ return std::vector<uint32_t>(list);
+}
+
+}
+
+struct MatchingElementsTest : ::testing::Test {
+ MatchingElements matches;
+ MatchingElementsTest() : matches() {
+ matches.add_matching_elements(1, "foo", vec({1, 3, 5}));
+ matches.add_matching_elements(1, "bar", vec({2, 4, 6}));
+ matches.add_matching_elements(2, "foo", vec({1, 2, 3}));
+ matches.add_matching_elements(2, "bar", vec({4, 5, 6}));
+ matches.add_matching_elements(2, "foo", vec({2, 3, 5}));
+ matches.add_matching_elements(2, "bar", vec({2, 4, 5}));
+ }
+ ~MatchingElementsTest() = default;
+};
+
+
+TEST_F(MatchingElementsTest, require_that_added_matches_can_be_looked_up) {
+ EXPECT_EQ(matches.get_matching_elements(1, "foo"), vec({1, 3, 5}));
+ EXPECT_EQ(matches.get_matching_elements(1, "bar"), vec({2, 4, 6}));
+}
+
+TEST_F(MatchingElementsTest, require_that_added_matches_are_merged) {
+ EXPECT_EQ(matches.get_matching_elements(2, "foo"), vec({1, 2, 3, 5}));
+ EXPECT_EQ(matches.get_matching_elements(2, "bar"), vec({2, 4, 5, 6}));
+}
+
+TEST_F(MatchingElementsTest, require_that_nonexisting_lookup_gives_empty_result) {
+ EXPECT_EQ(matches.get_matching_elements(1, "bogus"), vec({}));
+ EXPECT_EQ(matches.get_matching_elements(7, "foo"), vec({}));
+}
+
+GTEST_MAIN_RUN_ALL_TESTS()