* Bug 16592 fixed: | and & between complex and boolean or []
[scilab.git] / scilab / modules / ast / tests / unit_tests / and.tst
1 // ============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
4 // Copyright (C) 2020 - Samuel GOUGEON
5 //
6 //  This file is distributed under the same license as the Scilab package.
7 // ============================================================================
8 //
9 // <-- CLI SHELL MODE -->
10 // <-- NO CHECK REF -->
11 //
12 // <-- Short Description -->
13 // Unitary tests of the & operator
14 //
15 // See also: or_and.tst
16
17 empty = [];
18 r = 2;
19 R = [1,2;3,4];
20 R3(:,:,1) = R;
21 R3(:,:,2) = R';
22 c = 1 + 2*%i;
23 C = [1+2*%i,2+4*%i;3+6*%i,4+8*%i];
24 C3(:,:,1) = C;
25 C3(:,:,2) = C';
26 e = eye();
27 ec = (5+%i) * eye();
28 p = 1 + %s - %s**2;
29 pc = 1 + %s - %s**2 + ( 2 - 3 * %s + 4 * %s**2 ) * %i;
30 P = [2*p, -3*p;4*p,-5*p];
31 PC = [2*pc, -3*pc;4*pc,-5*pc];
32 SP = sparse([1,2;4,5;3,10],[1,2,3]);
33 SPC = sparse([1,2;4,5;3,10],[1,2,3]) * ( 1 + 4*%i);
34 SPB = sparse([1,2;2,1],[%t;%t],[2,2]);
35
36 i8 = int8(-8);
37 ui8 = uint8(8);
38 I8 = int8([-8 -16 ; -24 -32]);
39 UI8 = uint8([8 16 ; 24 32]);
40
41 I16 = int16([-16 -32 ; -48 -64]);
42 UI16 = uint16([16 32 ; 48 64]);
43 i16 = int16(-16);
44 ui16 = uint16(16);
45
46 i32 = int32(-32);
47 ui32 = uint32(32);
48 I32 = int32([-32 -64 ; -96 -128]);
49 UI32 = uint32([32 64 ; 96 128]);
50
51 str = "string";
52 STR = ["string1" "string2";"string3" "string4"];
53
54 b = %f;
55 B = [%t %f;%f %t];
56
57 assert_checkequal(empty & empty, []);
58 assert_checkequal(empty & r, []);
59 assert_checkequal(empty & R, []);
60 assert_checkequal(empty & c, []);
61 assert_checkequal(empty & C, []);
62 assert_checkequal(empty & e, []);
63 assert_checkequal(empty & b, %f);
64 assert_checkequal(empty & B, [%t,%f;%f,%t]);
65
66 assert_checkequal(r & empty, []);
67 assert_checkequal(r & r, %t);
68 assert_checkequal(r & R, [%t,%t;%t,%t]);
69 assert_checkequal(r & c, %t);
70 assert_checkequal(r & C, [%t,%t;%t,%t]);
71 assert_checkequal(r & e, %t);
72 assert_checkequal(r & b, %f);
73 assert_checkequal(r & B, [%t,%f;%f,%t]);
74
75 assert_checkequal(R & empty, []);
76 assert_checkequal(R & r, [%t,%t;%t,%t]);
77 assert_checkequal(R & R, [%t,%t;%t,%t]);
78 assert_checkequal(R & c, [%t,%t;%t,%t]);
79 assert_checkequal(R & C, [%t,%t;%t,%t]);
80 assert_checkequal(R & e, [%t,%t;%t,%t]);
81 assert_checkequal(R & b, [%f,%f;%f,%f]);
82 assert_checkequal(R & B, [%t,%f;%f,%t]);
83
84 assert_checkequal(c & empty, []);
85 assert_checkequal(c & r, %t);
86 assert_checkequal(c & R, [%t,%t;%t,%t]);
87 assert_checkequal(c & c, %t);
88 assert_checkequal(c & C, [%t,%t;%t,%t]);
89 assert_checkequal(c & e, %t);
90 assert_checkequal(c & b, %f);
91 assert_checkequal(c & B, [%t,%f;%f,%t]);
92
93 assert_checkequal(C & empty, []);
94 assert_checkequal(C & r, [%t,%t;%t,%t]);
95 assert_checkequal(C & R, [%t,%t;%t,%t]);
96 assert_checkequal(C & c, [%t,%t;%t,%t]);
97 assert_checkequal(C & C, [%t,%t;%t,%t]);
98 assert_checkequal(C & e, [%t,%t;%t,%t]);
99 assert_checkequal(C & b, [%f,%f;%f,%f]);
100 assert_checkequal(C & B, [%t,%f;%f,%t]);
101
102 assert_checkequal(e & empty, []);
103 assert_checkequal(e & r, %t);
104 assert_checkequal(e & R, [%t,%t;%t,%t]);
105 assert_checkequal(e & c, %t);
106 assert_checkequal(e & C, [%t,%t;%t,%t]);
107 assert_checkequal(e & b, %f);
108 assert_checkequal(e & B, [%t,%f;%f,%t]);
109
110 assert_checkequal(b & empty, %f);
111 assert_checkequal(b & r, %f);
112 assert_checkequal(b & R, [%f,%f;%f,%f]);
113 assert_checkequal(b & c, %f);
114 assert_checkequal(b & C, [%f,%f;%f,%f]);
115 assert_checkequal(b & e, %f);
116 assert_checkequal(b & b, %f);
117 assert_checkequal(b & B, [%f,%f;%f,%f]);
118 assert_checkequal(b & SPB, sparse([1,1], [%f], [2, 2]));
119
120 assert_checkequal(B & empty, [%t,%f;%f,%t]);
121 assert_checkequal(B & r, [%t,%f;%f,%t]);
122 assert_checkequal(B & R, [%t,%f;%f,%t]);
123 assert_checkequal(B & c, [%t,%f;%f,%t]);
124 assert_checkequal(B & C, [%t,%f;%f,%t]);
125 assert_checkequal(B & e, [%t,%f;%f,%t]);
126 assert_checkequal(B & b, [%f,%f;%f,%f]);
127 assert_checkequal(B & B, [%t,%f;%f,%t]);
128 assert_checkequal(B & SPB, sparse([1,1], [%f], [2, 2]));
129
130 assert_checkequal(SPB & b, sparse([1,1], [%f], [2, 2]));
131 assert_checkequal(SPB & B, sparse([1,1], [%f], [2, 2]));
132 assert_checkequal(SPB & SPB, sparse([1,2;2,1],[%t;%t],[2,2]));
133
134 assert_checkequal(i8 & i8, int8(-8));
135 assert_checkequal(i8 & I8, int8([-8,-16;-24,-32]));
136 assert_checkequal(i8 & ui8, uint8(8));
137 assert_checkequal(i8 & UI8, uint8([8,16;24,32]));
138 assert_checkequal(i8 & i16, int16(-16));
139 assert_checkequal(i8 & I16, int16([-16,-32;-48,-64]));
140 assert_checkequal(i8 & ui16, uint16(16));
141 assert_checkequal(i8 & UI16, uint16([16,32;48,64]));
142 assert_checkequal(i8 & i32, int32(-32));
143 assert_checkequal(i8 & I32, int32([-32,-64;-96,-128]));
144 assert_checkequal(i8 & ui32, uint32(32));
145 assert_checkequal(i8 & UI32, uint32([32,64;96,128]));
146
147 assert_checkequal(I8 & i8, int8([-8,-16;-24,-32]));
148 assert_checkequal(I8 & I8, int8([-8,-16;-24,-32]));
149 assert_checkequal(I8 & ui8, uint8([8,0;8,0]));
150 assert_checkequal(I8 & UI8, uint8([8,16;8,32]));
151 assert_checkequal(I8 & i16, int16([-16,-16;-32,-32]));
152 assert_checkequal(I8 & I16, int16([-16,-32;-64,-64]));
153 assert_checkequal(I8 & ui16, uint16([16,16;0,0]));
154 assert_checkequal(I8 & UI16, uint16([16,32;32,64]));
155 assert_checkequal(I8 & i32, int32([-32,-32;-32,-32]));
156 assert_checkequal(I8 & I32, int32([-32,-64;-96,-128]));
157 assert_checkequal(I8 & ui32, uint32([32,32;32,32]));
158 assert_checkequal(I8 & UI32, uint32([32,64;96,128]));
159
160 assert_checkequal(ui8 & i8, uint8(8));
161 assert_checkequal(ui8 & I8, uint8([8,0;8,0]));
162 assert_checkequal(ui8 & ui8, uint8(8));
163 assert_checkequal(ui8 & UI8, uint8([8,0;8,0]));
164 assert_checkequal(ui8 & i16, uint16(0));
165 assert_checkequal(ui8 & I16, uint16([0,0;0,0]));
166 assert_checkequal(ui8 & ui16, uint16(0));
167 assert_checkequal(ui8 & UI16, uint16([0,0;0,0]));
168 assert_checkequal(ui8 & i32, uint32(0));
169 assert_checkequal(ui8 & I32, uint32([0,0;0,0]));
170 assert_checkequal(ui8 & ui32, uint32(0));
171 assert_checkequal(ui8 & UI32, uint32([0,0;0,0]));
172
173 assert_checkequal(UI8 & i8, uint8([8,16;24,32]));
174 assert_checkequal(UI8 & I8, uint8([8,16;8,32]));
175 assert_checkequal(UI8 & ui8, uint8([8,0;8,0]));
176 assert_checkequal(UI8 & UI8, uint8([8,16;24,32]));
177 assert_checkequal(UI8 & i16, uint16([0,16;16,32]));
178 assert_checkequal(UI8 & I16, uint16([0,0;16,0]));
179 assert_checkequal(UI8 & ui16, uint16([0,16;16,0]));
180 assert_checkequal(UI8 & UI16, uint16([0,0;16,0]));
181 assert_checkequal(UI8 & i32, uint32([0,0;0,32]));
182 assert_checkequal(UI8 & I32, uint32([0,0;0,0]));
183 assert_checkequal(UI8 & ui32, uint32([0,0;0,32]));
184 assert_checkequal(UI8 & UI32, uint32([0,0;0,0]));
185
186 assert_checkequal(i16 & i8, int16(-16));
187 assert_checkequal(i16 & I8, int16([-16,-16;-32,-32]));
188 assert_checkequal(i16 & ui8, uint16(0));
189 assert_checkequal(i16 & UI8, uint16([0,16;16,32]));
190 assert_checkequal(i16 & i16, int16(-16));
191 assert_checkequal(i16 & I16, int16([-16,-32;-48,-64]));
192 assert_checkequal(i16 & ui16, uint16(16));
193 assert_checkequal(i16 & UI16, uint16([16,32;48,64]));
194 assert_checkequal(i16 & i32, int32(-32));
195 assert_checkequal(i16 & I32, int32([-32,-64;-96,-128]));
196 assert_checkequal(i16 & ui32, uint32(32));
197 assert_checkequal(i16 & UI32, uint32([32,64;96,128]));
198
199 assert_checkequal(I16 & i8, int16([-16,-32;-48,-64]));
200 assert_checkequal(I16 & I8, int16([-16,-32;-64,-64]));
201 assert_checkequal(I16 & ui8, uint16([0,0;0,0]));
202 assert_checkequal(I16 & UI8, uint16([0,0;16,0]));
203 assert_checkequal(I16 & i16, int16([-16,-32;-48,-64]));
204 assert_checkequal(I16 & I16, int16([-16,-32;-48,-64]));
205 assert_checkequal(I16 & ui16, uint16([16,0;16,0]));
206 assert_checkequal(I16 & UI16, uint16([16,32;16,64]));
207 assert_checkequal(I16 & i32, int32([-32,-32;-64,-64]));
208 assert_checkequal(I16 & I32, int32([-32,-64;-128,-128]));
209 assert_checkequal(I16 & ui32, uint32([32,32;0,0]));
210 assert_checkequal(I16 & UI32, uint32([32,64;64,128]));
211
212 assert_checkequal(ui16 & i8, uint16(16));
213 assert_checkequal(ui16 & I8, uint16([16,16;0,0]));
214 assert_checkequal(ui16 & ui8, uint16(0));
215 assert_checkequal(ui16 & UI8, uint16([0,16;16,0]));
216 assert_checkequal(ui16 & i16, uint16(16));
217 assert_checkequal(ui16 & I16, uint16([16,0;16,0]));
218 assert_checkequal(ui16 & ui16, uint16(16));
219 assert_checkequal(ui16 & UI16, uint16([16,0;16,0]));
220 assert_checkequal(ui16 & i32, uint32(0));
221 assert_checkequal(ui16 & I32, uint32([0,0;0,0]));
222 assert_checkequal(ui16 & ui32, uint32(0));
223 assert_checkequal(ui16 & UI32, uint32([0,0;0,0]));
224
225 assert_checkequal(UI16 & i8, uint16([16,32;48,64]));
226 assert_checkequal(UI16 & I8, uint16([16,32;32,64]));
227 assert_checkequal(UI16 & ui8, uint16([0,0;0,0]));
228 assert_checkequal(UI16 & UI8, uint16([0,0;16,0]));
229 assert_checkequal(UI16 & i16, uint16([16,32;48,64]));
230 assert_checkequal(UI16 & I16, uint16([16,32;16,64]));
231 assert_checkequal(UI16 & ui16, uint16([16,0;16,0]));
232 assert_checkequal(UI16 & UI16, uint16([16,32;48,64]));
233 assert_checkequal(UI16 & i32, uint32([0,32;32,64]));
234 assert_checkequal(UI16 & I32, uint32([0,0;32,0]));
235 assert_checkequal(UI16 & ui32, uint32([0,32;32,0]));
236 assert_checkequal(UI16 & UI32, uint32([0,0;32,0]));
237
238 assert_checkequal(i32 & i8, int32(-32));
239 assert_checkequal(i32 & I8, int32([-32,-32;-32,-32]));
240 assert_checkequal(i32 & ui8, uint32(0));
241 assert_checkequal(i32 & UI8, uint32([0,0;0,32]));
242 assert_checkequal(i32 & i16, int32(-32));
243 assert_checkequal(i32 & I16, int32([-32,-32;-64,-64]));
244 assert_checkequal(i32 & ui16, uint32(0));
245 assert_checkequal(i32 & UI16, uint32([0,32;32,64]));
246 assert_checkequal(i32 & i32, int32(-32));
247 assert_checkequal(i32 & I32, int32([-32,-64;-96,-128]));
248 assert_checkequal(i32 & ui32, uint32(32));
249 assert_checkequal(i32 & UI32, uint32([32,64;96,128]));
250
251 assert_checkequal(I32 & i8, int32([-32,-64;-96,-128]));
252 assert_checkequal(I32 & I8, int32([-32,-64;-96,-128]));
253 assert_checkequal(I32 & ui8, uint32([0,0;0,0]));
254 assert_checkequal(I32 & UI8, uint32([0,0;0,0]));
255 assert_checkequal(I32 & i16, int32([-32,-64;-96,-128]));
256 assert_checkequal(I32 & I16, int32([-32,-64;-128,-128]));
257 assert_checkequal(I32 & ui16, uint32([0,0;0,0]));
258 assert_checkequal(I32 & UI16, uint32([0,0;32,0]));
259 assert_checkequal(I32 & i32, int32([-32,-64;-96,-128]));
260 assert_checkequal(I32 & I32, int32([-32,-64;-96,-128]));
261 assert_checkequal(I32 & ui32, uint32([32,0;32,0]));
262 assert_checkequal(I32 & UI32, uint32([32,64;32,128]));
263
264 assert_checkequal(ui32 & i8, uint32(32));
265 assert_checkequal(ui32 & I8, uint32([32,32;32,32]));
266 assert_checkequal(ui32 & ui8, uint32(0));
267 assert_checkequal(ui32 & UI8, uint32([0,0;0,32]));
268 assert_checkequal(ui32 & i16, uint32(32));
269 assert_checkequal(ui32 & I16, uint32([32,32;0,0]));
270 assert_checkequal(ui32 & ui16, uint32(0));
271 assert_checkequal(ui32 & UI16, uint32([0,32;32,0]));
272 assert_checkequal(ui32 & i32, uint32(32));
273 assert_checkequal(ui32 & I32, uint32([32,0;32,0]));
274 assert_checkequal(ui32 & ui32, uint32(32));
275 assert_checkequal(ui32 & UI32, uint32([32,0;32,0]));
276
277 assert_checkequal(UI32 & i8, uint32([32,64;96,128]));
278 assert_checkequal(UI32 & I8, uint32([32,64;96,128]));
279 assert_checkequal(UI32 & ui8, uint32([0,0;0,0]));
280 assert_checkequal(UI32 & UI8, uint32([0,0;0,0]));
281 assert_checkequal(UI32 & i16, uint32([32,64;96,128]));
282 assert_checkequal(UI32 & I16, uint32([32,64;64,128]));
283 assert_checkequal(UI32 & ui16, uint32([0,0;0,0]));
284 assert_checkequal(UI32 & UI16, uint32([0,0;32,0]));
285 assert_checkequal(UI32 & i32, uint32([32,64;96,128]));
286 assert_checkequal(UI32 & I32, uint32([32,64;32,128]));
287 assert_checkequal(UI32 & ui32, uint32([32,0;32,0]));
288 assert_checkequal(UI32 & UI32, uint32([32,64;96,128]));