summaryrefslogtreecommitdiffstats
path: root/eval
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2021-01-11 16:03:42 +0000
committerArne Juul <arnej@verizonmedia.com>2021-01-11 16:10:32 +0000
commit024d645a666200544465db2b1e8a01b5583b343c (patch)
tree2ff8326001de0ed951add7a1887a365b4b0fbca0 /eval
parent61fcd38ea21f1877b4e1630179decb6df909a240 (diff)
add unit testing of factory copy()
Diffstat (limited to 'eval')
-rw-r--r--eval/src/tests/eval/fast_value/fast_value_test.cpp28
-rw-r--r--eval/src/tests/eval/simple_value/simple_value_test.cpp10
-rw-r--r--eval/src/tests/streamed/value/streamed_value_test.cpp10
3 files changed, 48 insertions, 0 deletions
diff --git a/eval/src/tests/eval/fast_value/fast_value_test.cpp b/eval/src/tests/eval/fast_value/fast_value_test.cpp
index 2124d4f169a..279f17a1ead 100644
--- a/eval/src/tests/eval/fast_value/fast_value_test.cpp
+++ b/eval/src/tests/eval/fast_value/fast_value_test.cpp
@@ -3,10 +3,12 @@
#include <vespa/eval/eval/fast_value.hpp>
#include <vespa/eval/eval/fast_value.h>
#include <vespa/eval/eval/value_codec.h>
+#include <vespa/eval/eval/test/tensor_model.hpp>
#include <vespa/vespalib/gtest/gtest.h>
using namespace vespalib;
using namespace vespalib::eval;
+using namespace vespalib::eval::test;
using Handle = SharedStringRepo::Handle;
@@ -140,4 +142,30 @@ TEST(FastValueBuilderTest, mixed_add_subspace_robustness) {
}
}
+std::vector<Layout> layouts = {
+ {},
+ {x(3)},
+ {x(3),y(5)},
+ {x(3),y(5),z(7)},
+ float_cells({x(3),y(5),z(7)}),
+ {x({"a","b","c"})},
+ {x({"a","b","c"}),y({"foo","bar"})},
+ {x({"a","b","c"}),y({"foo","bar"}),z({"i","j","k","l"})},
+ float_cells({x({"a","b","c"}),y({"foo","bar"}),z({"i","j","k","l"})}),
+ {x(3),y({"foo", "bar"}),z(7)},
+ {x({"a","b","c"}),y(5),z({"i","j","k","l"})},
+ float_cells({x({"a","b","c"}),y(5),z({"i","j","k","l"})})
+};
+
+TEST(FastValueBuilderFactoryTest, fast_values_can_be_copied) {
+ auto factory = FastValueBuilderFactory::get();
+ for (const auto &layout: layouts) {
+ TensorSpec expect = spec(layout, N());
+ std::unique_ptr<Value> value = value_from_spec(expect, factory);
+ std::unique_ptr<Value> copy = factory.copy(*value);
+ TensorSpec actual = spec_from_value(*copy);
+ EXPECT_EQ(actual, expect);
+ }
+}
+
GTEST_MAIN_RUN_ALL_TESTS()
diff --git a/eval/src/tests/eval/simple_value/simple_value_test.cpp b/eval/src/tests/eval/simple_value/simple_value_test.cpp
index ffc58df4a16..3a653b75172 100644
--- a/eval/src/tests/eval/simple_value/simple_value_test.cpp
+++ b/eval/src/tests/eval/simple_value/simple_value_test.cpp
@@ -83,6 +83,16 @@ TEST(SimpleValueTest, simple_values_can_be_converted_from_and_to_tensor_spec) {
}
}
+TEST(SimpleValueTest, simple_values_can_be_copied) {
+ for (const auto &layout: layouts) {
+ TensorSpec expect = spec(layout, N());
+ std::unique_ptr<Value> value = value_from_spec(expect, SimpleValueBuilderFactory::get());
+ std::unique_ptr<Value> copy = SimpleValueBuilderFactory::get().copy(*value);
+ TensorSpec actual = spec_from_value(*copy);
+ EXPECT_EQ(actual, expect);
+ }
+}
+
TEST(SimpleValueTest, simple_value_can_be_built_and_inspected) {
ValueType type = ValueType::from_spec("tensor<float>(x{},y[2],z{})");
const auto &factory = SimpleValueBuilderFactory::get();
diff --git a/eval/src/tests/streamed/value/streamed_value_test.cpp b/eval/src/tests/streamed/value/streamed_value_test.cpp
index 075595c5d2c..2f91c3b9390 100644
--- a/eval/src/tests/streamed/value/streamed_value_test.cpp
+++ b/eval/src/tests/streamed/value/streamed_value_test.cpp
@@ -83,6 +83,16 @@ TEST(StreamedValueTest, streamed_values_can_be_converted_from_and_to_tensor_spec
}
}
+TEST(StreamedValueTest, streamed_values_can_be_copied) {
+ for (const auto &layout: layouts) {
+ TensorSpec expect = spec(layout, N());
+ std::unique_ptr<Value> value = value_from_spec(expect, StreamedValueBuilderFactory::get());
+ std::unique_ptr<Value> copy = StreamedValueBuilderFactory::get().copy(*value);
+ TensorSpec actual = spec_from_value(*copy);
+ EXPECT_EQ(actual, expect);
+ }
+}
+
TEST(StreamedValueTest, streamed_value_can_be_built_and_inspected) {
ValueType type = ValueType::from_spec("tensor<float>(x{},y[2],z{})");
const auto &factory = StreamedValueBuilderFactory::get();