/** * Copyright 2020 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include "common/common_test.h" #include "ir/value.h" #include "abstract/abstract_value.h" #include "utils/log_adapter.h" namespace mindspore { using AbstractScalar = abstract::AbstractScalar; using AbstractTuple = abstract::AbstractTuple; using AbstractBasePtrList = abstract::AbstractBasePtrList; class TestValue : public UT::Common { public: TestValue() {} }; TEST_F(TestValue, test_int64) { auto i64a = std::make_shared(2); ASSERT_TRUE(i64a != nullptr); } TEST_F(TestValue, testToAbstract) { ValuePtr boolv = std::make_shared(true); AbstractBasePtr boola = std::make_shared(true); AbstractBasePtr ret = boolv->ToAbstract(); ASSERT_TRUE(ret); ASSERT_EQ(*(ret), *(boola)); ASSERT_FALSE(*(ret) == *(std::make_shared(false))); ASSERT_FALSE(*(ret) == *(std::make_shared(static_cast(2)))); ValuePtr i64v = std::make_shared(2); AbstractBasePtr i64a = std::make_shared(static_cast(2)); ret = i64v->ToAbstract(); ASSERT_TRUE(ret); ASSERT_EQ(*(ret), *(i64a)); ValuePtr f32v = std::make_shared(1.0); AbstractBasePtr f32a = std::make_shared(1.0f); ret = f32v->ToAbstract(); ASSERT_TRUE(ret); ASSERT_EQ(*(ret), *(f32a)); ValuePtr sv = std::make_shared("_"); AbstractBasePtr sa = std::make_shared(std::string("_")); ret = sv->ToAbstract(); ASSERT_TRUE(ret); ASSERT_EQ(*(ret), *(sa)); ValuePtr vv = std::make_shared(); AbstractBasePtr va = std::make_shared(); ret = vv->ToAbstract(); ASSERT_TRUE(ret); ASSERT_EQ(*(ret), *(va)); ValuePtr tv = std::make_shared(std::vector({boolv, i64v, f32v, sv, vv})); AbstractBasePtr ta = std::make_shared(AbstractBasePtrList({boola, i64a, f32a, sa, va})); ret = tv->ToAbstract(); ASSERT_TRUE(ret); ASSERT_EQ(*(ret), *(ta)); ValuePtr rv = std::make_shared("net.weight"); abstract::AbstractRefKeyPtr ra = std::make_shared(); ra->set_value(rv); ret = rv->ToAbstract(); ASSERT_TRUE(ret); ASSERT_EQ(*(ret), *(ra)); } TEST_F(TestValue, GetValue) { ValuePtr fv = MakeValue("test"); const char* fv_c = GetValue(fv); MS_LOG(INFO) << "" << fv_c; MS_LOG(INFO) << "" << GetValue(fv); ASSERT_TRUE(fv_c != nullptr); } } // namespace mindspore