diff options
author | Geir Storli <geirst@verizonmedia.com> | 2019-11-27 09:10:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-27 09:10:35 +0100 |
commit | b8d12bc4fcf30fd51d8b7f3a0352780902e4f620 (patch) | |
tree | 0c973c70aed3b088987e0466b723f31d3e0935a8 | |
parent | 0e6935d94c8e0c93a6f67d982438d98d17f0763a (diff) | |
parent | dca05b7005634874caf6c5b77562a04c5ef70ff3 (diff) |
Merge pull request #11419 from vespa-engine/geirst/attributeblueprint-tests-to-gtest
Rewrite attributeblueprint tests to gtest.
-rw-r--r-- | searchlib/src/tests/attribute/searchable/CMakeLists.txt | 1 | ||||
-rw-r--r-- | searchlib/src/tests/attribute/searchable/attributeblueprint_test.cpp | 115 |
2 files changed, 67 insertions, 49 deletions
diff --git a/searchlib/src/tests/attribute/searchable/CMakeLists.txt b/searchlib/src/tests/attribute/searchable/CMakeLists.txt index 56a6921f2f3..e754253c34a 100644 --- a/searchlib/src/tests/attribute/searchable/CMakeLists.txt +++ b/searchlib/src/tests/attribute/searchable/CMakeLists.txt @@ -19,5 +19,6 @@ vespa_add_executable(searchlib_attribute_blueprint_test_app TEST attributeblueprint_test.cpp DEPENDS searchlib + gtest ) vespa_add_test(NAME searchlib_attribute_blueprint_test_app COMMAND searchlib_attribute_blueprint_test_app) diff --git a/searchlib/src/tests/attribute/searchable/attributeblueprint_test.cpp b/searchlib/src/tests/attribute/searchable/attributeblueprint_test.cpp index 571c2ce3431..1418d1f0c97 100644 --- a/searchlib/src/tests/attribute/searchable/attributeblueprint_test.cpp +++ b/searchlib/src/tests/attribute/searchable/attributeblueprint_test.cpp @@ -19,7 +19,7 @@ #include <vespa/searchlib/queryeval/leaf_blueprints.h> #include <vespa/searchlib/queryeval/nearest_neighbor_blueprint.h> #include <vespa/searchlib/tensor/dense_tensor_attribute.h> -#include <vespa/vespalib/testkit/testapp.h> +#include <vespa/vespalib/gtest/gtest.h> #include <vespa/log/log.h> LOG_SETUP("attributeblueprint_test"); @@ -103,15 +103,17 @@ public: constexpr uint32_t DOCID_LIMIT = 3; -bool search(const Node &node, IAttributeManager &attribute_manager, bool expect_attribute_search_context = true) { +bool +do_search(const Node &node, IAttributeManager &attribute_manager, bool expect_attribute_search_context = true) +{ AttributeContext ac(attribute_manager); FakeRequestContext requestContext(&ac); MatchData::UP md(MatchData::makeTestInstance(1, 1)); AttributeBlueprintFactory source; Blueprint::UP result = source.createBlueprint(requestContext, FieldSpec(field, 0, 0), node); - ASSERT_TRUE(result.get()); + assert(result.get()); EXPECT_TRUE(!result->getState().estimate().empty); - EXPECT_EQUAL(3u, result->getState().estimate().estHits); + EXPECT_EQ(3u, result->getState().estimate().estHits); if (expect_attribute_search_context) { EXPECT_TRUE(result->get_attribute_search_context() != nullptr); } else { @@ -120,24 +122,28 @@ bool search(const Node &node, IAttributeManager &attribute_manager, bool expect_ result->fetchPostings(true); result->setDocIdLimit(DOCID_LIMIT); SearchIterator::UP iterator = result->createSearch(*md, true); - ASSERT_TRUE((bool)iterator); + assert((bool)iterator); iterator->initRange(1, 3); EXPECT_TRUE(!iterator->seek(1)); return iterator->seek(2); } -bool search(const string &term, IAttributeManager &attribute_manager) { - TEST_STATE(term.c_str()); +bool +search_for_term(const string &term, IAttributeManager &attribute_manager) +{ SimpleStringTerm node(term, "field", 0, Weight(0)); - bool ret = search(node, attribute_manager); + bool ret = do_search(node, attribute_manager); return ret; } -template <typename T> struct AttributeVectorTypeFinder { +template <typename T> +struct AttributeVectorTypeFinder { typedef SingleStringExtAttribute Type; static void add(Type & a, const T & v) { a.add(v, weight); } }; -template <> struct AttributeVectorTypeFinder<int64_t> { + +template <> +struct AttributeVectorTypeFinder<int64_t> { typedef search::SingleValueNumericAttribute<search::IntegerAttributeTemplate<int64_t> > Type; static void add(Type & a, int64_t v) { a.set(a.getNumDocs()-1, v); a.commit(); } }; @@ -148,7 +154,9 @@ struct FastSearchLongAttribute { }; template <typename AT, typename T> -MyAttributeManager fill(typename AT::Type * attr, T value) { +MyAttributeManager +fill(typename AT::Type * attr, T value) +{ AttributeVector::DocId docid; attr->addDoc(docid); attr->addDoc(docid); @@ -159,14 +167,18 @@ MyAttributeManager fill(typename AT::Type * attr, T value) { } template <typename T> -MyAttributeManager makeAttributeManager(T value) { +MyAttributeManager +makeAttributeManager(T value) +{ typedef AttributeVectorTypeFinder<T> AT; typedef typename AT::Type AttributeVectorType; AttributeVectorType *attr = new AttributeVectorType(field); return fill<AT, T>(attr, value); } -MyAttributeManager makeFastSearchLongAttribute(int64_t value) { +MyAttributeManager +makeFastSearchLongAttribute(int64_t value) +{ typedef FastSearchLongAttribute::Type AttributeVectorType; Config cfg(BasicType::fromType(int64_t()), CollectionType::SINGLE); cfg.setFastSearch(true); @@ -176,46 +188,50 @@ MyAttributeManager makeFastSearchLongAttribute(int64_t value) { } // namespace -TEST("requireThatIteratorsCanBeCreated") { - MyAttributeManager attribute_manager = makeAttributeManager("foo"); +TEST(AttributeBlueprintTest, require_that_iterators_can_be_created) +{ + auto attribute_manager = makeAttributeManager("foo"); - EXPECT_TRUE(search("foo", attribute_manager)); + EXPECT_TRUE(search_for_term("foo", attribute_manager)); } -TEST("requireThatRangeTermsWorkToo") { - MyAttributeManager attribute_manager = makeAttributeManager(int64_t(42)); +TEST(AttributeBlueprintTest, require_that_range_terms_work) +{ + auto attribute_manager = makeAttributeManager(int64_t(42)); - EXPECT_TRUE(search("[23;46]", attribute_manager)); - EXPECT_TRUE(!search("[10;23]", attribute_manager)); - EXPECT_TRUE(!search(">43", attribute_manager)); - EXPECT_TRUE(search("[10;]", attribute_manager)); + EXPECT_TRUE(search_for_term("[23;46]", attribute_manager)); + EXPECT_TRUE(!search_for_term("[10;23]", attribute_manager)); + EXPECT_TRUE(!search_for_term(">43", attribute_manager)); + EXPECT_TRUE(search_for_term("[10;]", attribute_manager)); } -TEST("requireThatPrefixTermsWork") +TEST(AttributeBlueprintTest, require_that_prefix_terms_work) { - MyAttributeManager attribute_manager = makeAttributeManager("foo"); + auto attribute_manager = makeAttributeManager("foo"); SimplePrefixTerm node("fo", "field", 0, Weight(0)); - EXPECT_TRUE(search(node, attribute_manager)); + EXPECT_TRUE(do_search(node, attribute_manager)); } -TEST("requireThatLocationTermsWork") { +TEST(AttributeBlueprintTest, require_that_location_terms_work) +{ // 0xcc is z-curve for (10, 10). - MyAttributeManager attribute_manager = makeAttributeManager(int64_t(0xcc)); + auto attribute_manager = makeAttributeManager(int64_t(0xcc)); SimpleLocationTerm node(Location(Point(10, 10), 3, 0), field, 0, Weight(0)); - EXPECT_TRUE(search(node, attribute_manager, false)); + EXPECT_TRUE(do_search(node, attribute_manager, false)); node = SimpleLocationTerm(Location(Point(100, 100), 3, 0), field, 0, Weight(0)); - EXPECT_TRUE(!search(node, attribute_manager, false)); + EXPECT_TRUE(!do_search(node, attribute_manager, false)); node = SimpleLocationTerm(Location(Point(13, 13), 4, 0), field, 0, Weight(0)); - EXPECT_TRUE(!search(node, attribute_manager, false)); + EXPECT_TRUE(!do_search(node, attribute_manager, false)); node = SimpleLocationTerm(Location(Point(10, 13), 3, 0), field, 0, Weight(0)); - EXPECT_TRUE(search(node, attribute_manager, false)); + EXPECT_TRUE(do_search(node, attribute_manager, false)); } -TEST("requireThatFastSearchLocationTermsWork") { +TEST(AttributeBlueprintTest, require_that_fast_search_location_terms_work) +{ // 0xcc is z-curve for (10, 10). - MyAttributeManager attribute_manager = makeFastSearchLongAttribute(int64_t(0xcc)); + auto attribute_manager = makeFastSearchLongAttribute(int64_t(0xcc)); SimpleLocationTerm node(Location(Point(10, 10), 3, 0), field, 0, Weight(0)); #if 0 @@ -249,7 +265,7 @@ const BlueprintType& as_type(const Blueprint& blueprint) { const auto* result = dynamic_cast<const BlueprintType*>(&blueprint); - ASSERT_TRUE(result != nullptr); + assert(result != nullptr); return *result; } @@ -269,6 +285,7 @@ public: source() { } + ~NearestNeighborFixture() {} void set_query_tensor(const TensorSpec& tensor_spec) { request_ctx.set_query_tensor("query_tensor", tensor_spec); } @@ -278,17 +295,17 @@ public: } }; -TEST_F("nearest neighbor blueprint is created by attribute blueprint factory", - NearestNeighborFixture(make_tensor_attribute(field, "tensor(x[2])"))) +TEST(AttributeBlueprintTest, nearest_neighbor_blueprint_is_created_by_attribute_blueprint_factory) { + NearestNeighborFixture f(make_tensor_attribute(field, "tensor(x[2])")); TensorSpec dense_x_2 = TensorSpec("tensor(x[2])").add({{"x", 0}}, 3).add({{"x", 1}}, 5); f.set_query_tensor(dense_x_2); auto result = f.create_blueprint(); const auto& nearest = as_type<NearestNeighborBlueprint>(*result); - EXPECT_EQUAL("tensor(x[2])", nearest.get_attribute_tensor().getTensorType().to_spec()); - EXPECT_EQUAL(dense_x_2, DefaultTensorEngine::ref().to_spec(nearest.get_query_tensor())); - EXPECT_EQUAL(7u, nearest.get_target_num_hits()); + EXPECT_EQ("tensor(x[2])", nearest.get_attribute_tensor().getTensorType().to_spec()); + EXPECT_EQ(dense_x_2, DefaultTensorEngine::ref().to_spec(nearest.get_query_tensor())); + EXPECT_EQ(7u, nearest.get_target_num_hits()); } void @@ -308,18 +325,18 @@ expect_empty_blueprint(AttributeVector::SP attr) expect_empty_blueprint(std::move(attr), TensorSpec("double"), false); } -TEST("empty blueprint is created when nearest neighbor term is invalid") +TEST(AttributeBlueprintTest, empty_blueprint_is_created_when_nearest_neighbor_term_is_invalid) { TensorSpec sparse_x = TensorSpec("tensor(x{})").add({{"x", 0}}, 3); TensorSpec dense_y_2 = TensorSpec("tensor(y[2])").add({{"y", 0}}, 3).add({{"y", 1}}, 5); TensorSpec dense_x_3 = TensorSpec("tensor(x[3])").add({{"x", 0}}, 3).add({{"x", 1}}, 5).add({{"x", 2}}, 7); - TEST_DO(expect_empty_blueprint(make_int_attribute(field))); // attribute is not a tensor - TEST_DO(expect_empty_blueprint(make_tensor_attribute(field, "tensor(x{})"))); // attribute is not a dense tensor - TEST_DO(expect_empty_blueprint(make_tensor_attribute(field, "tensor(x[2],y[2])"))); // tensor type is not of order 1 - TEST_DO(expect_empty_blueprint(make_tensor_attribute(field, "tensor(x[2])"))); // query tensor not found - TEST_DO(expect_empty_blueprint(make_tensor_attribute(field, "tensor(x[2])"), sparse_x)); // query tensor is not dense - TEST_DO(expect_empty_blueprint(make_tensor_attribute(field, "tensor(x[2])"), dense_y_2)); // tensor types are not equal - TEST_DO(expect_empty_blueprint(make_tensor_attribute(field, "tensor(x[2])"), dense_x_3)); // tensor types are not same size + expect_empty_blueprint(make_int_attribute(field)); // attribute is not a tensor + expect_empty_blueprint(make_tensor_attribute(field, "tensor(x{})")); // attribute is not a dense tensor + expect_empty_blueprint(make_tensor_attribute(field, "tensor(x[2],y[2])")); // tensor type is not of order 1 + expect_empty_blueprint(make_tensor_attribute(field, "tensor(x[2])")); // query tensor not found + expect_empty_blueprint(make_tensor_attribute(field, "tensor(x[2])"), sparse_x); // query tensor is not dense + expect_empty_blueprint(make_tensor_attribute(field, "tensor(x[2])"), dense_y_2); // tensor types are not equal + expect_empty_blueprint(make_tensor_attribute(field, "tensor(x[2])"), dense_x_3); // tensor types are not same size } - -TEST_MAIN() { TEST_RUN_ALL(); } + +GTEST_MAIN_RUN_ALL_TESTS() |