summaryrefslogtreecommitdiffstats
path: root/eval/src/tests
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2018-03-15 10:57:57 +0000
committerHåvard Pettersen <havardpe@oath.com>2018-03-15 14:37:50 +0000
commit6c0d09b07f1ef9d5faccce302e0ca44db25be183 (patch)
tree158765aee266cf8411fb63487c8511f68db89e16 /eval/src/tests
parent7826d89cf412a8791e4ac35deb5f199e0e95526e (diff)
added generic DenseReplaceTypeFunction with test
Diffstat (limited to 'eval/src/tests')
-rw-r--r--eval/src/tests/tensor/dense_replace_type_function/CMakeLists.txt8
-rw-r--r--eval/src/tests/tensor/dense_replace_type_function/dense_replace_type_function_test.cpp67
2 files changed, 75 insertions, 0 deletions
diff --git a/eval/src/tests/tensor/dense_replace_type_function/CMakeLists.txt b/eval/src/tests/tensor/dense_replace_type_function/CMakeLists.txt
new file mode 100644
index 00000000000..dd4a8a58082
--- /dev/null
+++ b/eval/src/tests/tensor/dense_replace_type_function/CMakeLists.txt
@@ -0,0 +1,8 @@
+# Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(eval_dense_replace_type_function_test_app TEST
+ SOURCES
+ dense_replace_type_function_test.cpp
+ DEPENDS
+ vespaeval
+)
+vespa_add_test(NAME eval_dense_replace_type_function_test_app COMMAND eval_dense_replace_type_function_test_app)
diff --git a/eval/src/tests/tensor/dense_replace_type_function/dense_replace_type_function_test.cpp b/eval/src/tests/tensor/dense_replace_type_function/dense_replace_type_function_test.cpp
new file mode 100644
index 00000000000..0e774be3dc3
--- /dev/null
+++ b/eval/src/tests/tensor/dense_replace_type_function/dense_replace_type_function_test.cpp
@@ -0,0 +1,67 @@
+// Copyright 2018 Yahoo Holdings. 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/eval/eval/interpreted_function.h>
+#include <vespa/eval/tensor/default_tensor_engine.h>
+#include <vespa/eval/tensor/dense/dense_tensor_view.h>
+#include <vespa/eval/tensor/dense/dense_replace_type_function.h>
+#include <vespa/eval/eval/test/tensor_model.hpp>
+
+using namespace vespalib::eval::tensor_function;
+using namespace vespalib::eval::test;
+using namespace vespalib::eval;
+using namespace vespalib::tensor;
+using namespace vespalib;
+
+using CellsRef = DenseTensorView::CellsRef;
+
+const TensorEngine &engine = DefaultTensorEngine::ref();
+
+CellsRef getCellsRef(const eval::Value &value) {
+ return static_cast<const DenseTensorView &>(value).cellsRef();
+}
+
+struct ChildMock : Leaf {
+ bool is_mutable;
+ ChildMock(const ValueType &type) : Leaf(type), is_mutable(true) {}
+ bool result_is_mutable() const override { return is_mutable; }
+ InterpretedFunction::Instruction compile_self(Stash &) const override { abort(); }
+};
+
+struct Fixture {
+ Value::UP my_value;
+ ValueType new_type;
+ ChildMock mock_child;
+ DenseReplaceTypeFunction my_fun;
+ std::vector<TensorFunction::Child::CREF> children;
+ InterpretedFunction::State state;
+ Fixture()
+ : my_value(engine.from_spec(spec({x(10)}, N()))),
+ new_type(ValueType::from_spec("tensor(x[5],y[2])")),
+ mock_child(my_value->type()),
+ my_fun(new_type, mock_child),
+ children(),
+ state(engine)
+ {
+ my_fun.push_children(children);
+ state.stack.push_back(*my_value);
+ my_fun.compile_self(state.stash).perform(state);
+ ASSERT_EQUAL(children.size(), 1u);
+ ASSERT_EQUAL(state.stack.size(), 1u);
+ ASSERT_TRUE(!new_type.is_error());
+ }
+};
+
+TEST_F("require that DenseReplaceTypeFunction works as expected", Fixture()) {
+ EXPECT_EQUAL(f1.my_fun.result_type(), f1.new_type);
+ EXPECT_EQUAL(f1.my_fun.result_is_mutable(), true);
+ f1.mock_child.is_mutable = false;
+ EXPECT_EQUAL(f1.my_fun.result_is_mutable(), false);
+ EXPECT_EQUAL(&f1.children[0].get().get(), &f1.mock_child);
+ EXPECT_EQUAL(getCellsRef(f1.state.stack[0]).begin(), getCellsRef(*f1.my_value).begin());
+ EXPECT_EQUAL(getCellsRef(f1.state.stack[0]).end(), getCellsRef(*f1.my_value).end());
+ EXPECT_EQUAL(f1.state.stack[0].get().type(), f1.new_type);
+ fprintf(stderr, "%s\n", f1.my_fun.as_string().c_str());
+}
+
+TEST_MAIN() { TEST_RUN_ALL(); }