PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/python/li_std_vector_extra_runme.py

#
Python | 176 lines | 116 code | 57 blank | 3 comment | 36 complexity | 65cd1e8a597272353274a2635c25219c MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. from li_std_vector_extra import *
  2. iv = IntVector(4)
  3. for i in range(0,4):
  4. iv[i] = i
  5. x = average(iv)
  6. y = average([1,2,3,4])
  7. a = half([10,10.5,11,11.5])
  8. dv = DoubleVector(10)
  9. for i in range(0,10):
  10. dv[i] = i/2.0
  11. halve_in_place(dv)
  12. bv = BoolVector(4)
  13. bv[0]= 1
  14. bv[1]= 0
  15. bv[2]= 4
  16. bv[3]= 0
  17. if bv[0] != bv[2]:
  18. raise RuntimeError,"bad std::vector<bool> mapping"
  19. b = B(5)
  20. va = VecA([b,None,b,b])
  21. if va[0].f(1) != 6:
  22. raise RuntimeError,"bad std::vector<A*> mapping"
  23. if vecAptr(va) != 6:
  24. raise RuntimeError,"bad std::vector<A*> mapping"
  25. b.val = 7
  26. if va[3].f(1) != 8:
  27. raise RuntimeError,"bad std::vector<A*> mapping"
  28. ip = PtrInt()
  29. ap = new_ArrInt(10)
  30. ArrInt_setitem(ip,0,123)
  31. ArrInt_setitem(ap,2,123)
  32. vi = IntPtrVector((ip,ap,None))
  33. if ArrInt_getitem(vi[0],0) != ArrInt_getitem(vi[1],2):
  34. raise RuntimeError,"bad std::vector<int*> mapping"
  35. delete_ArrInt(ap)
  36. a = halfs([10,8,4,3])
  37. v = IntVector()
  38. v[0:2] = [1,2]
  39. if v[0] != 1 or v[1] != 2:
  40. raise RuntimeError,"bad setslice"
  41. if v[0:-1][0] != 1:
  42. raise RuntimeError,"bad getslice"
  43. if v[0:-2].size() != 0:
  44. raise RuntimeError,"bad getslice"
  45. v[0:1] = [2]
  46. if v[0] != 2:
  47. raise RuntimeError,"bad setslice"
  48. v[1:] = [3]
  49. if v[1] != 3:
  50. raise RuntimeError,"bad setslice"
  51. v[2:] = [3]
  52. if v[2] != 3:
  53. raise RuntimeError,"bad setslice"
  54. if v[0:][0] != v[0]:
  55. raise RuntimeError,"bad getslice"
  56. del v[:]
  57. if v.size() != 0:
  58. raise RuntimeError,"bad getslice"
  59. del v[:]
  60. if v.size() != 0:
  61. raise RuntimeError,"bad getslice"
  62. v = vecStr(["hello ", "world"])
  63. if v[0] != 'hello world':
  64. raise RuntimeError,"bad std::string+std::vector"
  65. pv = pyvector([1, "hello", (1,2)])
  66. if pv[1] != "hello":
  67. raise RuntimeError
  68. iv = IntVector(5)
  69. for i in range(0,5):
  70. iv[i] = i
  71. iv[1:3] = []
  72. if iv[1] != 3:
  73. raise RuntimeError
  74. # Overloading checks
  75. if overloaded1(iv) != "vector<int>":
  76. raise RuntimeError
  77. if overloaded1(dv) != "vector<double>":
  78. raise RuntimeError
  79. if overloaded2(iv) != "vector<int>":
  80. raise RuntimeError
  81. if overloaded2(dv) != "vector<double>":
  82. raise RuntimeError
  83. if overloaded3(iv) != "vector<int> *":
  84. raise RuntimeError
  85. if overloaded3(None) != "vector<int> *":
  86. raise RuntimeError
  87. if overloaded3(100) != "int":
  88. raise RuntimeError
  89. # vector pointer checks
  90. ip = makeIntPtr(11)
  91. dp = makeDoublePtr(33.3)
  92. error = 0
  93. try:
  94. vi = IntPtrVector((ip, dp)) # check vector<int *> does not accept double * element
  95. error = 1
  96. except:
  97. pass
  98. if error:
  99. raise RuntimeError
  100. vi = IntPtrVector((ip, makeIntPtr(22)))
  101. if extractInt(vi[0]) != 11:
  102. raise RuntimeError
  103. if extractInt(vi[1]) != 22:
  104. raise RuntimeError
  105. # vector const pointer checks
  106. csp = makeConstShortPtr(111)
  107. error = 0
  108. try:
  109. vcs = ConstShortPtrVector((csp, dp)) # check vector<const unsigned short *> does not accept double * element
  110. error = 1
  111. except:
  112. pass
  113. if error:
  114. raise RuntimeError
  115. vcs = ConstShortPtrVector((csp, makeConstShortPtr(222)))
  116. if extractConstShort(vcs[0]) != 111:
  117. raise RuntimeError
  118. if extractConstShort(vcs[1]) != 222:
  119. raise RuntimeError