summaryrefslogtreecommitdiffstats
path: root/eval/src/tests/tensor/tensor_address/tensor_address_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'eval/src/tests/tensor/tensor_address/tensor_address_test.cpp')
-rw-r--r--eval/src/tests/tensor/tensor_address/tensor_address_test.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/eval/src/tests/tensor/tensor_address/tensor_address_test.cpp b/eval/src/tests/tensor/tensor_address/tensor_address_test.cpp
new file mode 100644
index 00000000000..70f33bdf0c4
--- /dev/null
+++ b/eval/src/tests/tensor/tensor_address/tensor_address_test.cpp
@@ -0,0 +1,39 @@
+// Copyright 2016 Yahoo Inc. 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/vespalib/tensor/tensor_address.h>
+
+using namespace vespalib::tensor;
+
+void
+assertSortOrder(const TensorAddress::Elements &exp,
+ const TensorAddress::Elements &input)
+{
+ TensorAddress address(input);
+ EXPECT_EQUAL(exp, address.elements());
+}
+
+TEST("require that elements are sorted in constructor")
+{
+ assertSortOrder({{"a","1"},{"b","1"},{"c","1"}},
+ {{"c","1"},{"a","1"},{"b","1"}});
+}
+
+TEST("require that we can check whether a dimension is present")
+{
+ TensorAddress address({{"a","1"},{"b","1"}});
+ EXPECT_TRUE(address.hasDimension("a"));
+ EXPECT_TRUE(address.hasDimension("b"));
+ EXPECT_FALSE(address.hasDimension("c"));
+}
+
+TEST("require that tensor address sort order is defined")
+{
+ TensorAddress::Elements single = {{"a","1"}};
+ EXPECT_LESS(TensorAddress(single),
+ TensorAddress({{"a","1"},{"b","1"}}));
+ EXPECT_LESS(TensorAddress({{"a","1"},{"b","1"}}),
+ TensorAddress({{"a","1"},{"c","1"}}));
+}
+
+TEST_MAIN() { TEST_RUN_ALL(); }