• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "common/common_test.h"
17 #include "pipeline/jit/static_analysis/static_analysis.h"
18 #include "utils/symbolic.h"
19 
20 using std::cout;
21 using std::endl;
22 using std::string;
23 
24 namespace mindspore {
25 class TestSymbolic : public UT::Common {
26  public:
TestSymbolic()27   TestSymbolic() {}
28 };
29 
TEST_F(TestSymbolic,test_env)30 TEST_F(TestSymbolic, test_env) {
31   auto sk1 = std::make_shared<SymbolicKeyInstance>(NewValueNode(static_cast<int64_t>(1)), abstract::FromValue(1234));
32   auto sk1b = std::make_shared<SymbolicKeyInstance>(NewValueNode(static_cast<int64_t>(1)), abstract::FromValue(1234));
33 
34   ASSERT_EQ(*sk1, *sk1b);
35 
36   auto sk2 = std::make_shared<SymbolicKeyInstance>(NewValueNode(static_cast<int64_t>(2)), abstract::FromValue(1234));
37 
38   EnvInstance e = newenv->Set(sk1, 100);
39   ASSERT_FALSE(e == *newenv);
40 
41   ASSERT_EQ(newenv->Len(), 0);
42   ASSERT_EQ(e.Len(), 1);
43   ASSERT_EQ(e.Get(sk1, 0), 100);
44   ASSERT_EQ(e.Get(sk2, 0), 0);
45 
46   EnvInstance e2 = e.Set(sk1b, 200);
47   ASSERT_EQ(e2.Len(), 1);
48   ASSERT_EQ(e2.Get(sk1, 0), 200);
49   ASSERT_EQ(e2.Get(sk2, 0), 0);
50 
51   EnvInstance e3 = e2.Set(sk2, 300);
52   ASSERT_EQ(e3.Len(), 2);
53   ASSERT_EQ(e3.Get(sk1, 0), 200);
54   ASSERT_EQ(e3.Get(sk2, 0), 300);
55 }
56 
57 }  // namespace mindspore
58