diff --git a/ngraph/test/visitors/op/ceiling.cpp b/ngraph/test/visitors/op/ceiling.cpp index 34ed3b653b3..11e71e1e9c6 100644 --- a/ngraph/test/visitors/op/ceiling.cpp +++ b/ngraph/test/visitors/op/ceiling.cpp @@ -2,25 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "gtest/gtest.h" +#include "unary_ops.hpp" +using Type = ::testing::Types>; -#include "ngraph/ngraph.hpp" -#include "ngraph/op/util/attr_types.hpp" -#include "ngraph/opsets/opset1.hpp" -#include "util/visitor.hpp" - -using namespace std; -using namespace ngraph; -using ngraph::test::NodeBuilder; - -TEST(attributes, ceiling_op) -{ - NodeBuilder::get_ops().register_factory(); - const auto A = make_shared(element::f32, Shape{5, 2}); - - const auto ceiling = make_shared(A); - NodeBuilder builder(ceiling); - - const auto expected_attr_count = 0; - EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); -} +INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute, + UnaryOperatorVisitor, + Type, + UnaryOperatorTypeName); \ No newline at end of file diff --git a/ngraph/test/visitors/op/floor.cpp b/ngraph/test/visitors/op/floor.cpp index 57cd6011c67..98731229010 100644 --- a/ngraph/test/visitors/op/floor.cpp +++ b/ngraph/test/visitors/op/floor.cpp @@ -2,25 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "gtest/gtest.h" +#include "unary_ops.hpp" -#include "ngraph/ngraph.hpp" -#include "ngraph/op/util/attr_types.hpp" -#include "ngraph/opsets/opset1.hpp" -#include "util/visitor.hpp" +using Types = ::testing::Types, + UnaryOperatorType>; -using namespace std; -using namespace ngraph; -using ngraph::test::NodeBuilder; - -TEST(attributes, floor_op) -{ - NodeBuilder::get_ops().register_factory(); - const auto A = make_shared(element::f32, Shape{5, 2}); - - const auto floor = make_shared(A); - NodeBuilder builder(floor); - - const auto expected_attr_count = 0; - EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); -} +INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute, + UnaryOperatorVisitor, + Types, + UnaryOperatorTypeName); \ No newline at end of file diff --git a/ngraph/test/visitors/op/log.cpp b/ngraph/test/visitors/op/log.cpp index 02d6293871c..5acb4971ba8 100644 --- a/ngraph/test/visitors/op/log.cpp +++ b/ngraph/test/visitors/op/log.cpp @@ -1,29 +1,11 @@ // Copyright (C) 2021 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // +#include "unary_ops.hpp" +using Types = ::testing::Types, + UnaryOperatorType>; -#include "gtest/gtest.h" - -#include "ngraph/ngraph.hpp" -#include "ngraph/op/util/attr_types.hpp" -#include "ngraph/opsets/opset1.hpp" - -#include "util/visitor.hpp" - -using namespace std; -using namespace ngraph; -using ngraph::test::NodeBuilder; - -TEST(attributes, log_op) -{ - using namespace opset1; - - NodeBuilder::get_ops().register_factory(); - const auto data_input = make_shared(element::f32, Shape{1, 2, 3}); - const auto op = make_shared(data_input); - - NodeBuilder builder(op); - const auto expected_attr_count = 0; - - EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); -} \ No newline at end of file +INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute, + UnaryOperatorVisitor, + Types, + UnaryOperatorTypeName); \ No newline at end of file diff --git a/ngraph/test/visitors/op/result.cpp b/ngraph/test/visitors/op/result.cpp index 528d1ee50cf..df01ad5f913 100644 --- a/ngraph/test/visitors/op/result.cpp +++ b/ngraph/test/visitors/op/result.cpp @@ -2,24 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "ngraph/opsets/opset1.hpp" -#include "util/visitor.hpp" +#include "unary_ops.hpp" -using namespace std; -using namespace ngraph; -using ngraph::test::NodeBuilder; -using ngraph::test::ValueMap; +using Types = ::testing::Types, + UnaryOperatorType>; -TEST(attributes, result) -{ - NodeBuilder::get_ops().register_factory(); - const auto data_node = make_shared(element::f32, Shape{1}); - const auto result = make_shared(data_node); - - NodeBuilder builder(result); - const auto expected_attr_count = 0; - - EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); -} +INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute, + UnaryOperatorVisitor, + Types, + UnaryOperatorTypeName); \ No newline at end of file diff --git a/ngraph/test/visitors/op/sqrt.cpp b/ngraph/test/visitors/op/sqrt.cpp index 23bc0035390..5e26c542348 100644 --- a/ngraph/test/visitors/op/sqrt.cpp +++ b/ngraph/test/visitors/op/sqrt.cpp @@ -2,28 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "gtest/gtest.h" +#include "unary_ops.hpp" +using Types = ::testing::Types, + UnaryOperatorType>; -#include "ngraph/ngraph.hpp" -#include "ngraph/op/util/attr_types.hpp" -#include "ngraph/opsets/opset1.hpp" - -#include "util/visitor.hpp" - -using namespace std; -using namespace ngraph; -using ngraph::test::NodeBuilder; - -TEST(attributes, sqrt_op) -{ - using namespace opset1; - - NodeBuilder::get_ops().register_factory(); - const auto data_input = make_shared(element::f32, Shape{1, 2, 3}); - const auto op = make_shared(data_input); - - NodeBuilder builder(op); - const auto expected_attr_count = 0; - - EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); -} +INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute, + UnaryOperatorVisitor, + Types, + UnaryOperatorTypeName); \ No newline at end of file diff --git a/ngraph/test/visitors/op/squeeze.cpp b/ngraph/test/visitors/op/squeeze.cpp index feed9fcdf9b..a8b0c2c488c 100644 --- a/ngraph/test/visitors/op/squeeze.cpp +++ b/ngraph/test/visitors/op/squeeze.cpp @@ -2,27 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "gtest/gtest.h" +#include "unary_ops.hpp" +using Types = ::testing::Types, + UnaryOperatorType>; -#include "ngraph/ngraph.hpp" -#include "ngraph/op/util/attr_types.hpp" -#include "ngraph/opsets/opset1.hpp" - -#include "util/visitor.hpp" - -using namespace std; -using namespace ngraph; -using ngraph::test::NodeBuilder; -using ngraph::test::ValueMap; - -TEST(attributes, squeeze_op) -{ - NodeBuilder::get_ops().register_factory(); - const auto data_node = make_shared(element::f32, Shape{1}); - const auto squeeze = make_shared(data_node); - - NodeBuilder builder(squeeze); - const auto expected_attr_count = 0; - - EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); -} +INSTANTIATE_TYPED_TEST_CASE_P(visitor_without_atrribute, + UnaryOperatorVisitor, + Types, + UnaryOperatorTypeName); \ No newline at end of file diff --git a/ngraph/test/visitors/op/unary_ops.hpp b/ngraph/test/visitors/op/unary_ops.hpp new file mode 100644 index 00000000000..16764c42a7c --- /dev/null +++ b/ngraph/test/visitors/op/unary_ops.hpp @@ -0,0 +1,59 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include "gtest/gtest.h" +#include "ngraph/ngraph.hpp" + +#include "ngraph/op/util/attr_types.hpp" +#include "util/visitor.hpp" + +using namespace ngraph; +using ngraph::test::NodeBuilder; +template +class UnaryOperatorType +{ +public: + using op_type = T; + static constexpr element::Type_t element_type = ELEMENT_TYPE; +}; +template +class UnaryOperatorVisitor : public testing::Test +{ +}; + +class UnaryOperatorTypeName +{ +public: + template + static std::string GetName(int) + { + using OP_Type = typename T::op_type; + constexpr element::Type precision(T::element_type); + const ngraph::Node::type_info_t typeinfo = OP_Type::get_type_info_static(); + std::string op_name{typeinfo.name}; + op_name.append("_"); + return (op_name.append(precision.get_type_name())); + } +}; + +TYPED_TEST_CASE_P(UnaryOperatorVisitor); + +TYPED_TEST_P(UnaryOperatorVisitor, No_Attribute_4D) +{ + using OP_Type = typename TypeParam::op_type; + const element::Type_t element_type = TypeParam::element_type; + + NodeBuilder::get_ops().register_factory(); + const auto A = std::make_shared(element_type, PartialShape{2, 2, 2, 2}); + + const auto op_func = std::make_shared(A); + NodeBuilder builder(op_func); + const auto expected_attr_count = 0; + EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); +} + +REGISTER_TYPED_TEST_CASE_P(UnaryOperatorVisitor, No_Attribute_4D);