1# Copyright 2020 Huawei Technologies Co., Ltd 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# ============================================================================ 15import mindspore.context as context 16from mindspore import Tensor, ms_function 17from mindspore.common import dtype as mstype 18 19 20@ms_function 21def t1_while(x, y): 22 y = y + 4 23 while x < y: 24 x = x + 1 25 x = x + 3 26 return x 27 28 29def test_net(): 30 context.set_context(mode=context.GRAPH_MODE, device_target="Ascend") 31 c1 = Tensor([2], mstype.int32) 32 c2 = Tensor([14], mstype.int32) 33 expect = Tensor([21], mstype.int32) 34 ret = t1_while(c1, c2) 35 assert ret == expect 36 37 38if __name__ == "__main__": 39 test_net() 40