t505.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. ## tests for operator module
  2. import operator
  3. print operator.lt(1, 2)
  4. print operator.lt(2, 1)
  5. print operator.le(1, 2)
  6. print operator.le(2, 1)
  7. print operator.le(2, 2)
  8. print operator.eq(2, 2)
  9. print operator.eq(3, 2)
  10. print operator.ne(2, 3)
  11. print operator.ne(2, 2)
  12. print operator.ge(2, 1)
  13. print operator.ge(1, 2)
  14. print operator.ge(2, 2)
  15. print operator.gt(2, 1)
  16. print operator.gt(1, 2)
  17. # Not implemented
  18. # print operator.not_("hello")
  19. print operator.truth(True)
  20. print operator.truth(False)
  21. print operator.truth(1)
  22. print operator.truth(0)
  23. print operator.is_("hello", "hello")
  24. print operator.is_("hello", "goodbye")
  25. print operator.is_(1, 1)
  26. print operator.is_(2, 1)
  27. print operator.is_not("hello", "goodbye")
  28. print operator.is_not("hello", "hello")
  29. print operator.is_not(1, 2)
  30. print operator.is_not(1, 1)
  31. print operator.abs(5)
  32. print operator.abs(-5)
  33. print operator.abs(1.1)
  34. print operator.abs(-1.1)
  35. print operator.add(1, 2)
  36. print operator.add(-4, 2)
  37. print operator.add("he", "llo")
  38. print operator.and_(2, 3)
  39. print operator.and_(5, 3)
  40. print operator.and_(-4, 3)
  41. print operator.div(10, 5)
  42. print operator.div(5, 2)
  43. print operator.div(2.2, 2)
  44. print operator.div(-5.0, 2)
  45. print operator.floordiv(10, 5)
  46. print operator.floordiv(5, 2)
  47. print operator.floordiv(2.2, 2)
  48. print operator.floordiv(-5.0, 2)
  49. # Not implemented
  50. # print operator.index("hello")
  51. # Not implemented
  52. # print operator.invert("hello")
  53. print operator.lshift(5, 2)
  54. print operator.lshift(-5, 3)
  55. print operator.mod(10, 5)
  56. print operator.mod(10, 3)
  57. print operator.mod(15, 4)
  58. print operator.mul(2, 1)
  59. print operator.mul(-2, 1)
  60. print operator.mul(2, -1)
  61. print operator.mul(10, 20)
  62. print operator.neg(-5)
  63. print operator.neg(5)
  64. print operator.neg(True)
  65. print operator.neg(False)
  66. print operator.or_(1, 2)
  67. print operator.or_(4, 3)
  68. print operator.or_(5, 2)
  69. print operator.pos(5)
  70. print operator.pos(-5)
  71. print operator.pos(True)
  72. print operator.pos(False)
  73. print operator.pow(2, 2)
  74. print operator.pow(5, 3)
  75. print operator.rshift(5, 2)
  76. print operator.rshift(-5, 3)
  77. print operator.sub(4, 2)
  78. print operator.sub(2, 4)
  79. print operator.sub(-4, 2)
  80. print operator.xor(4, 2)
  81. print operator.xor(8, 5)
  82. print operator.concat("he", "llo")
  83. print operator.concat([1,2,3,4], [5,6,7])
  84. print operator.concat((1,2), (3,4))
  85. l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 9]
  86. s = "hello world"
  87. t = ("a", "b", "c")
  88. d = {1:1, 2:2, 3:3, 4:4, 5:5}
  89. print operator.contains(l, 2)
  90. print operator.contains(l, 30)
  91. print operator.contains(s, "ll")
  92. print operator.contains(s, "z")
  93. print operator.contains(t, "a")
  94. print operator.contains(t, 2)
  95. print operator.contains(d, 3)
  96. print operator.contains(d, 0)
  97. print operator.countOf(l, 9)
  98. print operator.countOf(l, 30)
  99. print operator.countOf(s, "l")
  100. print operator.countOf(t, "a")
  101. operator.delitem(l, 9)
  102. print l
  103. operator.delitem(l, 0)
  104. print l
  105. l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 9]
  106. s = "hello world"
  107. t = ("a", "b", "c")
  108. d = {1:1, 2:2, 3:3, 4:4, 5:5}
  109. print operator.getitem(l, 2)
  110. print operator.getitem(s, 0)
  111. print operator.getitem(t, 1)
  112. print operator.getitem(d, 4)
  113. print operator.indexOf(l, 5)
  114. print operator.indexOf(s, "l")
  115. print operator.indexOf(t, "a")
  116. operator.setitem(l, 0, 10)
  117. print l
  118. operator.setitem(d, 1, 10)
  119. print d
  120. operator.setitem(d, 6, 6)
  121. print d