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# ============================================================================ 15""" test not in""" 16import numpy as np 17 18import mindspore.nn as nn 19from mindspore import context, Tensor 20 21context.set_context(mode=context.GRAPH_MODE) 22 23 24def test_number_not_in_tuple(): 25 class Net(nn.Cell): 26 def __init__(self): 27 super(Net, self).__init__() 28 self.tuple_ = (2, 3, 4) 29 self.list_ = [2, 3, 4] 30 self.dict_ = {"a": Tensor(np.ones([1, 2, 3], np.int32)), 31 "b": Tensor(np.ones([1, 2, 3], np.int32)), 32 "c": Tensor(np.ones([1, 2, 3], np.int32))} 33 self.number_in = 3 34 self.number_not_in = 5 35 self.str_in = "a" 36 self.str_not_in = "e" 37 38 def construct(self): 39 ret = 0 40 if self.number_in not in self.tuple_: 41 ret += 1 42 if self.number_not_in not in self.tuple_: 43 ret += 2 44 if self.number_in not in self.list_: 45 ret += 3 46 if self.number_not_in not in self.list_: 47 ret += 4 48 if self.str_in not in self.dict_: 49 ret += 5 50 if self.str_not_in not in self.dict_: 51 ret += 6 52 return ret 53 54 net = Net() 55 output = net() 56 assert output == 12 57