[core.ADT] Introduce operator== over feature shape (#442)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 2 Jul 2018 23:45:22 +0000 (08:45 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 2 Jul 2018 23:45:22 +0000 (08:45 +0900)
This commit introduces equality operator which tests whether two feature
shapes are identical.

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

index 38b7d22..ec204e1 100644 (file)
@@ -40,6 +40,11 @@ inline uint64_t num_elements(const Shape &shape)
   return shape.depth() * shape.height() * shape.width();
 }
 
+inline bool operator==(const Shape &l, const Shape &r)
+{
+  return (l.depth() == r.depth()) && (l.height() == r.height()) && (l.width() == r.width());
+}
+
 } // namespace feature
 } // namespace ADT
 } // namespace core
index 8c4c080..62a0668 100644 (file)
@@ -26,3 +26,15 @@ TEST(ADT_FEATURE_SHAPE, num_elements)
 
   ASSERT_EQ(num_elements(Shape{C, H, W}), C * H * W);
 }
+
+TEST(ADT_FEATURE_SHAPE, operator_eq)
+{
+  using nncc::core::ADT::feature::Shape;
+
+  // NOTE We use ASSERT_TRUE/ASSERT_FALSE instead of ASSERT_EQ/ASSERT_NE as it is impossible to
+  //      introduce negative tests with ASSERT_NE (it uses operator!= instead of operator==).
+  ASSERT_TRUE(Shape(1, 1, 1) == Shape(1, 1, 1));
+  ASSERT_FALSE(Shape(1, 1, 1) == Shape(2, 1, 1));
+  ASSERT_FALSE(Shape(1, 1, 1) == Shape(1, 2, 1));
+  ASSERT_FALSE(Shape(1, 1, 1) == Shape(1, 1, 2));
+}