1 /** 2 * Copyright 2020 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #include <iostream> 17 #include <memory> 18 19 #include "common/common_test.h" 20 21 #include "abstract/dshape.h" 22 #include "utils/log_adapter.h" 23 24 namespace mindspore { 25 namespace abstract { 26 class TestDShape : public UT::Common { 27 public: 28 Shape shp_1; 29 Shape shp_2; 30 Shape shp_3; 31 Shape shp_4; 32 Shape shp_5; 33 34 NoShape shp_noshp_1; 35 NoShape shp_noshp_2; 36 37 TupleShape shp_tuple_1; 38 TupleShape shp_tuple_2; 39 TupleShape shp_tuple_3; 40 TupleShape shp_tuple_4; 41 TestDShape() 42 : shp_1({1, 1}), 43 shp_2({1, 1}), 44 shp_3({1, 2}), 45 shp_4({1}), 46 shp_5({-1, 2}, {1, 2}, {3, 3}), 47 48 shp_noshp_1(), 49 shp_noshp_2(), 50 51 shp_tuple_1({NoShape().Clone(), Shape({1, 1}).Clone()}), 52 shp_tuple_2({NoShape().Clone(), Shape({1, 1, 1}).Clone()}), 53 shp_tuple_3({NoShape().Clone(), Shape({1, 2, 1}).Clone()}), 54 shp_tuple_4({NoShape().Clone()}) {} 55 }; 56 57 TEST_F(TestDShape, EqualTest) { 58 ASSERT_TRUE(shp_1 == shp_2); 59 ASSERT_FALSE(shp_1 == shp_3); 60 ASSERT_FALSE(shp_1 == shp_noshp_1); 61 62 ASSERT_TRUE(shp_noshp_1 == shp_noshp_2); 63 64 ASSERT_FALSE(shp_tuple_1 == shp_1); 65 ASSERT_FALSE(shp_tuple_1 == shp_tuple_2); 66 ASSERT_FALSE(shp_tuple_1 == shp_tuple_4); 67 } 68 TEST_F(TestDShape, ToString) { 69 ASSERT_EQ(shp_3.ToString(), "(1, 2)"); 70 ASSERT_EQ(shp_noshp_1.ToString(), "NoShape"); 71 ASSERT_EQ(shp_tuple_2.ToString(), "TupleShape(NoShape, (1, 1, 1))"); 72 ASSERT_EQ(shp_5.ToString(), "{shape:(-1, 2)|min shape:(1, 2)|max shape:(3, 3)}"); 73 } 74 75 TEST_F(TestDShape, Clone) { 76 ASSERT_EQ(*shp_3.Clone(), shp_3); 77 ASSERT_EQ(*shp_noshp_1.Clone(), shp_noshp_1); 78 ASSERT_EQ(*shp_tuple_2.Clone(), shp_tuple_2); 79 } 80 81 } // namespace abstract 82 } // namespace mindspore 83