diff options
author | Geir Storli <geirst@yahooinc.com> | 2024-02-20 11:09:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-20 11:09:56 +0100 |
commit | 9e73f6c7986bd5217b589ca4858987ba78d5e8c2 (patch) | |
tree | 122897e87c81c8760855f7aab0e1b8dd13655e10 /searchlib | |
parent | de5f9fec5591b6edbabab0b0cb9412f4b12369c5 (diff) | |
parent | 4983e0fff8a95e20b8f3aaa1005fe6adcbb73a8a (diff) |
Merge pull request #30340 from vespa-engine/toregge/rewrite-tensor-from-labels-feature-unit-test-to-gtest
Rewrite tensorFromLabels feature unit test to gtest.
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/tests/features/tensor_from_labels/tensor_from_labels_test.cpp | 141 |
1 files changed, 73 insertions, 68 deletions
diff --git a/searchlib/src/tests/features/tensor_from_labels/tensor_from_labels_test.cpp b/searchlib/src/tests/features/tensor_from_labels/tensor_from_labels_test.cpp index f241398539a..c4bed915761 100644 --- a/searchlib/src/tests/features/tensor_from_labels/tensor_from_labels_test.cpp +++ b/searchlib/src/tests/features/tensor_from_labels/tensor_from_labels_test.cpp @@ -1,5 +1,4 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/testkit/test_kit.h> #include <vespa/searchlib/attribute/attributefactory.h> #include <vespa/searchlib/attribute/attributevector.h> @@ -9,13 +8,15 @@ #include <vespa/searchlib/features/tensor_from_labels_feature.h> #include <vespa/searchlib/fef/fef.h> #include <vespa/searchlib/fef/test/indexenvironment.h> -#include <vespa/searchlib/test/ft_test_app.h> +#define ENABLE_GTEST_MIGRATION +#include <vespa/searchlib/test/ft_test_app_base.h> #include <vespa/searchcommon/attribute/config.h> #include <vespa/eval/eval/function.h> #include <vespa/eval/eval/simple_value.h> #include <vespa/eval/eval/tensor_spec.h> #include <vespa/eval/eval/value.h> #include <vespa/eval/eval/test/value_compare.h> +#include <vespa/vespalib/gtest/gtest.h> using search::feature_t; using namespace search::fef; @@ -33,7 +34,7 @@ using AVC = search::attribute::Config; using AVBT = search::attribute::BasicType; using AVCT = search::attribute::CollectionType; using AttributePtr = search::AttributeVector::SP; -using FTA = FtTestApp; +using FTA = FtTestAppBase; Value::UP make_tensor(const TensorSpec &spec) { return SimpleValue::from_spec(spec); @@ -54,24 +55,28 @@ struct SetupFixture } }; -TEST_F("require that blueprint can be created from factory", SetupFixture) +TEST(TensorFromLabelsTest, require_that_blueprint_can_be_created_from_factory) { + SetupFixture f; EXPECT_TRUE(FTA::assertCreateInstance(f.blueprint, "tensorFromLabels")); } -TEST_F("require that setup fails if source spec is invalid", SetupFixture) +TEST(TensorFromLabelsTest, require_that_setup_fails_if_source_spec_is_invalid) { + SetupFixture f; FTA::FT_SETUP_FAIL(f.blueprint, f.indexEnv, StringList().add("source(foo)")); } -TEST_F("require that setup succeeds with attribute source", SetupFixture) +TEST(TensorFromLabelsTest, require_that_setup_succeeds_with_attribute_source) { + SetupFixture f; FTA::FT_SETUP_OK(f.blueprint, f.indexEnv, StringList().add("attribute(foo)"), StringList(), StringList().add("tensor")); } -TEST_F("require that setup succeeds with query source", SetupFixture) +TEST(TensorFromLabelsTest, require_that_setup_succeeds_with_query_source) { + SetupFixture f; FTA::FT_SETUP_OK(f.blueprint, f.indexEnv, StringList().add("query(foo)"), StringList(), StringList().add("tensor")); } @@ -87,7 +92,7 @@ struct ExecFixture setup_search_features(factory); setupAttributeVectors(); setupQueryEnvironment(); - ASSERT_TRUE(test.setup()); + EXPECT_TRUE(test.setup()); } void setupAttributeVectors() { std::vector<AttributePtr> attrs; @@ -134,102 +139,102 @@ struct ExecFixture // Tests for attribute source: -TEST_F("require that array string attribute can be converted to tensor (default dimension)", - ExecFixture("tensorFromLabels(attribute(astr))")) +TEST(TensorFromLabelsTest, require_that_array_string_attribute_can_be_converted_to_tensor_using_default_dimension) { - EXPECT_EQUAL(*make_tensor(TensorSpec("tensor(astr{})") - .add({{"astr", "a"}}, 1) - .add({{"astr", "b"}}, 1) - .add({{"astr", "c"}}, 1)), f.execute()); + ExecFixture f("tensorFromLabels(attribute(astr))"); + EXPECT_EQ(*make_tensor(TensorSpec("tensor(astr{})") + .add({{"astr", "a"}}, 1) + .add({{"astr", "b"}}, 1) + .add({{"astr", "c"}}, 1)), f.execute()); } -TEST_F("require that array string attribute can be converted to tensor (explicit dimension)", - ExecFixture("tensorFromLabels(attribute(astr),dim)")) +TEST(TensorFromLabelsTest, require_that_array_string_attribute_can_be_converted_to_tensor_using_explicit_dimension) { - EXPECT_EQUAL(*make_tensor(TensorSpec("tensor(dim{})") - .add({{"dim", "a"}}, 1) - .add({{"dim", "b"}}, 1) - .add({{"dim", "c"}}, 1)), f.execute()); + ExecFixture f("tensorFromLabels(attribute(astr),dim)"); + EXPECT_EQ(*make_tensor(TensorSpec("tensor(dim{})") + .add({{"dim", "a"}}, 1) + .add({{"dim", "b"}}, 1) + .add({{"dim", "c"}}, 1)), f.execute()); } -TEST_F("require that array integer attribute can be converted to tensor (default dimension)", - ExecFixture("tensorFromLabels(attribute(aint))")) +TEST(TensorFromLabelsTest, require_that_array_integer_attribute_can_be_converted_to_tensor_using_default_dimension) { - EXPECT_EQUAL(*make_tensor(TensorSpec("tensor(aint{})") - .add({{"aint", "7"}}, 1) - .add({{"aint", "3"}}, 1) - .add({{"aint", "5"}}, 1)), f.execute()); + ExecFixture f("tensorFromLabels(attribute(aint))"); + EXPECT_EQ(*make_tensor(TensorSpec("tensor(aint{})") + .add({{"aint", "7"}}, 1) + .add({{"aint", "3"}}, 1) + .add({{"aint", "5"}}, 1)), f.execute()); } -TEST_F("require that array attribute can be converted to tensor (explicit dimension)", - ExecFixture("tensorFromLabels(attribute(aint),dim)")) +TEST(TensorFromLabelsTest, require_that_array_attribute_can_be_converted_to_tensor_using_explicit_dimension) { - EXPECT_EQUAL(*make_tensor(TensorSpec("tensor(dim{})") - .add({{"dim", "7"}}, 1) - .add({{"dim", "3"}}, 1) - .add({{"dim", "5"}}, 1)), f.execute()); + ExecFixture f("tensorFromLabels(attribute(aint),dim)"); + EXPECT_EQ(*make_tensor(TensorSpec("tensor(dim{})") + .add({{"dim", "7"}}, 1) + .add({{"dim", "3"}}, 1) + .add({{"dim", "5"}}, 1)), f.execute()); } -TEST_F("require that single-value integer attribute can be converted to tensor (default dimension)", - ExecFixture("tensorFromLabels(attribute(sint))")) +TEST(TensorFromLabelsTest, require_that_single_value_integer_attribute_can_be_converted_to_tensor_using_default_dimension) { - EXPECT_EQUAL(*make_tensor(TensorSpec("tensor(sint{})") - .add({{"sint", "5"}}, 1)), f.execute()); + ExecFixture f("tensorFromLabels(attribute(sint))"); + EXPECT_EQ(*make_tensor(TensorSpec("tensor(sint{})") + .add({{"sint", "5"}}, 1)), f.execute()); } -TEST_F("require that single-value integer attribute can be converted to tensor (explicit dimension)", - ExecFixture("tensorFromLabels(attribute(sint),foobar)")) +TEST(TensorFromLabelsTest, require_that_single_value_integer_attribute_can_be_converted_to_tensor_using_explicit_dimension) { - EXPECT_EQUAL(*make_tensor(TensorSpec("tensor(foobar{})") - .add({{"foobar", "5"}}, 1)), f.execute()); + ExecFixture f("tensorFromLabels(attribute(sint),foobar)"); + EXPECT_EQ(*make_tensor(TensorSpec("tensor(foobar{})") + .add({{"foobar", "5"}}, 1)), f.execute()); } -TEST_F("require that empty tensor is created if attribute does not exists", - ExecFixture("tensorFromLabels(attribute(null))")) +TEST(TensorFromLabelsTest, require_that_empty_tensor_is_created_if_attribute_does_not_exists) { - EXPECT_EQUAL(*make_empty("tensor(null{})"), f.execute()); + ExecFixture f("tensorFromLabels(attribute(null))"); + EXPECT_EQ(*make_empty("tensor(null{})"), f.execute()); } -TEST_F("require that empty tensor is created if attribute type is not supported", - ExecFixture("tensorFromLabels(attribute(wsstr))")) +TEST(TensorFromLabelsTest, require_that_empty_tensor_is_created_if_attribute_type_is_not_supported) { - EXPECT_EQUAL(*make_empty("tensor(wsstr{})"), f.execute()); + ExecFixture f("tensorFromLabels(attribute(wsstr))"); + EXPECT_EQ(*make_empty("tensor(wsstr{})"), f.execute()); } // Tests for query source: -TEST_F("require that string array from query can be converted to tensor (default dimension)", - ExecFixture("tensorFromLabels(query(astr_query))")) +TEST(TensorFromLabelsTest, require_that_string_array_from_query_can_be_converted_to_tensor_using_default_dimension) { - EXPECT_EQUAL(*make_tensor(TensorSpec("tensor(astr_query{})") - .add({{"astr_query", "d"}}, 1) - .add({{"astr_query", "e"}}, 1) - .add({{"astr_query", "f"}}, 1)), f.execute()); + ExecFixture f("tensorFromLabels(query(astr_query))"); + EXPECT_EQ(*make_tensor(TensorSpec("tensor(astr_query{})") + .add({{"astr_query", "d"}}, 1) + .add({{"astr_query", "e"}}, 1) + .add({{"astr_query", "f"}}, 1)), f.execute()); } -TEST_F("require that integer array from query can be converted to tensor (default dimension)", - ExecFixture("tensorFromLabels(query(aint_query))")) +TEST(TensorFromLabelsTest, require_that_integer_array_from_query_can_be_converted_to_tensor_using_default_dimension) { - EXPECT_EQUAL(*make_tensor(TensorSpec("tensor(aint_query{})") - .add({{"aint_query", "13"}}, 1) - .add({{"aint_query", "17"}}, 1) - .add({{"aint_query", "11"}}, 1)), f.execute()); + ExecFixture f("tensorFromLabels(query(aint_query))"); + EXPECT_EQ(*make_tensor(TensorSpec("tensor(aint_query{})") + .add({{"aint_query", "13"}}, 1) + .add({{"aint_query", "17"}}, 1) + .add({{"aint_query", "11"}}, 1)), f.execute()); } -TEST_F("require that string array from query can be converted to tensor (explicit dimension)", - ExecFixture("tensorFromLabels(query(astr_query),dim)")) +TEST(TensorFromLabelsTest, require_that_string_array_from_query_can_be_converted_to_tensor_using_explicit_dimension) { - EXPECT_EQUAL(*make_tensor(TensorSpec("tensor(dim{})") - .add({{"dim", "d"}}, 1) - .add({{"dim", "e"}}, 1) - .add({{"dim", "f"}}, 1)), f.execute()); + ExecFixture f("tensorFromLabels(query(astr_query),dim)"); + EXPECT_EQ(*make_tensor(TensorSpec("tensor(dim{})") + .add({{"dim", "d"}}, 1) + .add({{"dim", "e"}}, 1) + .add({{"dim", "f"}}, 1)), f.execute()); } -TEST_F("require that empty tensor is created if query parameter is not found", - ExecFixture("tensorFromLabels(query(null))")) +TEST(TensorFromLabelsTest, require_that_empty_tensor_is_created_if_query_parameter_is_not_found) { - EXPECT_EQUAL(*make_empty("tensor(null{})"), f.execute()); + ExecFixture f("tensorFromLabels(query(null))"); + EXPECT_EQ(*make_empty("tensor(null{})"), f.execute()); } -TEST_MAIN() { TEST_RUN_ALL(); } +GTEST_MAIN_RUN_ALL_TESTS() |