1
0

89_operator.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import operator as op
  2. assert op.le(1, 2) == True
  3. assert op.lt(1, 2) == True
  4. assert op.ge(1, 2) == False
  5. assert op.gt(1, 2) == False
  6. assert op.eq(1, 2) == False
  7. assert op.ne(1, 2) == True
  8. assert op.and_(0b01, 0b11) == 0b01
  9. assert op.or_(0b01, 0b11) == 0b11
  10. assert op.xor(0b01, 0b11) == 0b10
  11. assert op.invert(0b01) == -0b10
  12. assert op.lshift(0b01, 1) == 0b10
  13. assert op.rshift(0b10, 1) == 0b01
  14. assert op.is_('a', 'a') == True
  15. assert op.is_not('a', 1) == True
  16. assert op.not_(True) == False
  17. assert op.neg(1) == -1
  18. assert op.truth(1) == True
  19. assert op.contains([1, 2], 1) == True
  20. assert op.add(1, 2) == 3
  21. assert op.sub(1, 2) == -1
  22. assert op.mul(1, 2) == 2
  23. assert op.truediv(1, 2) == 0.5
  24. assert op.floordiv(1, 2) == 0
  25. assert op.mod(1, 2) == 1
  26. assert op.pow(2, 3) == 8
  27. from linalg import mat3x3
  28. assert op.matmul(mat3x3.identity(), mat3x3.identity()) == mat3x3.identity()
  29. a = [1, 2]
  30. assert op.getitem(a, 0) == 1
  31. op.setitem(a, 0, 3)
  32. assert a == [3, 2]
  33. op.delitem(a, 0)
  34. assert a == [2]
  35. a = 'abc'
  36. assert op.iadd(a, 'def') == 'abcdef'
  37. assert op.isub(8, 3) == 5
  38. assert op.imul(a, 2) == 'abcabc'
  39. assert op.itruediv(8, 2) == 4.0
  40. assert op.ifloordiv(8, 3) == 2
  41. assert op.imod(8, 3) == 2
  42. assert op.iand(0b01, 0b11) == 0b01
  43. assert op.ior(0b01, 0b11) == 0b11
  44. assert op.ixor(0b01, 0b11) == 0b10
  45. assert op.ilshift(0b01, 1) == 0b10
  46. assert op.irshift(0b10, 1) == 0b01