* Bug 13303 fixed: mprintf msprintf mfprintf now accept input booleans
[scilab.git] / scilab / modules / output_stream / tests / unit_tests / mprintf.dia.ref
1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2008 - INRIA
4 // Copyright (C) 2020 - Samuel GOUGEON - Le Mans Universit√©
5 //
6 //  This file is distributed under the same license as the Scilab package.
7 // =============================================================================
8 // <-- CLI SHELL MODE -->
9 // unit tests for msprintf function
10 // =============================================================================
11 // format '%f'
12 // =============================================================================
13 mprintf("==>%f<==\n\n",-35);
14 ==>-35.000000<==
15 mprintf("==>%f<==\n\n",35.55);
16 ==>35.550000<==
17 mprintf("==>%f<==\n\n",0.00433);
18 ==>0.004330<==
19 mprintf("==>%f<==\n\n",0.0000000345456);
20 ==>0.000000<==
21 mprintf("==>%f<==\n\n",1112423453);
22 ==>1112423453.000000<==
23 mprintf("==>%15f<==\n\n",-35);
24 ==>     -35.000000<==
25 mprintf("==>%15f<==\n\n",0.00433);
26 ==>       0.004330<==
27 mprintf("==>%15f<==\n\n",0.0000000345456);
28 ==>       0.000000<==
29 mprintf("==>%15f<==\n\n",1112423453);
30 ==>1112423453.000000<==
31 mprintf("==>%.1f<==\n\n" ,-35);
32 ==>-35.0<==
33 mprintf("==>%.0f<==\n\n" ,-35);
34 ==>-35<==
35 mprintf("==>%#.0f<==\n\n",-35);
36 ==>-35.<==
37 mprintf("==>%.1f<==\n\n" ,0.00433);
38 ==>0.0<==
39 mprintf("==>%.15f<==\n\n",0.0000000345456);
40 ==>0.000000034545600<==
41 mprintf("==>%.1f<==\n\n" ,11124234534545);
42 ==>11124234534545.0<==
43 // format '%g'
44 // =============================================================================
45 mprintf("==>%g<==\n\n" ,-35);
46 ==>-35<==
47 mprintf("==>%g<==\n\n" ,35.55);
48 ==>35.55<==
49 mprintf("==>%g<==\n\n" ,35.551234567890);
50 ==>35.5512<==
51 mprintf("==>%+g<==\n\n",35.551234567890);
52 ==>+35.5512<==
53 mprintf("==>%g<==\n\n" ,0.00433);
54 ==>0.00433<==
55 mprintf("==>%g<==\n\n" ,0.0000000345456);
56 ==>3.45456e-08<==
57 mprintf("==>%g<==\n\n" ,11124234534545);
58 ==>1.11242e+13<==
59 mprintf("==>%15g<==\n\n",-35);
60 ==>            -35<==
61 mprintf("==>%15g<==\n\n",0.00433);
62 ==>        0.00433<==
63 mprintf("==>%15g<==\n\n",0.0000000345456);
64 ==>    3.45456e-08<==
65 mprintf("==>%15g<==\n\n",11124234534545);
66 ==>    1.11242e+13<==
67 mprintf("==>%.1g<==\n\n",-35.1);
68 ==>-4e+01<==
69 mprintf("==>%.0g<==\n\n",-35.1);
70 ==>-4e+01<==
71 mprintf("==>%#.0g<==\n\n",-35.1);
72 ==>-4.e+01<==
73 mprintf("==>%#.0G<==\n\n",-35.1);
74 ==>-4.E+01<==
75 mprintf("==>%.1g<==\n\n",0.00433);
76 ==>0.004<==
77 mprintf("==>%.15g<==\n\n",0.0000000345456);
78 ==>3.45456e-08<==
79 mprintf("==>%.1g<==\n\n",11124234534545);
80 ==>1e+13<==
81 // format '%e'
82 // =============================================================================
83 mprintf("==>%e<==\n\n",-35);
84 ==>-3.500000e+01<==
85 mprintf("==>%e<==\n\n",35.55);
86 ==>3.555000e+01<==
87 mprintf("==>%+e<==\n\n",35.55);
88 ==>+3.555000e+01<==
89 mprintf("==>%e<==\n\n",35.551234567890);
90 ==>3.555123e+01<==
91 mprintf("==>%e<==\n\n",0.00433);
92 ==>4.330000e-03<==
93 mprintf("==>%e<==\n\n",0.0000000345456);
94 ==>3.454560e-08<==
95 mprintf("==>%e<==\n\n",11124234534545);
96 ==>1.112423e+13<==
97 mprintf("==>%E<==\n\n",11124234534545);
98 ==>1.112423E+13<==
99 mprintf("==>%15e<==\n\n",-35);
100 ==>  -3.500000e+01<==
101 mprintf("==>%15e<==\n\n",0.00433);
102 ==>   4.330000e-03<==
103 mprintf("==>%15e<==\n\n",0.0000000345456);
104 ==>   3.454560e-08<==
105 mprintf("==>%+15e<==\n\n",0.0000000345456);
106 ==>  +3.454560e-08<==
107 mprintf("==>%15e<==\n\n",11124234534545);
108 ==>   1.112423e+13<==
109 mprintf("==>%.1e<==\n\n",-35);
110 ==>-3.5e+01<==
111 mprintf("==>%.0e<==\n\n",-35.1);
112 ==>-4e+01<==
113 mprintf("==>%#.0e<==\n\n",-35.1);
114 ==>-4.e+01<==
115 mprintf("==>%.1e<==\n\n",0.00433);
116 ==>4.3e-03<==
117 mprintf("==>%.15e<==\n\n",0.0000000345456);
118 ==>3.454560000000000e-08<==
119 mprintf("==>%.1e<==\n\n",11124234534545);
120 ==>1.1e+13<==
121 // format '%c'
122 // =============================================================================
123 mprintf("==>%c<==\n\n","t");
124 ==>t<==
125 mprintf("==>%10c<==\n\n","t");
126 ==>         t<==
127 mprintf("==>%10.3c<==\n\n","t");
128 ==>         t<==
129 mprintf("==>%-10c<==\n\n","t");
130 ==>t         <==
131 // format '%s'
132 // =============================================================================
133 mprintf("==>%s<==\n\n","text");
134 ==>text<==
135 mprintf("==>%10s<==\n\n","text");
136 ==>      text<==
137 mprintf("==>%10.3s<==\n\n","text");
138 ==>       tex<==
139 mprintf("==>%-10s<==\n\n","text");
140 ==>text      <==
141 mprintf("==>%s<==\n\n","t");
142 ==>t<==
143 // format '%x'
144 // =============================================================================
145 mprintf("==>%x<==\n\n",123);
146 ==>7b<==
147 mprintf("==>%.10x<==\n\n",123);
148 ==>000000007b<==
149 mprintf("==>%x<==\n\n",-123);
150 ==>ffffff85<==
151 mprintf("==>%X<==\n\n",-123);
152 ==>FFFFFF85<==
153 mprintf("==>%#.3X<==\n\n",12);
154 ==>0X00C<==
155 // Vectorisation
156 // =============================================================================
157 // test 1
158 A = "row "+string(1:10)';
159 B = [ ..
160     50.153416    28.06498     40.948255 ; ..
161     43.685876    12.800585    87.841258 ; ..
162     26.931248    77.831286    11.383597 ; ..
163     63.257449    21.190304    19.983377 ; ..
164     40.51954     11.213547    56.186607 ; ..
165     91.847078    68.56896     58.961773 ; ..
166     4.3733433    15.312167    68.539797 ; ..
167     48.185089    69.708506    89.062247 ; ..
168     26.39556     84.155184    50.422128 ; ..
169     41.481037    40.620248    34.936154 ];
170 mprintf("==>%10s : %08.4f %08.4f %08.4f<==\n\n",A,B);
171 ==>     row 1 : 050.1534 028.0650 040.9483<==
172 ==>     row 2 : 043.6859 012.8006 087.8413<==
173 ==>     row 3 : 026.9312 077.8313 011.3836<==
174 ==>     row 4 : 063.2574 021.1903 019.9834<==
175 ==>     row 5 : 040.5195 011.2135 056.1866<==
176 ==>     row 6 : 091.8471 068.5690 058.9618<==
177 ==>     row 7 : 004.3733 015.3122 068.5398<==
178 ==>     row 8 : 048.1851 069.7085 089.0622<==
179 ==>     row 9 : 026.3956 084.1552 050.4221<==
180 ==>    row 10 : 041.4810 040.6202 034.9362<==
181 // test 2
182 C = [ ..
183     50.153416    28.06498  ; ..
184     43.685876    12.800585 ; ..
185     26.931248    77.831286 ; ..
186     63.257449    21.190304 ; ..
187     40.51954     11.213547 ; ..
188     91.847078    68.56896  ; ..
189     4.3733433    15.312167 ; ..
190     48.185089    69.708506 ; ..
191     26.39556     84.155184 ; ..
192     41.481037    40.620248 ];
193 D = [ ..
194     40.948255 ; ..
195     87.841258 ; ..
196     11.383597 ; ..
197     19.983377 ; ..
198     56.186607 ; ..
199     58.961773 ; ..
200     68.539797 ; ..
201     89.062247 ; ..
202     50.422128 ; ..
203     34.936154 ];
204 mprintf("==>%10s : %08.4f %08.4f %08.4f<==\n\n",A,C,D);
205 ==>     row 1 : 050.1534 028.0650 040.9483<==
206 ==>     row 2 : 043.6859 012.8006 087.8413<==
207 ==>     row 3 : 026.9312 077.8313 011.3836<==
208 ==>     row 4 : 063.2574 021.1903 019.9834<==
209 ==>     row 5 : 040.5195 011.2135 056.1866<==
210 ==>     row 6 : 091.8471 068.5690 058.9618<==
211 ==>     row 7 : 004.3733 015.3122 068.5398<==
212 ==>     row 8 : 048.1851 069.7085 089.0622<==
213 ==>     row 9 : 026.3956 084.1552 050.4221<==
214 ==>    row 10 : 041.4810 040.6202 034.9362<==
215 // Booleans
216 // =============================================================================
217 n = [%pi ; %e];
218 b = [%T ; %F];
219 for f = ["d" "i" "u" "o" "x" "X" "g" "G"]
220     mprintf("%"+f+"\n", b);
221     mprintf("%"+f+" %d\n", b, n);
222     if and(f <> ["u" "o" "x" "X"])  // http://bugzilla.scilab.org/16563
223         mprintf("%2$"+f+" %1$d\n", n, b);
224     end
225 end
226 1
227 0
228 1 3
229 0 2
230 1 3
231 0 2
232 1
233 0
234 1 3
235 0 2
236 1 3
237 0 2
238 1
239 0
240 1 3
241 0 2
242 1
243 0
244 1 3
245 0 2
246 1
247 0
248 1 3
249 0 2
250 1
251 0
252 1 3
253 0 2
254 1
255 0
256 1 3
257 0 2
258 1 3
259 0 2
260 1
261 0
262 1 3
263 0 2
264 1 3
265 0 2
266 // %f
267 msprintf("%f\n", b);
268 mprintf("%f %d\n", b, n);
269 1.000000 3
270 0.000000 2
271 mprintf("%2$f %1$d\n", n, b);
272 1.000000 3
273 0.000000 2
274 // %e
275 mprintf("%e\n", b);
276 1.000000e+00
277 0.000000e+00
278 mprintf("%e %d\n", b, n);
279 1.000000e+00 3
280 0.000000e+00 2
281 mprintf("%2$e %1$d\n", n, b);
282 1.000000e+00 3
283 0.000000e+00 2
284 // %E
285 mprintf("%E\n", b);
286 1.000000E+00
287 0.000000E+00
288 mprintf("%E %d\n", b, n);
289 1.000000E+00 3
290 0.000000E+00 2
291 mprintf("%2$E %1$d\n", n, b);
292 1.000000E+00 3
293 0.000000E+00 2
294 // %s, %c
295 for f = ["s" "c"]
296     mprintf("%"+f+"\n", b);
297     mprintf("%"+f+" %d\n", b, n);
298     mprintf("%2$"+f+" %1$d\n", n, b);
299 end
300 T
301 F
302 T 3
303 F 2
304 T 3
305 F 2
306 T
307 F
308 T 3
309 F 2
310 T 3
311 F 2