You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_not_in.py 1.9 kB

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