~ubuntu-branches/ubuntu/oneiric/swig1.3/oneiric

« back to all changes in this revision

Viewing changes to Examples/test-suite/python/li_std_vector_extra_runme.py

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2009-11-15 14:00:28 UTC
  • mfrom: (1.2.9 upstream) (2.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091115140028-me7amr2rie8zz1xn
Tags: 1.3.40-2ubuntu1
* Merge from Debian testing (LP: #356529), remaining changes:
  - Drop libchicken-dev from the build-depends (it's in universe)
  - Remove Pike from package description and from configure flags
  - drop "--without-mzscheme", we don't have it in our build-depends
  - use php-config5
  - Clean Runtime/ as well.
  - debian/rules (clean): Remove Lib/ocaml/swigp4.ml.
* debian/rules: Remove hardcoded python version.
* Remove upper limit for python from Build-Depends.

Show diffs side-by-side

added added

removed removed

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