diff --git a/searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp b/searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp index 295b8136f77f..27850004dc1b 100644 --- a/searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp +++ b/searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp @@ -9,7 +9,8 @@ #include #include #include -#include +#include +#include using search::attribute::IAttributeVector; using search::tensor::ITensorAttribute; @@ -27,42 +28,54 @@ namespace search::attribute { using Fixture = ImportedAttributeFixture; -TEST_F("Accessors return expected attributes", Fixture) { - EXPECT_EQUAL(f.imported_attr->getReferenceAttribute().get(), - f.reference_attr.get()); - EXPECT_EQUAL(f.imported_attr->getTargetAttribute().get(), - f.target_attr.get()); +TEST(ImportedAttributeVectorTest, accessors_return_expected_attributes) +{ + Fixture f; + EXPECT_EQ(f.imported_attr->getReferenceAttribute().get(), f.reference_attr.get()); + EXPECT_EQ(f.imported_attr->getTargetAttribute().get(), f.target_attr.get()); } -TEST_F("getName() is equal to name given during construction", Fixture) { +TEST(ImportedAttributeVectorTest, getName_is_equal_to_name_given_during_construction) +{ + Fixture f; auto attr = f.create_attribute_vector_from_members("coolvector"); - EXPECT_EQUAL("coolvector", attr->getName()); - EXPECT_EQUAL("coolvector", attr->makeReadGuard(false)->attribute()->getName()); + EXPECT_EQ("coolvector", attr->getName()); + EXPECT_EQ("coolvector", attr->makeReadGuard(false)->attribute()->getName()); } -TEST_F("getNumDocs() returns number of documents in reference attribute vector", Fixture) { +TEST(ImportedAttributeVectorTest, getNumDocs_returns_number_of_documents_in_reference_attribute_vector) +{ + Fixture f; add_n_docs_with_undefined_values(*f.reference_attr, 42); - EXPECT_EQUAL(42u, f.get_imported_attr()->getNumDocs()); + EXPECT_EQ(42u, f.get_imported_attr()->getNumDocs()); } -TEST_F("hasEnum() is false for non-enum target attribute vector", Fixture) { +TEST(ImportedAttributeVectorTest, hasEnum_is_false_for_non_enum_target_attribute_vector) +{ + Fixture f; EXPECT_FALSE(f.get_imported_attr()->hasEnum()); } -TEST_F("Collection type is inherited from target attribute", Fixture) { - EXPECT_EQUAL(CollectionType::SINGLE, f.get_imported_attr()->getCollectionType()); +TEST(ImportedAttributeVectorTest, collection_type_is_inherited_from_target_attribute) +{ + Fixture f; + EXPECT_EQ(CollectionType::SINGLE, f.get_imported_attr()->getCollectionType()); f.reset_with_new_target_attr(create_array_attribute(BasicType::INT32)); - EXPECT_EQUAL(CollectionType::ARRAY, f.get_imported_attr()->getCollectionType()); + EXPECT_EQ(CollectionType::ARRAY, f.get_imported_attr()->getCollectionType()); } -TEST_F("getBasicType() returns target vector basic type", Fixture) { +TEST(ImportedAttributeVectorTest, getBasicType_returns_target_vector_basic_type) +{ + Fixture f; f.reset_with_new_target_attr(create_single_attribute(BasicType::INT64)); - EXPECT_EQUAL(BasicType::INT64, f.get_imported_attr()->getBasicType()); + EXPECT_EQ(BasicType::INT64, f.get_imported_attr()->getBasicType()); f.reset_with_new_target_attr(create_single_attribute(BasicType::DOUBLE)); - EXPECT_EQUAL(BasicType::DOUBLE, f.get_imported_attr()->getBasicType()); + EXPECT_EQ(BasicType::DOUBLE, f.get_imported_attr()->getBasicType()); } -TEST_F("makeReadGuard(false) acquires guards on both target and reference attributes", Fixture) { +TEST(ImportedAttributeVectorTest, makeReadGuard_false_acquires_guards_on_both_target_and_reference_attributes) +{ + Fixture f; add_n_docs_with_undefined_values(*f.reference_attr, 2); add_n_docs_with_undefined_values(*f.target_attr, 2); // Now at generation 1 in both attributes. @@ -71,20 +84,22 @@ TEST_F("makeReadGuard(false) acquires guards on both target and reference attrib add_n_docs_with_undefined_values(*f.reference_attr, 1); add_n_docs_with_undefined_values(*f.target_attr, 1); - EXPECT_EQUAL(2u, f.target_attr->getCurrentGeneration()); - EXPECT_EQUAL(2u, f.reference_attr->getCurrentGeneration()); + EXPECT_EQ(2u, f.target_attr->getCurrentGeneration()); + EXPECT_EQ(2u, f.reference_attr->getCurrentGeneration()); // Should still be holding guard for first generation of writes for both attributes - EXPECT_EQUAL(1u, f.target_attr->get_oldest_used_generation()); - EXPECT_EQUAL(1u, f.reference_attr->get_oldest_used_generation()); + EXPECT_EQ(1u, f.target_attr->get_oldest_used_generation()); + EXPECT_EQ(1u, f.reference_attr->get_oldest_used_generation()); } // Force a generation handler update add_n_docs_with_undefined_values(*f.reference_attr, 1); add_n_docs_with_undefined_values(*f.target_attr, 1); - EXPECT_EQUAL(3u, f.target_attr->get_oldest_used_generation()); - EXPECT_EQUAL(3u, f.reference_attr->get_oldest_used_generation()); + EXPECT_EQ(3u, f.target_attr->get_oldest_used_generation()); + EXPECT_EQ(3u, f.reference_attr->get_oldest_used_generation()); } -TEST_F("makeReadGuard(true) acquires enum guard on target and regular guard on reference attribute", Fixture) { +TEST(ImportedAttributeVectorTest, makeReadGuard_true_acquires_enum_guard_on_target_and_regular_guard_on_reference_attribute) +{ + Fixture f; f.reset_with_new_target_attr(create_single_attribute(BasicType::STRING)); add_n_docs_with_undefined_values(*f.reference_attr, 2); add_n_docs_with_undefined_values(*f.target_attr, 2); @@ -93,67 +108,81 @@ TEST_F("makeReadGuard(true) acquires enum guard on target and regular guard on r add_n_docs_with_undefined_values(*f.target_attr, 1); add_n_docs_with_undefined_values(*f.reference_attr, 1); - EXPECT_EQUAL(5u, f.target_attr->getCurrentGeneration()); - EXPECT_EQUAL(2u, f.reference_attr->getCurrentGeneration()); + EXPECT_EQ(5u, f.target_attr->getCurrentGeneration()); + EXPECT_EQ(2u, f.reference_attr->getCurrentGeneration()); - EXPECT_EQUAL(3u, f.target_attr->get_oldest_used_generation()); - EXPECT_EQUAL(1u, f.reference_attr->get_oldest_used_generation()); + EXPECT_EQ(3u, f.target_attr->get_oldest_used_generation()); + EXPECT_EQ(1u, f.reference_attr->get_oldest_used_generation()); EXPECT_TRUE(has_active_enum_guards(*f.target_attr)); } // Force a generation handler update add_n_docs_with_undefined_values(*f.reference_attr, 1); add_n_docs_with_undefined_values(*f.target_attr, 1); - EXPECT_EQUAL(7u, f.target_attr->get_oldest_used_generation()); - EXPECT_EQUAL(3u, f.reference_attr->get_oldest_used_generation()); + EXPECT_EQ(7u, f.target_attr->get_oldest_used_generation()); + EXPECT_EQ(3u, f.reference_attr->get_oldest_used_generation()); EXPECT_FALSE(has_active_enum_guards(*f.target_attr)); } -TEST_F("Single-valued integer attribute values can be retrieved via reference", Fixture) +TEST(ImportedAttributeVectorTest, single_valued_integer_attribute_values_can_be_retrieved_via_reference) { + Fixture f; reset_with_single_value_reference_mappings( f, BasicType::INT32, {{DocId(1), dummy_gid(3), DocId(3), 1234}, {DocId(3), dummy_gid(7), DocId(7), 5678}}); - EXPECT_EQUAL(1234, f.get_imported_attr()->getInt(DocId(1))); - EXPECT_EQUAL(5678, f.get_imported_attr()->getInt(DocId(3))); + EXPECT_EQ(1234, f.get_imported_attr()->getInt(DocId(1))); + EXPECT_EQ(5678, f.get_imported_attr()->getInt(DocId(3))); } -TEST_F("getValueCount() is 1 for mapped single value attribute", Fixture) +TEST(ImportedAttributeVectorTest, getValueCount_is_1_for_mapped_single_value_attribute) { + Fixture f; reset_with_single_value_reference_mappings( f, BasicType::INT32, {{DocId(1), dummy_gid(3), DocId(3), 1234}}); - EXPECT_EQUAL(1u, f.get_imported_attr()->getValueCount(DocId(1))); + EXPECT_EQ(1u, f.get_imported_attr()->getValueCount(DocId(1))); } -TEST_F("getValueCount() is 0 for non-mapped single value attribute", Fixture) +TEST(ImportedAttributeVectorTest, getValueCount_is_0_for_non_mapped_single_value_attribute) { + Fixture f; add_n_docs_with_undefined_values(*f.reference_attr, 3); - EXPECT_EQUAL(0u, f.get_imported_attr()->getValueCount(DocId(2))); + EXPECT_EQ(0u, f.get_imported_attr()->getValueCount(DocId(2))); } -TEST_F("getMaxValueCount() is 1 for single value attribute vectors", Fixture) { - EXPECT_EQUAL(1u, f.get_imported_attr()->getMaxValueCount()); +TEST(ImportedAttributeVectorTest, getMaxValueCount_is_1_for_single_value_attribute_vectors) +{ + Fixture f; + EXPECT_EQ(1u, f.get_imported_attr()->getMaxValueCount()); } -TEST_F("getFixedWidth() is inherited from target attribute vector", Fixture) { - EXPECT_EQUAL(f.target_attr->getFixedWidth(), - f.get_imported_attr()->getFixedWidth()); +TEST(ImportedAttributeVectorTest, getFixedWidth_is_inherited_from_target_attribute_vector) +{ + Fixture f; + EXPECT_EQ(f.target_attr->getFixedWidth(), f.get_imported_attr()->getFixedWidth()); } -TEST_F("as_docid_with_weight_posting_store() returns nullptr", Fixture) { +TEST(ImportedAttributeVectorTest, as_docid_with_weight_posting_store_returns_nullptr) +{ + Fixture f; EXPECT_TRUE(f.get_imported_attr()->as_docid_with_weight_posting_store() == nullptr); } -TEST_F("asTensorAttribute() returns nullptr", Fixture) { +TEST(ImportedAttributeVectorTest, asTensorAttribute_returns_nullptr) +{ + Fixture f; EXPECT_TRUE(f.get_imported_attr()->asTensorAttribute() == nullptr); } -TEST_F("isImported() returns true", Fixture) { +TEST(ImportedAttributeVectorTest, isImported_returns_true) +{ + Fixture f; EXPECT_TRUE(f.get_imported_attr()->isImported()); } -TEST_F("Multi-valued integer attribute values can be retrieved via reference", Fixture) { +TEST(ImportedAttributeVectorTest, multi_valued_integer_attribute_values_can_be_retrieved_via_reference) +{ + Fixture f; const std::vector doc3_values({1234}); const std::vector doc7_values({5678, 9876, 555, 777}); const std::vector doc8_values({}); @@ -167,7 +196,9 @@ TEST_F("Multi-valued integer attribute values can be retrieved via reference", F assert_multi_value_matches(f, DocId(5), doc8_values); } -TEST_F("Weighted integer attribute values can be retrieved via reference", Fixture) { +TEST(ImportedAttributeVectorTest, weighted_integer_attribute_values_can_be_retrieved_via_reference) +{ + Fixture f; const std::vector doc3_values({WeightedInt(1234, 5)}); const std::vector doc7_values({WeightedInt(5678, 10), WeightedInt(9876, 20)}); reset_with_wset_value_reference_mappings( @@ -178,25 +209,30 @@ TEST_F("Weighted integer attribute values can be retrieved via reference", Fixtu assert_multi_value_matches(f, DocId(3), doc7_values); } -TEST_F("LID with not present GID reference mapping returns default value", Fixture) +TEST(ImportedAttributeVectorTest, lid_with_not_present_gid_reference_mapping_returns_default_value) { + Fixture f; f.target_attr->addReservedDoc(); add_n_docs_with_undefined_values(*f.reference_attr, 2); - EXPECT_EQUAL(f.target_attr->getInt(DocId(0)), // Implicit default undefined value - f.get_imported_attr()->getInt(DocId(1))); + EXPECT_EQ(f.target_attr->getInt(DocId(0)), // Implicit default undefined value + f.get_imported_attr()->getInt(DocId(1))); } -TEST_F("Singled-valued floating point attribute values can be retrieved via reference", Fixture) { +TEST(ImportedAttributeVectorTest, single_value_floating_point_attribute_values_can_be_retrieved_via_reference) +{ + Fixture f; reset_with_single_value_reference_mappings( f, BasicType::FLOAT, {{DocId(2), dummy_gid(3), DocId(3), 10.5f}, {DocId(4), dummy_gid(8), DocId(8), 3.14f}}); - EXPECT_EQUAL(10.5, f.get_imported_attr()->getFloat(DocId(2))); - EXPECT_EQUAL(3.14, f.get_imported_attr()->getFloat(DocId(4))); + EXPECT_FLOAT_EQ(10.5, f.get_imported_attr()->getFloat(DocId(2))); + EXPECT_FLOAT_EQ(3.14, f.get_imported_attr()->getFloat(DocId(4))); } -TEST_F("Multi-valued floating point attribute values can be retrieved via reference", Fixture) { +TEST(ImportedAttributeVectorTest, multi_value_floating_point_attribute_values_can_be_retrieved_via_reference) +{ + Fixture f; const std::vector doc3_values({3.14, 133.7}); const std::vector doc7_values({5.5, 6.5, 10.5}); reset_with_array_value_reference_mappings( @@ -207,7 +243,9 @@ TEST_F("Multi-valued floating point attribute values can be retrieved via refere assert_multi_value_matches(f, DocId(4), doc7_values); } -TEST_F("Weighted floating point attribute values can be retrieved via reference", Fixture) { +TEST(ImportedAttributeVectorTest, weighted_floating_point_attribute_values_can_be_retrieved_via_reference) +{ + Fixture f; const std::vector doc3_values({WeightedFloat(3.14, 5)}); const std::vector doc7_values({WeightedFloat(5.5, 7), WeightedFloat(10.25, 42)}); reset_with_wset_value_reference_mappings( @@ -218,7 +256,9 @@ TEST_F("Weighted floating point attribute values can be retrieved via reference" assert_multi_value_matches(f, DocId(3), doc7_values); } -TEST_F("isUndefined() works for primitive attribute type", Fixture) { +TEST(ImportedAttributeVectorTest, isUndefined_works_for_primitive_attribute_type) +{ + Fixture f; reset_with_single_value_reference_mappings( f, BasicType::INT32, {{DocId(3), dummy_gid(7), DocId(7), 5678}}); @@ -227,8 +267,9 @@ TEST_F("isUndefined() works for primitive attribute type", Fixture) { EXPECT_TRUE(f.get_imported_attr()->isUndefined(DocId(2))); // Not mapped } -TEST_F("original lid range is used by read guard", Fixture) +TEST(ImportedAttributeVectorTest, original_lid_range_is_used_by_read_guard) { + Fixture f; reset_with_single_value_reference_mappings( f, BasicType::INT32, {{DocId(1), dummy_gid(3), DocId(3), 1234}}); @@ -236,27 +277,28 @@ TEST_F("original lid range is used by read guard", Fixture) add_n_docs_with_undefined_values(*f.reference_attr, 1); f.map_reference(DocId(10), dummy_gid(3), DocId(3)); auto second_guard = f.get_imported_attr(); - EXPECT_EQUAL(1234, second_guard->getInt(DocId(10))); - EXPECT_NOT_EQUAL(1234, first_guard->getInt(DocId(10))); - EXPECT_EQUAL(getUndefined(), first_guard->getInt(DocId(10))); + EXPECT_EQ(1234, second_guard->getInt(DocId(10))); + EXPECT_NE(1234, first_guard->getInt(DocId(10))); + EXPECT_EQ(getUndefined(), first_guard->getInt(DocId(10))); } -TEST_F("Original target lid range is used by read guard", Fixture) +TEST(ImportedAttributeVectorTest, original_target_lid_range_is_used_by_read_guard) { + Fixture f; reset_with_single_value_reference_mappings( f, BasicType::INT32, {}); - EXPECT_EQUAL(11u, f.target_attr->getNumDocs()); + EXPECT_EQ(11u, f.target_attr->getNumDocs()); auto first_guard = f.get_imported_attr(); add_n_docs_with_undefined_values(*f.target_attr, 1); - EXPECT_EQUAL(12u, f.target_attr->getNumDocs()); + EXPECT_EQ(12u, f.target_attr->getNumDocs()); auto typed_target_attr = f.template target_attr_as(); ASSERT_TRUE(typed_target_attr->update(11, 2345)); f.target_attr->commit(); f.map_reference(DocId(8), dummy_gid(11), DocId(11)); auto second_guard = f.get_imported_attr(); - EXPECT_EQUAL(2345, second_guard->getInt(DocId(8))); - EXPECT_NOT_EQUAL(2345, first_guard->getInt(DocId(8))); + EXPECT_EQ(2345, second_guard->getInt(DocId(8))); + EXPECT_NE(2345, first_guard->getInt(DocId(8))); } struct SingleStringAttrFixture : Fixture { @@ -275,31 +317,35 @@ struct SingleStringAttrFixture : Fixture { SingleStringAttrFixture::~SingleStringAttrFixture() = default; -TEST_F("Single-valued string attribute values can be retrieved via reference", SingleStringAttrFixture) +TEST(ImportedAttributeVectorTest, single_valued_string_attribute_values_can_be_retrieved_via_reference) { + SingleStringAttrFixture f; auto buf = f.get_imported_attr()->get_raw(DocId(2)); - EXPECT_EQUAL(std::string_view("foo"), std::string_view(buf.data(), buf.size())); + EXPECT_EQ(std::string_view("foo"), std::string_view(buf.data(), buf.size())); buf = f.get_imported_attr()->get_raw(DocId(4)); - EXPECT_EQUAL(std::string_view("bar"), std::string_view(buf.data(), buf.size())); + EXPECT_EQ(std::string_view("bar"), std::string_view(buf.data(), buf.size())); } -TEST_F("getEnum() returns target vector enum via reference", SingleStringAttrFixture) +TEST(ImportedAttributeVectorTest, getEnum_returns_target_vector_enum_via_reference) { - EXPECT_EQUAL(f.target_attr->getEnum(DocId(3)), - f.get_imported_attr()->getEnum(DocId(2))); - EXPECT_EQUAL(f.target_attr->getEnum(DocId(7)), - f.get_imported_attr()->getEnum(DocId(4))); + SingleStringAttrFixture f; + EXPECT_EQ(f.target_attr->getEnum(DocId(3)), f.get_imported_attr()->getEnum(DocId(2))); + EXPECT_EQ(f.target_attr->getEnum(DocId(7)), f.get_imported_attr()->getEnum(DocId(4))); } -TEST_F("findEnum() returns target vector enum via reference", SingleStringAttrFixture) { +TEST(ImportedAttributeVectorTest, findEnum_returns_target_vector_enum_via_reference) +{ + SingleStringAttrFixture f; EnumHandle expected_handle{}; ASSERT_TRUE(f.target_attr->findEnum("foo", expected_handle)); EnumHandle actual_handle{}; ASSERT_TRUE(f.get_imported_attr()->findEnum("foo", actual_handle)); - EXPECT_EQUAL(expected_handle, actual_handle); + EXPECT_EQ(expected_handle, actual_handle); } -TEST_F("isUndefined() works for enumerated attribute type", SingleStringAttrFixture) { +TEST(ImportedAttributeVectorTest, isUndefined_works_for_enumerated_attribute_type) +{ + SingleStringAttrFixture f; EXPECT_FALSE(f.get_imported_attr()->isUndefined(DocId(2))); // Mapped EXPECT_TRUE(f.get_imported_attr()->isUndefined(DocId(3))); // Not mapped } @@ -311,18 +357,24 @@ void verify_get_string_from_enum_is_mapped(FixtureType& f) { ASSERT_TRUE(f.target_attr->findEnum("foo", handle)); const char* from_enum = f.get_imported_attr()->getStringFromEnum(handle); ASSERT_TRUE(from_enum != nullptr); - EXPECT_EQUAL(std::string("foo"), std::string(from_enum)); + EXPECT_EQ(std::string("foo"), std::string(from_enum)); } -TEST_F("Single-value getStringFromEnum() returns string enum is mapped to", SingleStringAttrFixture) { +TEST(ImportedAttributeVectorTest, single_value_getStringFromEnum_returns_string_enum_is_mapped_to) +{ + SingleStringAttrFixture f; verify_get_string_from_enum_is_mapped(f); } -TEST_F("hasEnum() is true for enum target attribute vector", SingleStringAttrFixture) { +TEST(ImportedAttributeVectorTest, hasEnum_is_true_for_enum_target_attribute_vector) +{ + SingleStringAttrFixture f; EXPECT_TRUE(f.get_imported_attr()->hasEnum()); } -TEST_F("createSearchContext() returns an imported search context", SingleStringAttrFixture) { +TEST(ImportedAttributeVectorTest, createSearchContext_returns_an_imported_search_context) +{ + SingleStringAttrFixture f; auto ctx = f.get_imported_attr()->createSearchContext(word_term("bar"), SearchContextParams()); ASSERT_TRUE(ctx.get() != nullptr); fef::TermFieldMatchData match; @@ -364,27 +416,37 @@ struct MultiStringAttrFixture : Fixture { MultiStringAttrFixture::~MultiStringAttrFixture() = default; -TEST_F("Multi-valued string attribute values can be retrieved via reference", MultiStringAttrFixture) { +TEST(ImportedAttributeVectorTest, multi_value_string_attribute_values_can_be_retrieved_via_reference) +{ + MultiStringAttrFixture f; assert_multi_value_matches(f, DocId(2), f.doc3_values, string_eq); assert_multi_value_matches(f, DocId(4), f.doc7_values, string_eq); } -TEST_F("Multi-valued enum attribute values can be retrieved via reference", MultiStringAttrFixture) { +TEST(ImportedAttributeVectorTest, multi_valued_enum_attribute_values_can_be_retrieved_via_reference) +{ + MultiStringAttrFixture f; AttributeContent expected; expected.fill(*f.target_attr, DocId(3)); assert_multi_value_matches(f, DocId(2), as_vector(expected)); } -TEST_F("Multi-value getStringFromEnum() returns string enum is mapped to", MultiStringAttrFixture) { +TEST(ImportedAttributeVectorTest, multi_value_getStringFromEnum_returns_string_enum_is_mapped_to) +{ + MultiStringAttrFixture f; verify_get_string_from_enum_is_mapped(f); } -TEST_F("getValueCount() is equal to stored values for mapped multi value attribute", MultiStringAttrFixture) { - EXPECT_EQUAL(f.doc7_values.size(), f.get_imported_attr()->getValueCount(DocId(4))); +TEST(ImportedAttributeVectorTest, getValueCount_is_equal_to_stored_values_for_mapped_multi_value_attribute) +{ + MultiStringAttrFixture f; + EXPECT_EQ(f.doc7_values.size(), f.get_imported_attr()->getValueCount(DocId(4))); } -TEST_F("getMaxValueCount() is greater than 1 for multi value attribute vectors", MultiStringAttrFixture) { - EXPECT_GREATER(f.get_imported_attr()->getMaxValueCount(), 1u); +TEST(ImportedAttributeVectorTest, getMaxValueCount_is_greater_than_1_for_multi_value_attribute_vectors) +{ + MultiStringAttrFixture f; + EXPECT_GT(f.get_imported_attr()->getMaxValueCount(), 1u); } struct WeightedMultiStringAttrFixture : Fixture { @@ -406,12 +468,16 @@ struct WeightedMultiStringAttrFixture : Fixture { WeightedMultiStringAttrFixture::~WeightedMultiStringAttrFixture() = default; -TEST_F("Weighted string attribute values can be retrieved via reference", WeightedMultiStringAttrFixture) { +TEST(ImportedAttributeVectorTest, weighted_string_attribute_values_can_be_retrieved_via_reference) +{ + WeightedMultiStringAttrFixture f; assert_multi_value_matches(f, DocId(1), f.doc3_values); assert_multi_value_matches(f, DocId(3), f.doc7_values); } -TEST_F("Weighted enum attribute values can be retrieved via reference", WeightedMultiStringAttrFixture) { +TEST(ImportedAttributeVectorTest, weighted_enum_attribute_values_can_be_retrieved_via_reference) +{ + WeightedMultiStringAttrFixture f; AttributeContent expected; expected.fill(*f.target_attr, DocId(7)); assert_multi_value_matches(f, DocId(3), as_vector(expected)); @@ -424,14 +490,18 @@ bool weighted_string_eq(const WeightedConstChar& lhs, const WeightedConstChar& r return (strcmp(lhs.value(), rhs.value()) == 0); }; -TEST_F("Weighted const char attribute values can be retrieved via reference", WeightedMultiStringAttrFixture) { +TEST(ImportedAttributeVectorTest, weighted_const_char_attribute_values_can_be_retrieved_via_reference) +{ + WeightedMultiStringAttrFixture f; AttributeContent expected; expected.fill(*f.target_attr, DocId(7)); assert_multi_value_matches(f, DocId(3), as_vector(expected), weighted_string_eq); } -TEST_F("Weighted set getStringFromEnum() returns string enum is mapped to", WeightedMultiStringAttrFixture) { +TEST(ImportedAttributeVectorTest, weighted_set_getStringFromEnum_returns_string_enum_is_mapped_to) +{ + WeightedMultiStringAttrFixture f; verify_get_string_from_enum_is_mapped(f); } @@ -506,19 +576,19 @@ void check_onSerializeForAscendingSort_is_forwarded_with_remapped_lid() { FixtureT f; int dummy_tag; void* ser_to = &dummy_tag; - EXPECT_EQUAL(f.mock_target->_return_value, - f.get_imported_attr()->serializeForAscendingSort( - DocId(4), ser_to, 777, &f.mock_converter)); // child lid 4 -> parent lid 7 + EXPECT_EQ(f.mock_target->_return_value, + f.get_imported_attr()->serializeForAscendingSort( + DocId(4), ser_to, 777, &f.mock_converter)); // child lid 4 -> parent lid 7 EXPECT_TRUE(f.mock_target->_ascending_called); - EXPECT_EQUAL(DocId(7), f.mock_target->_doc_id); - EXPECT_EQUAL(ser_to, f.mock_target->_ser_to); - EXPECT_EQUAL(777, f.mock_target->_available); - EXPECT_EQUAL(&f.mock_converter, f.mock_target->_bc); + EXPECT_EQ(DocId(7), f.mock_target->_doc_id); + EXPECT_EQ(ser_to, f.mock_target->_ser_to); + EXPECT_EQ(777, f.mock_target->_available); + EXPECT_EQ(&f.mock_converter, f.mock_target->_bc); } -TEST("onSerializeForAscendingSort() is forwarded with remapped LID to target vector") { - TEST_DO(check_onSerializeForAscendingSort_is_forwarded_with_remapped_lid< - SerializeFixture>()); +TEST(ImportedAttributeVectorTest, onSerializeForAscendingSort_is_forwarded_with_remapped_lid_to_target_vector) +{ + check_onSerializeForAscendingSort_is_forwarded_with_remapped_lid>(); } template @@ -526,19 +596,19 @@ void check_onSerializeForDescendingSort_is_forwarded_with_remapped_lid() { FixtureT f; int dummy_tag; void* ser_to = &dummy_tag; - EXPECT_EQUAL(f.mock_target->_return_value, + EXPECT_EQ(f.mock_target->_return_value, f.get_imported_attr()->serializeForDescendingSort( DocId(2), ser_to, 555, &f.mock_converter)); // child lid 2 -> parent lid 3 EXPECT_TRUE(f.mock_target->_descending_called); - EXPECT_EQUAL(DocId(3), f.mock_target->_doc_id); - EXPECT_EQUAL(ser_to, f.mock_target->_ser_to); - EXPECT_EQUAL(555, f.mock_target->_available); - EXPECT_EQUAL(&f.mock_converter, f.mock_target->_bc); + EXPECT_EQ(DocId(3), f.mock_target->_doc_id); + EXPECT_EQ(ser_to, f.mock_target->_ser_to); + EXPECT_EQ(555, f.mock_target->_available); + EXPECT_EQ(&f.mock_converter, f.mock_target->_bc); } -TEST("onSerializeForDescendingSort() is forwarded with remapped LID to target vector") { - TEST_DO(check_onSerializeForDescendingSort_is_forwarded_with_remapped_lid< - SerializeFixture>()); +TEST(ImportedAttributeVectorTest, onSerializeForDescendingSort_is_forwarded_with_remapped_lid_to_target_vector) +{ + check_onSerializeForDescendingSort_is_forwarded_with_remapped_lid>(); } struct TensorAttrFixture : Fixture { @@ -571,7 +641,7 @@ struct TensorAttrFixture : Fixture { Value::UP getTensor(DocId docId) { auto imp_attr = this->get_imported_attr(); const ITensorAttribute *tensorAttr = imp_attr->asTensorAttribute(); - ASSERT_TRUE(tensorAttr != nullptr); + assert(tensorAttr != nullptr); return tensorAttr->getTensor(docId); } void assertNoTensor(DocId docId) { @@ -581,7 +651,7 @@ struct TensorAttrFixture : Fixture { void assertTensor(DocId docId, const Value &expTensor) { auto tensor = getTensor(docId); ASSERT_TRUE(!!tensor); - EXPECT_EQUAL(expTensor, *tensor); + EXPECT_EQ(expTensor, *tensor); } void assertTensors() { assertNoTensor(0); @@ -594,16 +664,18 @@ struct TensorAttrFixture : Fixture { TensorAttrFixture::~TensorAttrFixture() = default; -TEST_F("Imported sparse tensor", TensorAttrFixture(false)) +TEST(ImportedAttributeVectorTest, imported_sparse_tensor) { + TensorAttrFixture f(false); f.assertTensors(); } -TEST_F("Imported dense tensor", TensorAttrFixture(true)) +TEST(ImportedAttributeVectorTest, imported_dense_tensor) { + TensorAttrFixture f(true); f.assertTensors(); } } -TEST_MAIN() { TEST_RUN_ALL(); } +GTEST_MAIN_RUN_ALL_TESTS() diff --git a/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp b/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp index 7d02949c9944..57ee3e8470cf 100644 --- a/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp +++ b/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp @@ -8,8 +8,7 @@ #include #include #include -#include -#include +#include namespace search::attribute { @@ -48,8 +47,8 @@ struct Fixture : ImportedAttributeFixture { return create_iterator(ctx, match, true); } - void assertSearch(const std::vector &expDocIds, SearchIterator &iter) { - EXPECT_EQUAL(SimpleResult(expDocIds), SimpleResult().searchStrict(iter, get_imported_attr()->getNumDocs())); + SimpleResult search(SearchIterator& iter) { + return SimpleResult().searchStrict(iter, get_imported_attr()->getNumDocs()); } }; @@ -57,38 +56,53 @@ Fixture::~Fixture() = default; template bool is_hit_with_weight(Iterator& iter, TermFieldMatchData& match, DocId lid, int32_t weight) { - if (!EXPECT_TRUE(iter.seek(lid))) { + bool failed = false; + EXPECT_TRUE(iter.seek(lid)) << (failed = true, ""); + if (failed) { return false; } iter.unpack(lid); - return (EXPECT_EQUAL(lid, match.getDocId()) && - EXPECT_EQUAL(weight, match.getWeight())); + EXPECT_EQ(lid, match.getDocId()) << (failed = true, ""); + if (failed) { + return false; + } + EXPECT_EQ(weight, match.getWeight()) << (failed = true, ""); + return !failed; } template bool is_strict_hit_with_weight(Iterator& iter, TermFieldMatchData& match, DocId seek_lid, DocId expected_lid, int32_t weight) { + bool failed = false; iter.seek(seek_lid); - if (!EXPECT_EQUAL(expected_lid, iter.getDocId())) { + EXPECT_EQ(expected_lid, iter.getDocId()) << (failed = true, ""); + if (failed) { return false; } iter.unpack(expected_lid); - return (EXPECT_EQUAL(expected_lid, match.getDocId()) && - EXPECT_EQUAL(weight, match.getWeight())); + EXPECT_EQ(expected_lid, match.getDocId()) << (failed = true, ""); + if (failed) { + return false; + } + EXPECT_EQ(weight, match.getWeight()) << (failed = true, ""); + return !failed; } -TEST_F("calc_hit_estimate() returns document count of reference attribute when not using fast-search target attribute", Fixture) { +TEST(ImportedSearchContextTest, calc_hit_estimate_returns_document_count_of_reference_attribute_when_not_using_fast_search_target_attribute) +{ + Fixture f; add_n_docs_with_undefined_values(*f.target_attr, 10); add_n_docs_with_undefined_values(*f.reference_attr, 101); auto ctx = f.create_context(word_term("foo")); auto est = ctx->calc_hit_estimate(); - EXPECT_EQUAL(101u, est.est_hits()); + EXPECT_EQ(101u, est.est_hits()); EXPECT_TRUE(est.is_unknown()); } -TEST_F("calc_hit_estimate() estimates hits when using fast-search target attribute", Fixture(false, FastSearchConfig::ExplicitlyEnabled)) +TEST(ImportedSearchContextTest, calc_hit_estimate_estimates_hits_when_using_fast_search_target_attribute) { + Fixture f(false, FastSearchConfig::ExplicitlyEnabled); constexpr uint32_t target_docs = 1000; constexpr uint32_t docs = 10000; constexpr uint32_t target_gids = 200; @@ -119,7 +133,7 @@ TEST_F("calc_hit_estimate() estimates hits when using fast-search target attribu auto ctx = f.create_context(word_term("10")); // Exact count: 0 target hits => 0 auto est = ctx->calc_hit_estimate(); - EXPECT_EQUAL(0u, est.est_hits()); + EXPECT_EQ(0u, est.est_hits()); EXPECT_FALSE(est.is_unknown()); TermFieldMatchData match; auto iter = f.create_iterator(*ctx, match, false); @@ -127,35 +141,43 @@ TEST_F("calc_hit_estimate() estimates hits when using fast-search target attribu ctx = f.create_context(word_term("20")); // Exact count: 2 target hits, 2 docs / target doc => 2 * 2 = 4 est = ctx->calc_hit_estimate(); - EXPECT_EQUAL(4u, est.est_hits()); + EXPECT_EQ(4u, est.est_hits()); EXPECT_FALSE(est.is_unknown()); ctx = f.create_context(word_term("30")); // Approximation: 110 target hits => 110 * 10001 / 1001 = 1099 est = ctx->calc_hit_estimate(); - EXPECT_EQUAL(1099u, est.est_hits()); + EXPECT_EQ(1099u, est.est_hits()); EXPECT_FALSE(est.is_unknown()); } -TEST_F("attributeName() returns imported attribute name", Fixture) { +TEST(ImportedSearchContextTest, attributeName_returns_imported_attribute_name) +{ + Fixture f; auto ctx = f.create_context(word_term("foo")); - EXPECT_EQUAL(f.default_imported_attr_name(), ctx->attributeName()); + EXPECT_EQ(f.default_imported_attr_name(), ctx->attributeName()); } -TEST_F("valid() forwards to target search context", Fixture) { +TEST(ImportedSearchContextTest, valid_forwards_to_target_search_context) +{ + Fixture f; auto ctx = f.create_context(word_term("foo")); - EXPECT_EQUAL(ctx->target_search_context().valid(), ctx->valid()); + EXPECT_EQ(ctx->target_search_context().valid(), ctx->valid()); } -TEST_F("getAsIntegerTerm() forwards to target search context", Fixture) { +TEST(ImportedSearchContextTest, getAsIntegerTerm_forwards_to_target_search_context) +{ + Fixture f; auto ctx = f.create_context(word_term("foo")); // No operator== or printing for Range, so doing this the hard way auto expected_range = ctx->target_search_context().getAsIntegerTerm(); auto actual_range = ctx->getAsIntegerTerm(); - EXPECT_EQUAL(expected_range.lower(), actual_range.lower()); - EXPECT_EQUAL(expected_range.upper(), actual_range.upper()); + EXPECT_EQ(expected_range.lower(), actual_range.lower()); + EXPECT_EQ(expected_range.upper(), actual_range.upper()); } -TEST_F("Non-strict iterator not marked as strict", Fixture) { +TEST(ImportedSearchContextTest, non_strict_iterator_not_marked_as_strict) +{ + Fixture f; auto ctx = f.create_context(word_term("5678")); TermFieldMatchData match; auto iter = f.create_non_strict_iterator(*ctx, match); @@ -163,7 +185,9 @@ TEST_F("Non-strict iterator not marked as strict", Fixture) { EXPECT_TRUE(iter->is_strict() == Trinary::False); // No EXPECT_EQUALS printing of Trinary... } -TEST_F("Non-strict iterator seek forwards to target attribute", Fixture) { +TEST(ImportedSearchContextTest, non_strict_iterator_seek_forwards_to_target_attribute) +{ + Fixture f; reset_with_single_value_reference_mappings( f, BasicType::INT32, {{DocId(1), dummy_gid(3), DocId(3), 1234}, @@ -175,19 +199,21 @@ TEST_F("Non-strict iterator seek forwards to target attribute", Fixture) { auto iter = f.create_non_strict_iterator(*ctx, match); EXPECT_FALSE(iter->isAtEnd()); - EXPECT_EQUAL(iter->beginId(), iter->getDocId()); + EXPECT_EQ(iter->beginId(), iter->getDocId()); EXPECT_FALSE(iter->seek(DocId(1))); - EXPECT_EQUAL(iter->beginId(), iter->getDocId()); // Non-strict iterator does not change current ID + EXPECT_EQ(iter->beginId(), iter->getDocId()); // Non-strict iterator does not change current ID EXPECT_TRUE(iter->seek(DocId(3))); - EXPECT_EQUAL(DocId(3), iter->getDocId()); + EXPECT_EQ(DocId(3), iter->getDocId()); EXPECT_FALSE(iter->seek(DocId(5))); - EXPECT_EQUAL(DocId(3), iter->getDocId()); // Still unchanged + EXPECT_EQ(DocId(3), iter->getDocId()); // Still unchanged } -TEST_F("Non-strict iterator unpacks target match data for single value hit", Fixture) { +TEST(ImportedSearchContextTest, non_strict_iterator_unpacks_target_match_data_for_single_value_hit) +{ + Fixture f; reset_with_single_value_reference_mappings( f, BasicType::INT32, {{DocId(1), dummy_gid(3), DocId(3), 1234}, @@ -217,16 +243,20 @@ struct ArrayValueFixture : Fixture { ArrayValueFixture::~ArrayValueFixture() = default; -TEST_F("Non-strict iterator handles unmapped LIDs", ArrayValueFixture) { +TEST(ImportedSearchContextTest, non_strict_iterator_handles_unmapped_lids) +{ + ArrayValueFixture f; auto ctx = f.create_context(word_term("1234")); TermFieldMatchData match; auto iter = f.create_non_strict_iterator(*ctx, match); EXPECT_FALSE(iter->seek(DocId(2))); - EXPECT_EQUAL(iter->beginId(), iter->getDocId()); + EXPECT_EQ(iter->beginId(), iter->getDocId()); } -TEST_F("Non-strict iterator handles seek outside of LID space", ArrayValueFixture) { +TEST(ImportedSearchContextTest, non_strict_iterator_handles_seek_outside_of_lid_space) +{ + ArrayValueFixture f; auto ctx = f.create_context(word_term("1234")); TermFieldMatchData match; auto iter = f.create_non_strict_iterator(*ctx, match); @@ -236,7 +266,9 @@ TEST_F("Non-strict iterator handles seek outside of LID space", ArrayValueFixtur EXPECT_TRUE(iter->isAtEnd()); } -TEST_F("Non-strict iterator unpacks target match data for array hit", ArrayValueFixture) { +TEST(ImportedSearchContextTest, non_strict_iterator_unpacks_target_match_data_for_array_hit) +{ + ArrayValueFixture f; auto ctx = f.create_context(word_term("1234")); TermFieldMatchData match; auto iter = f.create_non_strict_iterator(*ctx, match); @@ -261,7 +293,9 @@ struct WsetValueFixture : Fixture { WsetValueFixture::~WsetValueFixture() = default; -TEST_F("Non-strict iterator unpacks target match data for weighted set hit", WsetValueFixture) { +TEST(ImportedSearchContextTest, non_strict_iterator_unpacks_target_match_data_for_weighted_set_hit) +{ + WsetValueFixture f; auto ctx = f.create_context(word_term("foo")); TermFieldMatchData match; auto iter = f.create_non_strict_iterator(*ctx, match); @@ -270,7 +304,9 @@ TEST_F("Non-strict iterator unpacks target match data for weighted set hit", Wse EXPECT_TRUE(is_hit_with_weight(*iter, match, DocId(6), 42)); } -TEST_F("Strict iterator is marked as strict", Fixture) { +TEST(ImportedSearchContextTest, strict_iterator_is_marked_as_strict) +{ + Fixture f; auto ctx = f.create_context(word_term("5678")); ctx->fetchPostings(queryeval::ExecuteInfo::FULL, true); TermFieldMatchData match; @@ -279,7 +315,9 @@ TEST_F("Strict iterator is marked as strict", Fixture) { EXPECT_TRUE(iter->is_strict() == Trinary::True); // No EXPECT_EQUALS printing of Trinary... } -TEST_F("Non-strict blueprint with high hit rate is strict", Fixture(false, FastSearchConfig::ExplicitlyEnabled)) { +TEST(ImportedSearchContextTest, non_strict_blueprint_with_high_hit_rate_is_strict) +{ + Fixture f(false, FastSearchConfig::ExplicitlyEnabled); auto ctx = f.create_context(word_term("5678")); ctx->fetchPostings(queryeval::ExecuteInfo::createForTest(0.02), false); TermFieldMatchData match; @@ -288,7 +326,9 @@ TEST_F("Non-strict blueprint with high hit rate is strict", Fixture(false, FastS EXPECT_TRUE(iter->is_strict() == Trinary::True); } -TEST_F("Non-strict blueprint with low hit rate is non-strict", Fixture(false, FastSearchConfig::ExplicitlyEnabled)) { +TEST(ImportedSearchContextTest, non_strict_blueprint_with_low_hit_rate_is_non_strict) +{ + Fixture f(false, FastSearchConfig::ExplicitlyEnabled); auto ctx = f.create_context(word_term("5678")); ctx->fetchPostings(queryeval::ExecuteInfo::createForTest(0.01), false); TermFieldMatchData match; @@ -313,33 +353,37 @@ SingleValueFixture::~SingleValueFixture() = default; // Strict iteration implicitly tests unmapped LIDs by its nature, so we don't have a separate test for that. -TEST_F("Strict iterator seeks to first available hit LID", SingleValueFixture) { +TEST(ImportedSearchContextTest, strict_iterator_seeks_to_first_available_hit_lid) +{ + SingleValueFixture f; auto ctx = f.create_context(word_term("5678")); ctx->fetchPostings(queryeval::ExecuteInfo::FULL, true); TermFieldMatchData match; auto iter = f.create_strict_iterator(*ctx, match); EXPECT_FALSE(iter->isAtEnd()); - EXPECT_EQUAL(DocId(3), iter->getDocId()); + EXPECT_EQ(DocId(3), iter->getDocId()); EXPECT_FALSE(iter->seek(DocId(1))); EXPECT_FALSE(iter->isAtEnd()); - EXPECT_EQUAL(DocId(3), iter->getDocId()); + EXPECT_EQ(DocId(3), iter->getDocId()); EXPECT_TRUE(iter->seek(DocId(3))); EXPECT_FALSE(iter->isAtEnd()); - EXPECT_EQUAL(DocId(3), iter->getDocId()); + EXPECT_EQ(DocId(3), iter->getDocId()); EXPECT_FALSE(iter->seek(DocId(4))); EXPECT_FALSE(iter->isAtEnd()); - EXPECT_EQUAL(DocId(5), iter->getDocId()); + EXPECT_EQ(DocId(5), iter->getDocId()); // Seeking beyond last hit exhausts doc id limit and marks iterator as done EXPECT_FALSE(iter->seek(DocId(6))); EXPECT_TRUE(iter->isAtEnd()); } -TEST_F("Strict iterator unpacks target match data for single value hit", SingleValueFixture) { +TEST(ImportedSearchContextTest, strict_iterator_unpacks_target_match_data_for_single_value_hit) +{ + SingleValueFixture f; auto ctx = f.create_context(word_term("5678")); ctx->fetchPostings(queryeval::ExecuteInfo::FULL, true); TermFieldMatchData match; @@ -351,7 +395,9 @@ TEST_F("Strict iterator unpacks target match data for single value hit", SingleV EXPECT_TRUE(is_strict_hit_with_weight(*iter, match, DocId(4), DocId(5), 1)); } -TEST_F("Strict iterator unpacks target match data for array hit", ArrayValueFixture) { +TEST(ImportedSearchContextTest, strict_iterator_unpacks_target_match_data_for_array_hit) +{ + ArrayValueFixture f; auto ctx = f.create_context(word_term("1234")); ctx->fetchPostings(queryeval::ExecuteInfo::FULL, true); TermFieldMatchData match; @@ -363,7 +409,9 @@ TEST_F("Strict iterator unpacks target match data for array hit", ArrayValueFixt EXPECT_TRUE(is_strict_hit_with_weight(*iter, match, DocId(4), DocId(4), 3)); } -TEST_F("Strict iterator unpacks target match data for weighted set hit", WsetValueFixture) { +TEST(ImportedSearchContextTest, strict_iterator_unpacks_target_match_data_for_weighted_set_hit) +{ + WsetValueFixture f; auto ctx = f.create_context(word_term("foo")); ctx->fetchPostings(queryeval::ExecuteInfo::FULL, true); TermFieldMatchData match; @@ -374,7 +422,9 @@ TEST_F("Strict iterator unpacks target match data for weighted set hit", WsetVal EXPECT_TRUE(is_strict_hit_with_weight(*iter, match, DocId(3), DocId(6), 42)); } -TEST_F("Strict iterator handles seek outside of LID space", ArrayValueFixture) { +TEST(ImportedSearchContextTest, strict_iterator_handles_seek_outside_of_lid_space) +{ + ArrayValueFixture f; auto ctx = f.create_context(word_term("1234")); ctx->fetchPostings(queryeval::ExecuteInfo::FULL, true); TermFieldMatchData match; @@ -385,7 +435,9 @@ TEST_F("Strict iterator handles seek outside of LID space", ArrayValueFixture) { EXPECT_TRUE(iter->isAtEnd()); } -TEST_F("matches() performs GID mapping and forwards to target attribute", SingleValueFixture) { +TEST(ImportedSearchContextTest, matches_performs_gid_mapping_and_forwards_to_target_attribute) +{ + SingleValueFixture f; auto ctx = f.create_context(word_term("5678")); EXPECT_FALSE(ctx->matches(DocId(2))); EXPECT_TRUE(ctx->matches(DocId(3))); @@ -393,20 +445,24 @@ TEST_F("matches() performs GID mapping and forwards to target attribute", Single EXPECT_TRUE(ctx->matches(DocId(5))); } -TEST_F("matches(weight) performs GID mapping and forwards to target attribute", WsetValueFixture) { +TEST(ImportedSearchContextTest, matches_weight_performs_gid_mapping_and_forwards_to_target_attribute) +{ + WsetValueFixture f; auto ctx = f.create_context(word_term("foo")); int32_t weight = 0; EXPECT_FALSE(ctx->matches(DocId(1), weight)); - EXPECT_EQUAL(0, weight); // Unchanged + EXPECT_EQ(0, weight); // Unchanged EXPECT_TRUE(ctx->matches(DocId(2), weight)); - EXPECT_EQUAL(-5, weight); + EXPECT_EQ(-5, weight); EXPECT_TRUE(ctx->matches(DocId(6), weight)); - EXPECT_EQUAL(42, weight); + EXPECT_EQ(42, weight); } -TEST_F("Multiple iterators can be created from the same context", SingleValueFixture) { +TEST(ImportedSearchContextTest, multiple_iterators_can_be_created_from_the_same_context) +{ + SingleValueFixture f; auto ctx = f.create_context(word_term("5678")); ctx->fetchPostings(queryeval::ExecuteInfo::FULL, true); @@ -428,8 +484,9 @@ TEST_F("Multiple iterators can be created from the same context", SingleValueFix EXPECT_TRUE(is_hit_with_weight(*iter2, match2, DocId(3), 1)); } -TEST_F("original lid range is used by search context", SingleValueFixture) +TEST(ImportedSearchContextTest, original_lid_range_is_used_by_search_context) { + SingleValueFixture f; auto first_ctx = f.create_context(word_term("5678")); add_n_docs_with_undefined_values(*f.reference_attr, 1); f.map_reference(DocId(10), dummy_gid(5), DocId(5)); @@ -438,12 +495,13 @@ TEST_F("original lid range is used by search context", SingleValueFixture) EXPECT_TRUE(second_ctx->matches(DocId(10))); } -TEST_F("Original target lid range is used by search context", SingleValueFixture) +TEST(ImportedSearchContextTest, original_target_lid_range_is_used_by_search_context) { - EXPECT_EQUAL(11u, f.target_attr->getNumDocs()); + SingleValueFixture f; + EXPECT_EQ(11u, f.target_attr->getNumDocs()); auto first_ctx = f.create_context(word_term("2345")); add_n_docs_with_undefined_values(*f.target_attr, 1); - EXPECT_EQUAL(12u, f.target_attr->getNumDocs()); + EXPECT_EQ(12u, f.target_attr->getNumDocs()); auto typed_target_attr = f.template target_attr_as(); ASSERT_TRUE(typed_target_attr->update(11, 2345)); f.target_attr->commit(); @@ -455,9 +513,11 @@ TEST_F("Original target lid range is used by search context", SingleValueFixture // Note: this uses an underlying string attribute, as queryTerm() does not seem to // implemented at all for (single) numeric attributes. Intentional? -TEST_F("queryTerm() returns term context was created with", WsetValueFixture) { +TEST(ImportedSearchContextTest, queryTerm_returns_term_context_was_created_with) +{ + WsetValueFixture f; auto ctx = f.create_context(word_term("helloworld")); - EXPECT_EQUAL(std::string("helloworld"), std::string(ctx->queryTerm()->getTerm())); + EXPECT_EQ(std::string("helloworld"), std::string(ctx->queryTerm()->getTerm())); } struct SearchCacheFixture : Fixture { @@ -486,46 +546,48 @@ makeSearchCacheEntry(const std::vector docIds, uint32_t docIdLimit) return std::make_shared(IDocumentMetaStoreContext::IReadGuard::SP(), bitVector, docIdLimit); } -TEST_F("Bit vector from search cache is used if found", SearchCacheFixture) +TEST(ImportedSearchContextTest, bitvector_from_search_cache_is_used_if_found) { + SearchCacheFixture f; f.imported_attr->getSearchCache()->insert("5678", makeSearchCacheEntry({2, 6}, f.get_imported_attr()->getNumDocs())); auto ctx = f.create_context(word_term("5678")); ctx->fetchPostings(queryeval::ExecuteInfo::FULL, true); TermFieldMatchData match; auto iter = f.create_strict_iterator(*ctx, match); - TEST_DO(f.assertSearch({2, 6}, *iter)); // Note: would be {3, 5} if cache was not used - EXPECT_EQUAL(0u, f.document_meta_store->get_read_guard_cnt); + EXPECT_EQ(SimpleResult({2, 6}), f.search(*iter)); // Note: would be {3, 5} if cache was not used + EXPECT_EQ(0u, f.document_meta_store->get_read_guard_cnt); } -void -assertBitVector(const std::vector &expDocIds, const BitVector &bitVector) +std::vector +get_bitvector_hits(const BitVector &bitVector) { std::vector actDocsIds; bitVector.foreach_truebit([&](uint32_t docId){ actDocsIds.push_back(docId); }); - EXPECT_EQUAL(expDocIds, actDocsIds); + return actDocsIds; } -TEST_F("Entry is inserted into search cache if bit vector posting list is used", SearchCacheFixture) +TEST(ImportedSearchContextTest, entry_is_inserted_into_search_cache_if_bit_vector_posting_list_is_used) { - EXPECT_EQUAL(0u, f.imported_attr->getSearchCache()->size()); + SearchCacheFixture f; + EXPECT_EQ(0u, f.imported_attr->getSearchCache()->size()); auto old_mem_usage = f.imported_attr->get_memory_usage(); auto ctx = f.create_context(word_term("5678")); ctx->fetchPostings(queryeval::ExecuteInfo::FULL, true); TermFieldMatchData match; auto iter = f.create_strict_iterator(*ctx, match); - TEST_DO(f.assertSearch({3, 5}, *iter)); + EXPECT_EQ(SimpleResult({3, 5}), f.search(*iter)); - EXPECT_EQUAL(1u, f.imported_attr->getSearchCache()->size()); + EXPECT_EQ(1u, f.imported_attr->getSearchCache()->size()); auto new_mem_usage = f.imported_attr->get_memory_usage(); - EXPECT_LESS(old_mem_usage.usedBytes(), new_mem_usage.usedBytes()); - EXPECT_LESS(old_mem_usage.allocatedBytes(), new_mem_usage.allocatedBytes()); + EXPECT_LT(old_mem_usage.usedBytes(), new_mem_usage.usedBytes()); + EXPECT_LT(old_mem_usage.allocatedBytes(), new_mem_usage.allocatedBytes()); auto cacheEntry = f.imported_attr->getSearchCache()->find("5678"); - EXPECT_EQUAL(cacheEntry->docIdLimit, f.get_imported_attr()->getNumDocs()); - TEST_DO(assertBitVector({3, 5}, *cacheEntry->bitVector)); - EXPECT_EQUAL(1u, f.document_meta_store->get_read_guard_cnt); + EXPECT_EQ(cacheEntry->docIdLimit, f.get_imported_attr()->getNumDocs()); + EXPECT_EQ((std::vector{3, 5}), get_bitvector_hits(*cacheEntry->bitVector)); + EXPECT_EQ(1u, f.document_meta_store->get_read_guard_cnt); } } -TEST_MAIN() { TEST_RUN_ALL(); } +GTEST_MAIN_RUN_ALL_TESTS() diff --git a/searchlib/src/tests/features/imported_dot_product/imported_dot_product_test.cpp b/searchlib/src/tests/features/imported_dot_product/imported_dot_product_test.cpp index 47c631690a73..bbb8f7cf4d73 100644 --- a/searchlib/src/tests/features/imported_dot_product/imported_dot_product_test.cpp +++ b/searchlib/src/tests/features/imported_dot_product/imported_dot_product_test.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include using namespace search; @@ -115,7 +116,7 @@ struct ArrayFixture : FixtureBase { setup_integer_mappings_helper(int_type); break; default: - TEST_FATAL("unexpected integer type"); + FAIL() << "unexpected integer type"; } } @@ -136,7 +137,7 @@ struct ArrayFixture : FixtureBase { setup_float_mappings_helper(float_type); break; default: - TEST_FATAL("unexpected float type"); + FAIL() << "unexpected float type"; } } @@ -160,9 +161,13 @@ struct ArrayFixture : FixtureBase { } template static void verify(const dotproduct::ArrayParam & a, const dotproduct::ArrayParam & b) { - ASSERT_EQUAL(a.values.size(), b.values.size()); + ASSERT_EQ(a.values.size(), b.values.size()); for (size_t i(0); i < a.values.size(); i++) { - EXPECT_EQUAL(a.values[i], b.values[i]); + if constexpr (std::is_same_v || std::is_same_v) { + EXPECT_FLOAT_EQ(a.values[i], b.values[i]); + } else { + EXPECT_EQ(a.values[i], b.values[i]); + } } } template @@ -203,89 +208,125 @@ struct ArrayFixture : FixtureBase { ArrayFixture::~ArrayFixture() = default; -TEST_F("Dense i32/i64 array dot products can be evaluated with string parameter", ArrayFixture) { +TEST(ImportedDotProductTest, dense_i32_and_i64_array_dot_products_can_be_evaluated_with_string_parameter) +{ + ArrayFixture f; f.check_all_integer_executions(2*2 + 3*3 + 5*4, "[2 3 4]", DocId(1)); } -TEST_F("Dense float/double array dot products can be evaluated with string parameter", ArrayFixture) { +TEST(ImportedDotProductTest, dense_float_and_double_array_dot_products_can_be_evaluated_with_string_parameter) +{ + ArrayFixture f; f.check_all_float_executions(2.2*7.7 + 3.3*11.11 + 5.5*13.13, "[7.7 11.11 13.13]", DocId(2)); } -TEST_F("Zero-length i32/i64 array query vector evaluates to zero", ArrayFixture) { +TEST(ImportedDotProductTest, zero_length_i32_and_i64_array_query_vector_evaluates_to_zero) +{ + ArrayFixture f; f.check_all_integer_executions(0, "[]", DocId(1)); } -TEST_F("Zero-length float/double array query vector evaluates to zero", ArrayFixture) { +TEST(ImportedDotProductTest, zero_length_float_and_double_array_query_vector_evaluates_to_zero) +{ + ArrayFixture f; f.check_all_float_executions(0, "[]", DocId(1)); } -TEST_F("prepareSharedState emits i32 vector for i32 imported attribute", ArrayFixture) { +TEST(ImportedDotProductTest, prepareSharedState_emits_i32_vector_for_i32_imported_attribute) +{ + ArrayFixture f; f.setup_integer_mappings(BasicType::INT32); f.template check_prepare_state_output("[101 202 303]", dotproduct::ArrayParam({101, 202, 303})); } -TEST_F("prepareSharedState emits i64 vector for i64 imported attribute", ArrayFixture) { +TEST(ImportedDotProductTest, prepareSharedState_emits_i64_vector_for_i64_imported_attribute) +{ + ArrayFixture f; f.setup_integer_mappings(BasicType::INT64); f.template check_prepare_state_output("[101 202 303]", dotproduct::ArrayParam({101, 202, 303})); } -TEST_F("prepareSharedState emits float vector for float imported attribute", ArrayFixture) { +TEST(ImportedDotProductTest, prepareSharedState_emits_float_vector_for_float_imported_attribute) +{ + ArrayFixture f; f.setup_float_mappings(BasicType::FLOAT); f.template check_prepare_state_output("[10.1 20.2 30.3]", dotproduct::ArrayParam({10.1, 20.2, 30.3})); } -TEST_F("prepareSharedState emits double vector for double imported attribute", ArrayFixture) { +TEST(ImportedDotProductTest, prepareSharedState_emits_double_vector_for_double_imported_attribute) +{ + ArrayFixture f; f.setup_float_mappings(BasicType::DOUBLE); f.template check_prepare_state_output("[10.1 20.2 30.3]", dotproduct::ArrayParam({10.1, 20.2, 30.3})); } -TEST_F("prepareSharedState handles tensor as float from tensor for double imported attribute", ArrayFixture) { +TEST(ImportedDotProductTest, prepareSharedState_handles_tensor_as_float_from_tensor_for_double_imported_attribute) +{ + ArrayFixture f; f.setup_float_mappings(BasicType::DOUBLE); auto tensor = TensorSpec::from_expr("tensor(x[3]):[10.1,20.2,30.3]"); f.template check_prepare_state_output(tensor, dotproduct::ArrayParam({10.1, 20.2, 30.3})); } -TEST_F("prepareSharedState handles tensor as double from tensor for double imported attribute", ArrayFixture) { +TEST(ImportedDotProductTest, prepareSharedState_handles_tensor_as_double_from_tensor_for_double_imported_attribute) +{ + ArrayFixture f; f.setup_float_mappings(BasicType::DOUBLE); auto tensor = TensorSpec::from_expr("tensor(x[3]):[10.1,20.2,30.3]"); f.template check_prepare_state_output(tensor, dotproduct::ArrayParam({10.1, 20.2, 30.3})); } -TEST_F("prepareSharedState handles tensor as float from tensor for float imported attribute", ArrayFixture) { +TEST(ImportedDotProductTest, prepareSharedState_handles_tensor_as_float_from_tensor_for_float_imported_attribute) +{ + ArrayFixture f; f.setup_float_mappings(BasicType::FLOAT); auto tensor = TensorSpec::from_expr("tensor(x[3]):[10.1,20.2,30.3]"); f.template check_prepare_state_output(tensor, dotproduct::ArrayParam({10.1, 20.2, 30.3})); } -TEST_F("prepareSharedState handles tensor as double from tensor for float imported attribute", ArrayFixture) { +TEST(ImportedDotProductTest, prepareSharedState_handles_tensor_as_double_from_tensor_for_float_imported_attribute) +{ + ArrayFixture f; f.setup_float_mappings(BasicType::FLOAT); auto tensor = TensorSpec::from_expr("tensor(x[3]):[10.1,20.2,30.3]"); f.template check_prepare_state_output(tensor, dotproduct::ArrayParam({10.1, 20.2, 30.3})); } -TEST_F("Dense i32/i64 array dot product can be evaluated with pre-parsed object parameter", ArrayFixture) { +TEST(ImportedDotProductTest, dense_i32_and_i64_array_dot_product_can_be_evaluated_with_pre_parsed_object_parameter) +{ + ArrayFixture f; f.check_all_integer_executions(2*5 + 3*6 + 5*7, "[2 3 4]", DocId(1), "[5 6 7]"); // String input is ignored in favor of stored object } -TEST_F("Dense float/double array dot product can be evaluated with pre-parsed object parameter", ArrayFixture) { +TEST(ImportedDotProductTest, dense_float_and_double_array_dot_product_can_be_evaluated_with_pre_parsed_object_parameter) +{ + ArrayFixture f; f.check_all_float_executions(2.2*7.7 + 3.3*11.11 + 5.5*13.13, "[2.0 3.0 4.0]", DocId(2), "[7.7 11.11 13.13]"); } -TEST_F("Sparse i32/i64 array dot products can be evaluated with string parameter", ArrayFixture) { +TEST(ImportedDotProductTest, sparse_i32_and_i64_array_dot_products_can_be_evaluated_with_string_parameter) +{ + ArrayFixture f; // Have an outlier index to prevent auto-flattening of sparse input f.check_all_integer_executions(2*13 + 4*23, "{0:2,3:4,50:100}", DocId(5)); } -TEST_F("Sparse float/double array dot products can be evaluated with string parameter", ArrayFixture) { +TEST(ImportedDotProductTest, sparse_float_and_double_array_dot_products_can_be_evaluated_with_string_parameter) +{ + ArrayFixture f; f.check_all_float_executions(2.5*13.1 + 4.25*23.4, "{0:2.5,3:4.25,50:100.1}", DocId(6)); } -TEST_F("Sparse i32/i64 array dot products can be evaluated with pre-parsed object parameter", ArrayFixture) { +TEST(ImportedDotProductTest, sparse_i32_and_i64_array_dot_products_can_be_evaluated_with_pre_parsed_object_parameter) +{ + ArrayFixture f; // As before, we cheat a bit by having a different raw string vector than the pre-parsed vector. f.check_all_integer_executions(2*13 + 4*23, "[0 0 0]", DocId(5), "{0:2,3:4,50:100}"); } -TEST_F("Sparse float/double array dot products can be evaluated with pre-parsed object parameter", ArrayFixture) { +TEST(ImportedDotProductTest, sparse_float_and_double_array_dot_products_can_be_evaluated_with_pre_parsed_object_parameter) +{ + ArrayFixture f; f.check_all_float_executions(2.5*13.1 + 4.25*23.4, "[0 0 0]", DocId(6), "{0:2.5,3:4.25,50:100.1}"); } @@ -301,11 +342,15 @@ struct WsetFixture : FixtureBase { WsetFixture::~WsetFixture() = default; -TEST_F("i32/i64 wset dot products can be evaluated with string parameter", WsetFixture) { +TEST(ImportedDotProductTest, i32_and_i64_wset_dot_products_can_be_evaluated_with_string_parameter) +{ + WsetFixture f; f.check_all_integer_executions(21*7 + 19*13, "{200:21,300:19,999:1234}", DocId(3)); } -TEST_F("string wset dot products can be evaluated with string parameter", WsetFixture) { +TEST(ImportedDotProductTest, string_wset_dot_products_can_be_evaluated_with_string_parameter) +{ + WsetFixture f; std::vector doc7_values{{WeightedString("bar", 7), WeightedString("baz", 41)}}; reset_with_wset_value_reference_mappings( f, BasicType::STRING, @@ -313,7 +358,9 @@ TEST_F("string wset dot products can be evaluated with string parameter", WsetFi f.check_single_execution(5*7 + 3*41, "{bar:5,baz:3,nosuchkey:1234}", DocId(3)); } -TEST_F("integer enum dot products can be evaluated with string parameter", WsetFixture) { +TEST(ImportedDotProductTest, integer_enum_dot_products_can_be_evaluated_with_string_parameter) +{ + WsetFixture f; const std::vector doc7_values({WeightedInt(200, 7), WeightedInt(300, 13)}); // We only check i32 here, since the enum (fast search) aspect is what matters here. reset_with_wset_value_reference_mappings( @@ -327,4 +374,4 @@ TEST_F("integer enum dot products can be evaluated with string parameter", WsetF // - pre-parsed vectors not currently implemented for weighted sets. // - non-imported cases should also be tested for prepareSharedState. -TEST_MAIN() { TEST_RUN_ALL(); } +GTEST_MAIN_RUN_ALL_TESTS() diff --git a/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h b/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h index ba8e9b51eb2e..b15be5929b87 100644 --- a/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h +++ b/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h @@ -16,7 +16,7 @@ #include #include #include -#include +#include namespace search { @@ -238,7 +238,7 @@ void assert_multi_value_matches(const ImportedAttributeFixture &f, PredicateType predicate) { AttributeContent content; content.fill(*f.get_imported_attr(), lid); - ASSERT_EQUAL(expected.size(), content.size()); + ASSERT_EQ(expected.size(), content.size()); std::vector actual(content.begin(), content.end()); std::vector wanted(expected.begin(), expected.end()); if constexpr (IsWeightedType::value) {