From ca4063e0857220c4d78d55b47bfdfe344d8432f7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Senior=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Fri, 4 May 2018 10:15:27 +0900 Subject: [PATCH] [nncc.core] Simplify tensor tests with constructor (#194) This commit simplifies tensor tests with recently introduce constructors based on brace initialization. Signed-off-by: Jonghyun Park --- libs/core/src/nncc/core/ADT/tensor/Index.test.cpp | 12 +----- .../src/nncc/core/ADT/tensor/IndexRange.test.cpp | 45 ++++------------------ libs/core/src/nncc/core/ADT/tensor/Shape.test.cpp | 43 ++++----------------- 3 files changed, 16 insertions(+), 84 deletions(-) diff --git a/libs/core/src/nncc/core/ADT/tensor/Index.test.cpp b/libs/core/src/nncc/core/ADT/tensor/Index.test.cpp index 8429a2b..d50def0 100644 --- a/libs/core/src/nncc/core/ADT/tensor/Index.test.cpp +++ b/libs/core/src/nncc/core/ADT/tensor/Index.test.cpp @@ -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()); diff --git a/libs/core/src/nncc/core/ADT/tensor/IndexRange.test.cpp b/libs/core/src/nncc/core/ADT/tensor/IndexRange.test.cpp index f15efe7..5537af4 100644 --- a/libs/core/src/nncc/core/ADT/tensor/IndexRange.test.cpp +++ b/libs/core/src/nncc/core/ADT/tensor/IndexRange.test.cpp @@ -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 count; diff --git a/libs/core/src/nncc/core/ADT/tensor/Shape.test.cpp b/libs/core/src/nncc/core/ADT/tensor/Shape.test.cpp index 610c49b..3fd5590 100644 --- a/libs/core/src/nncc/core/ADT/tensor/Shape.test.cpp +++ b/libs/core/src/nncc/core/ADT/tensor/Shape.test.cpp @@ -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); } -- 2.7.4