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