From 91ae7785e7fc132d9e3959be5810a488f125ac84 Mon Sep 17 00:00:00 2001 From: Geir Storli Date: Fri, 15 Feb 2019 13:32:13 +0000 Subject: Simplify tensor type used in update tests. --- document/src/tests/documentupdatetestcase.cpp | 44 +++++++++++++----------- document/src/vespa/document/base/testdocrepo.cpp | 2 +- 2 files changed, 25 insertions(+), 21 deletions(-) (limited to 'document') diff --git a/document/src/tests/documentupdatetestcase.cpp b/document/src/tests/documentupdatetestcase.cpp index b351299f2d1..b71c270d3e8 100644 --- a/document/src/tests/documentupdatetestcase.cpp +++ b/document/src/tests/documentupdatetestcase.cpp @@ -914,17 +914,21 @@ struct TensorUpdateFixture { Document::UP emptyDoc; Document updatedDoc; vespalib::string fieldName; + const TensorDataType &tensorDataType; vespalib::string tensorType; - TensorDataType tensorDataType; - TensorUpdateFixture(const vespalib::string &fieldName_ = "tensor", - const vespalib::string &tensorType_ = "tensor(x{},y{})") + const TensorDataType &extractTensorDataType() { + const auto &dataType = emptyDoc->getField(fieldName).getDataType(); + return dynamic_cast(dataType); + } + + TensorUpdateFixture(const vespalib::string &fieldName_ = "sparse_tensor") : docMan(), emptyDoc(docMan.createDocument()), updatedDoc(*emptyDoc), fieldName(fieldName_), - tensorType(tensorType_), - tensorDataType(vespalib::eval::ValueType::from_spec(tensorType)) + tensorDataType(extractTensorDataType()), + tensorType(tensorDataType.getTensorType().to_spec()) { CPPUNIT_ASSERT(!emptyDoc->getValue(fieldName)); } @@ -952,8 +956,8 @@ struct TensorUpdateFixture { } std::unique_ptr makeBaselineTensor() { - return makeTensor(spec().add({{"x", "a"}, {"y", "a"}}, 2) - .add({{"x", "a"}, {"y", "b"}}, 3)); + return makeTensor(spec().add({{"x", "a"}}, 2) + .add({{"x", "b"}}, 3)); } void applyUpdate(const ValueUpdate &update) { @@ -1024,30 +1028,30 @@ void DocumentUpdateTest::tensor_add_update_can_be_applied() { TensorUpdateFixture f; - f.assertApplyUpdate(f.spec().add({{"x", "a"}, {"y", "a"}}, 2) - .add({{"x", "a"}, {"y", "b"}}, 3), + f.assertApplyUpdate(f.spec().add({{"x", "a"}}, 2) + .add({{"x", "b"}}, 3), - TensorAddUpdate(f.makeTensor(f.spec().add({{"x", "a"}, {"y", "b"}}, 5) - .add({{"x", "a"}, {"y", "c"}}, 7))), + TensorAddUpdate(f.makeTensor(f.spec().add({{"x", "b"}}, 5) + .add({{"x", "c"}}, 7))), - f.spec().add({{"x", "a"}, {"y", "a"}}, 2) - .add({{"x", "a"}, {"y", "b"}}, 5) - .add({{"x", "a"}, {"y", "c"}}, 7)); + f.spec().add({{"x", "a"}}, 2) + .add({{"x", "b"}}, 5) + .add({{"x", "c"}}, 7)); } void DocumentUpdateTest::tensor_modify_update_can_be_applied() { TensorUpdateFixture f; - f.assertApplyUpdate(f.spec().add({{"x", "a"}, {"y", "a"}}, 2) - .add({{"x", "a"}, {"y", "b"}}, 3), + f.assertApplyUpdate(f.spec().add({{"x", "a"}}, 2) + .add({{"x", "b"}}, 3), TensorModifyUpdate(TensorModifyUpdate::Operation::REPLACE, - f.makeTensor(f.spec().add({{"x", "a"}, {"y", "b"}}, 5) - .add({{"x", "a"}, {"y", "c"}}, 7))), + f.makeTensor(f.spec().add({{"x", "b"}}, 5) + .add({{"x", "c"}}, 7))), - f.spec().add({{"x", "a"}, {"y", "a"}}, 2) - .add({{"x", "a"}, {"y", "b"}}, 5)); + f.spec().add({{"x", "a"}}, 2) + .add({{"x", "b"}}, 5)); } void diff --git a/document/src/vespa/document/base/testdocrepo.cpp b/document/src/vespa/document/base/testdocrepo.cpp index 5bbb06519ac..c8041d8c254 100644 --- a/document/src/vespa/document/base/testdocrepo.cpp +++ b/document/src/vespa/document/base/testdocrepo.cpp @@ -52,7 +52,7 @@ DocumenttypesConfig TestDocRepo::getDefaultConfig() { .addField("content", DataType::T_STRING) .addField("rawarray", Array(DataType::T_RAW)) .addField("structarray", structarray_id) - .addTensorField("tensor", "tensor(x{},y{})")); + .addTensorField("sparse_tensor", "tensor(x{})")); builder.document(type2_id, "testdoctype2", Struct("testdoctype2.header") .addField("onlyinchild", DataType::T_INT), -- cgit v1.2.3