PageRenderTime 16ms CodeModel.GetById 2ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Python | 176 lines | 116 code | 57 blank | 3 comment | 37 complexity | 65cd1e8a597272353274a2635c25219c MD5 | raw file
  1from li_std_vector_extra import *
  2
  3iv = IntVector(4)
  4for i in range(0,4):
  5    iv[i] = i
  6
  7x = average(iv)
  8y = average([1,2,3,4])
  9
 10a = half([10,10.5,11,11.5])
 11
 12dv = DoubleVector(10)
 13for i in range(0,10):
 14    dv[i] = i/2.0
 15
 16halve_in_place(dv)
 17
 18
 19bv = BoolVector(4)
 20bv[0]= 1
 21bv[1]= 0
 22bv[2]= 4
 23bv[3]= 0
 24
 25if bv[0] != bv[2]:
 26    raise RuntimeError,"bad std::vector<bool> mapping"
 27
 28b = B(5)
 29va = VecA([b,None,b,b])
 30
 31if va[0].f(1) != 6:
 32    raise RuntimeError,"bad std::vector<A*> mapping"
 33
 34if vecAptr(va) != 6:
 35    raise RuntimeError,"bad std::vector<A*> mapping"
 36
 37b.val = 7
 38if va[3].f(1) != 8:
 39    raise RuntimeError,"bad std::vector<A*> mapping"
 40
 41
 42ip = PtrInt()
 43ap = new_ArrInt(10)
 44
 45ArrInt_setitem(ip,0,123)
 46ArrInt_setitem(ap,2,123)
 47
 48vi = IntPtrVector((ip,ap,None))
 49if ArrInt_getitem(vi[0],0) != ArrInt_getitem(vi[1],2):
 50    raise RuntimeError,"bad std::vector<int*> mapping"
 51
 52delete_ArrInt(ap)    
 53
 54
 55a = halfs([10,8,4,3])
 56
 57v = IntVector()
 58v[0:2] = [1,2]
 59if v[0] != 1 or v[1] != 2:
 60    raise RuntimeError,"bad setslice"
 61
 62if v[0:-1][0] != 1:
 63    raise RuntimeError,"bad getslice"
 64
 65if v[0:-2].size() != 0:
 66    raise RuntimeError,"bad getslice"
 67
 68v[0:1] = [2]
 69if v[0] != 2:
 70    raise RuntimeError,"bad setslice"
 71
 72v[1:] = [3]
 73if v[1] != 3:
 74    raise RuntimeError,"bad setslice"
 75
 76v[2:] = [3]
 77if v[2] != 3:
 78    raise RuntimeError,"bad setslice"
 79
 80if v[0:][0] != v[0]:
 81    raise RuntimeError,"bad getslice"
 82
 83
 84del v[:]
 85if v.size() != 0:
 86    raise RuntimeError,"bad getslice"    
 87
 88del v[:]
 89if v.size() != 0:
 90    raise RuntimeError,"bad getslice"    
 91
 92
 93
 94v = vecStr(["hello ", "world"])
 95if v[0] != 'hello world':
 96    raise RuntimeError,"bad std::string+std::vector"
 97    
 98
 99
100pv = pyvector([1, "hello", (1,2)])
101
102if pv[1] != "hello":
103    raise RuntimeError
104
105
106iv = IntVector(5)
107for i in range(0,5):
108    iv[i] = i
109
110iv[1:3] = []
111if iv[1] != 3:
112    raise RuntimeError
113
114# Overloading checks
115if overloaded1(iv) != "vector<int>":
116  raise RuntimeError
117
118if overloaded1(dv) != "vector<double>":
119  raise RuntimeError
120
121if overloaded2(iv) != "vector<int>":
122  raise RuntimeError
123
124if overloaded2(dv) != "vector<double>":
125  raise RuntimeError
126
127if overloaded3(iv) != "vector<int> *":
128  raise RuntimeError
129
130if overloaded3(None) != "vector<int> *":
131  raise RuntimeError
132
133if overloaded3(100) != "int":
134  raise RuntimeError
135
136
137# vector pointer checks
138ip = makeIntPtr(11)
139dp = makeDoublePtr(33.3)
140error = 0
141try:
142  vi = IntPtrVector((ip, dp)) # check vector<int *> does not accept double * element
143  error = 1
144except:
145  pass
146
147if error:
148  raise RuntimeError
149
150vi = IntPtrVector((ip, makeIntPtr(22)))
151if extractInt(vi[0]) != 11:
152  raise RuntimeError
153
154if extractInt(vi[1]) != 22:
155  raise RuntimeError
156
157# vector const pointer checks
158csp = makeConstShortPtr(111)
159
160error = 0
161try:
162  vcs = ConstShortPtrVector((csp, dp)) # check vector<const unsigned short *> does not accept double * element
163  error = 1
164except:
165  pass
166
167if error:
168  raise RuntimeError
169
170vcs = ConstShortPtrVector((csp, makeConstShortPtr(222)))
171if extractConstShort(vcs[0]) != 111:
172  raise RuntimeError
173
174if extractConstShort(vcs[1]) != 222:
175  raise RuntimeError
176