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