[nncc.core] Simplify tensor tests with constructor (#194)
author박종현/동작제어Lab(SR)/Senior Engineer/삼성전자 <jh1302.park@samsung.com>
Fri, 4 May 2018 01:15:27 +0000 (10:15 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Fri, 4 May 2018 01:15:27 +0000 (10:15 +0900)
This commit simplifies tensor tests with recently introduce constructors
based on brace initialization.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
libs/core/src/nncc/core/ADT/tensor/Index.test.cpp
libs/core/src/nncc/core/ADT/tensor/IndexRange.test.cpp
libs/core/src/nncc/core/ADT/tensor/Shape.test.cpp

index 8429a2b..d50def0 100644 (file)
@@ -47,17 +47,7 @@ TEST(ADT_TENSOR_INDEX, at)
 
 TEST(ADT_TENSOR_INDEX, copy)
 {
-  nncc::core::ADT::tensor::Index original;
-
-  original.resize(4);
-
-  uint32_t indices[4] = {3, 5, 2, 7};
-
-  for (uint32_t axis = 0; axis < 4; ++axis)
-  {
-    original.at(axis) = indices[axis];
-  }
-
+  const nncc::core::ADT::tensor::Index original{3, 5, 2, 7};
   const nncc::core::ADT::tensor::Index copied{original};
 
   ASSERT_EQ(original.rank(), copied.rank());
index f15efe7..5537af4 100644 (file)
@@ -7,56 +7,31 @@
 
 TEST(ADT_TENSOR_INDEX_RANGE, member_positive)
 {
-  nncc::core::ADT::tensor::Shape shape;
-
-  shape.resize(1);
-  shape.dim(0) = 3;
-
-  nncc::core::ADT::tensor::Index index;
-
-  index.resize(1);
-  index.at(0) = 2;
+  const nncc::core::ADT::tensor::Shape shape{3};
+  const nncc::core::ADT::tensor::Index index{2};
 
   ASSERT_TRUE(nncc::core::ADT::tensor::IndexRange{shape}.member(index));
 }
 
 TEST(ADT_TENSOR_INDEX_RANGE, member_negative_unmatched_rank)
 {
-  nncc::core::ADT::tensor::Shape shape;
-
-  shape.resize(1);
-  shape.dim(0) = 3;
-
-  nncc::core::ADT::tensor::Index index;
-
-  index.resize(2);
-  index.at(0) = 2;
-  index.at(1) = 3;
+  const nncc::core::ADT::tensor::Shape shape{3};
+  const nncc::core::ADT::tensor::Index index{2, 3};
 
   ASSERT_FALSE(nncc::core::ADT::tensor::IndexRange{shape}.member(index));
 }
 
 TEST(ADT_TENSOR_INDEX_RANGE, member_negative_overflowed_dim)
 {
-  nncc::core::ADT::tensor::Shape shape;
-
-  shape.resize(1);
-  shape.dim(0) = 3;
-
-  nncc::core::ADT::tensor::Index index;
-
-  index.resize(1);
-  index.at(0) = 4;
+  const nncc::core::ADT::tensor::Shape shape{3};
+  const nncc::core::ADT::tensor::Index index{4};
 
   ASSERT_FALSE(nncc::core::ADT::tensor::IndexRange{shape}.member(index));
 }
 
 TEST(ADT_TENSOR_INDEX_RANGE, iterate_empty_range)
 {
-  nncc::core::ADT::tensor::Shape shape;
-
-  shape.resize(1);
-  shape.dim(0) = 0;
+  const nncc::core::ADT::tensor::Shape shape{0};
 
   uint32_t count = 0;
 
@@ -70,11 +45,7 @@ TEST(ADT_TENSOR_INDEX_RANGE, iterate_empty_range)
 
 TEST(ADT_TENSOR_INDEX_RANGE, iterate_full_range)
 {
-  nncc::core::ADT::tensor::Shape shape;
-
-  shape.resize(2);
-  shape.dim(0) = 3;
-  shape.dim(1) = 4;
+  const nncc::core::ADT::tensor::Shape shape{3, 4};
 
   std::array<uint32_t, 3 * 4> count;
 
index 610c49b..3fd5590 100644 (file)
@@ -47,17 +47,7 @@ TEST(ADT_TENSOR_SHAPE, dim)
 
 TEST(ADT_TENSOR_SHAPE, copy)
 {
-  nncc::core::ADT::tensor::Shape original;
-
-  original.resize(4);
-
-  uint32_t dims[4] = {3, 5, 2, 7};
-
-  for (uint32_t axis = 0; axis < 4; ++axis)
-  {
-    original.dim(axis) = dims[axis];
-  }
-
+  const nncc::core::ADT::tensor::Shape original{3, 5, 2, 7};
   const nncc::core::ADT::tensor::Shape copied{original};
 
   ASSERT_EQ(original.rank(), copied.rank());
@@ -70,43 +60,24 @@ TEST(ADT_TENSOR_SHAPE, copy)
 
 TEST(ADT_TENSOR_SHAPE, eq_negative_on_unmatched_rank)
 {
-  nncc::core::ADT::tensor::Shape left;
-  nncc::core::ADT::tensor::Shape right;
-
-  left.resize(3);
-  right.resize(4);
+  const nncc::core::ADT::tensor::Shape left{1, 1, 1};
+  const nncc::core::ADT::tensor::Shape right{1, 1, 1, 1};
 
   ASSERT_FALSE(left == right);
 }
 
 TEST(ADT_TENSOR_SHAPE, eq_negative_on_unmatched_dim)
 {
-  nncc::core::ADT::tensor::Shape left;
-  nncc::core::ADT::tensor::Shape right;
-
-  left.resize(2);
-  left.dim(0) = 2;
-  left.dim(1) = 3;
-
-  right.resize(2);
-  right.dim(0) = 2;
-  right.dim(1) = 4;
+  const nncc::core::ADT::tensor::Shape left{2, 3};
+  const nncc::core::ADT::tensor::Shape right{2, 4};
 
   ASSERT_FALSE(left == right);
 }
 
 TEST(ADT_TENSOR_SHAPE, eq_positive)
 {
-  nncc::core::ADT::tensor::Shape left;
-  nncc::core::ADT::tensor::Shape right;
-
-  left.resize(2);
-  left.dim(0) = 2;
-  left.dim(1) = 3;
-
-  right.resize(2);
-  right.dim(0) = 2;
-  right.dim(1) = 3;
+  const nncc::core::ADT::tensor::Shape left{2, 3};
+  const nncc::core::ADT::tensor::Shape right{2, 3};
 
   ASSERT_TRUE(left == right);
 }