summaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/queryeval/weak_and_heap
diff options
context:
space:
mode:
Diffstat (limited to 'searchlib/src/tests/queryeval/weak_and_heap')
-rw-r--r--searchlib/src/tests/queryeval/weak_and_heap/.gitignore1
-rw-r--r--searchlib/src/tests/queryeval/weak_and_heap/CMakeLists.txt8
-rw-r--r--searchlib/src/tests/queryeval/weak_and_heap/DESC1
-rw-r--r--searchlib/src/tests/queryeval/weak_and_heap/FILES1
-rw-r--r--searchlib/src/tests/queryeval/weak_and_heap/weak_and_heap_test.cpp101
5 files changed, 112 insertions, 0 deletions
diff --git a/searchlib/src/tests/queryeval/weak_and_heap/.gitignore b/searchlib/src/tests/queryeval/weak_and_heap/.gitignore
new file mode 100644
index 00000000000..b10f1cb370d
--- /dev/null
+++ b/searchlib/src/tests/queryeval/weak_and_heap/.gitignore
@@ -0,0 +1 @@
+searchlib_weak_and_heap_test_app
diff --git a/searchlib/src/tests/queryeval/weak_and_heap/CMakeLists.txt b/searchlib/src/tests/queryeval/weak_and_heap/CMakeLists.txt
new file mode 100644
index 00000000000..cacf4987aff
--- /dev/null
+++ b/searchlib/src/tests/queryeval/weak_and_heap/CMakeLists.txt
@@ -0,0 +1,8 @@
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(searchlib_weak_and_heap_test_app
+ SOURCES
+ weak_and_heap_test.cpp
+ DEPENDS
+ searchlib
+)
+vespa_add_test(NAME searchlib_weak_and_heap_test_app COMMAND searchlib_weak_and_heap_test_app)
diff --git a/searchlib/src/tests/queryeval/weak_and_heap/DESC b/searchlib/src/tests/queryeval/weak_and_heap/DESC
new file mode 100644
index 00000000000..447bfc21e7c
--- /dev/null
+++ b/searchlib/src/tests/queryeval/weak_and_heap/DESC
@@ -0,0 +1 @@
+weak_and_heap test. Take a look at weak_and_heap_test.cpp for details.
diff --git a/searchlib/src/tests/queryeval/weak_and_heap/FILES b/searchlib/src/tests/queryeval/weak_and_heap/FILES
new file mode 100644
index 00000000000..05d3f4c5df0
--- /dev/null
+++ b/searchlib/src/tests/queryeval/weak_and_heap/FILES
@@ -0,0 +1 @@
+weak_and_heap_test.cpp
diff --git a/searchlib/src/tests/queryeval/weak_and_heap/weak_and_heap_test.cpp b/searchlib/src/tests/queryeval/weak_and_heap/weak_and_heap_test.cpp
new file mode 100644
index 00000000000..ee44abf2b27
--- /dev/null
+++ b/searchlib/src/tests/queryeval/weak_and_heap/weak_and_heap_test.cpp
@@ -0,0 +1,101 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/fastos/fastos.h>
+#include <vespa/vespalib/testkit/test_kit.h>
+#include <vespa/searchlib/queryeval/wand/weak_and_heap.h>
+
+using namespace search::queryeval;
+typedef wand::score_t score_t;
+
+struct Scores : public std::vector<score_t> {
+ Scores &s(score_t val) {
+ push_back(val);
+ return *this;
+ }
+};
+
+void
+adjust(WeakAndHeap &heap, const Scores &scores)
+{
+ Scores tmp = scores;
+ heap.adjust(&tmp[0], &tmp[0] + tmp.size());
+}
+
+void
+assertScores(const Scores &exp, SharedWeakAndPriorityQueue &heap)
+{
+ ASSERT_EQUAL(exp.size(), heap.getScores().size());
+ for (size_t i = 0; i < exp.size(); ++i) {
+ score_t front = heap.getScores().front();
+ EXPECT_EQUAL(exp[i], front);
+ heap.getScores().pop_front();
+ }
+}
+
+struct NullFixture {
+ SharedWeakAndPriorityQueue h;
+ NullFixture() : h(0) {}
+};
+
+struct EmptyFixture {
+ SharedWeakAndPriorityQueue h;
+ EmptyFixture() : h(4) {}
+};
+
+struct FilledFixture {
+ SharedWeakAndPriorityQueue h;
+ FilledFixture() : h(4) {
+ adjust(h, Scores().s(3).s(5).s(7).s(9));
+ EXPECT_EQUAL(3, h.getMinScore());
+ }
+};
+
+TEST_F("require that SharedWeakAndPriorityQueue with 0 size gives max threshold", NullFixture)
+{
+ EXPECT_EQUAL(std::numeric_limits<score_t>::max(), f.h.getMinScore());
+ adjust(f.h, Scores().s(100));
+ EXPECT_EQUAL(std::numeric_limits<score_t>::max(), f.h.getMinScore());
+}
+
+TEST_F("require that SharedWeakAndPriorityQueue can be filled one-by-one", EmptyFixture)
+{
+ adjust(f.h, Scores().s(4));
+ EXPECT_EQUAL(0, f.h.getMinScore());
+ adjust(f.h, Scores().s(3));
+ EXPECT_EQUAL(0, f.h.getMinScore());
+ adjust(f.h, Scores().s(2));
+ EXPECT_EQUAL(0, f.h.getMinScore());
+ adjust(f.h, Scores().s(1));
+ EXPECT_EQUAL(1, f.h.getMinScore());
+ assertScores(Scores().s(1).s(2).s(3).s(4), f.h);
+}
+
+TEST_F("require that SharedWeakAndPriorityQueue can be filled all-at-once", EmptyFixture)
+{
+ adjust(f.h, Scores().s(4).s(3).s(2).s(1));
+ EXPECT_EQUAL(1, f.h.getMinScore());
+ assertScores(Scores().s(1).s(2).s(3).s(4), f.h);
+}
+
+TEST_F("require that SharedWeakAndPriorityQueue can be adjusted one-by-one", FilledFixture)
+{
+ adjust(f.h, Scores().s(2));
+ EXPECT_EQUAL(3, f.h.getMinScore());
+ adjust(f.h, Scores().s(3));
+ EXPECT_EQUAL(3, f.h.getMinScore());
+ adjust(f.h, Scores().s(6));
+ EXPECT_EQUAL(5, f.h.getMinScore());
+ adjust(f.h, Scores().s(8));
+ EXPECT_EQUAL(6, f.h.getMinScore());
+ adjust(f.h, Scores().s(4));
+ EXPECT_EQUAL(6, f.h.getMinScore());
+ assertScores(Scores().s(6).s(7).s(8).s(9), f.h);
+}
+
+TEST_F("require that SharedWeakAndPriorityQueue can be adjusted all-at-once", FilledFixture)
+{
+ adjust(f.h, Scores().s(2).s(3).s(6).s(8).s(4));
+ EXPECT_EQUAL(6, f.h.getMinScore());
+ assertScores(Scores().s(6).s(7).s(8).s(9), f.h);
+}
+
+TEST_MAIN() { TEST_RUN_ALL(); }