* Bug 13303 fixed: mprintf msprintf mfprintf now accept input booleans
[scilab.git] / scilab / modules / output_stream / tests / unit_tests / mprintf.tst
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
9 // <-- CLI SHELL MODE -->
10
11 // unit tests for msprintf function
12 // =============================================================================
13
14 // format '%f'
15 // =============================================================================
16
17 mprintf("==>%f<==\n\n",-35);
18
19 mprintf("==>%f<==\n\n",35.55);
20 mprintf("==>%f<==\n\n",0.00433);
21 mprintf("==>%f<==\n\n",0.0000000345456);
22 mprintf("==>%f<==\n\n",1112423453);
23
24 mprintf("==>%15f<==\n\n",-35);
25 mprintf("==>%15f<==\n\n",0.00433);
26 mprintf("==>%15f<==\n\n",0.0000000345456);
27 mprintf("==>%15f<==\n\n",1112423453);
28
29 mprintf("==>%.1f<==\n\n" ,-35);
30 mprintf("==>%.0f<==\n\n" ,-35);
31 mprintf("==>%#.0f<==\n\n",-35);
32 mprintf("==>%.1f<==\n\n" ,0.00433);
33 mprintf("==>%.15f<==\n\n",0.0000000345456);
34 mprintf("==>%.1f<==\n\n" ,11124234534545);
35
36 // format '%g'
37 // =============================================================================
38
39 mprintf("==>%g<==\n\n" ,-35);
40 mprintf("==>%g<==\n\n" ,35.55);
41 mprintf("==>%g<==\n\n" ,35.551234567890);
42 mprintf("==>%+g<==\n\n",35.551234567890);
43 mprintf("==>%g<==\n\n" ,0.00433);
44 mprintf("==>%g<==\n\n" ,0.0000000345456);
45 mprintf("==>%g<==\n\n" ,11124234534545);
46
47 mprintf("==>%15g<==\n\n",-35);
48 mprintf("==>%15g<==\n\n",0.00433);
49 mprintf("==>%15g<==\n\n",0.0000000345456);
50 mprintf("==>%15g<==\n\n",11124234534545);
51
52 mprintf("==>%.1g<==\n\n",-35.1);
53 mprintf("==>%.0g<==\n\n",-35.1);
54 mprintf("==>%#.0g<==\n\n",-35.1);
55 mprintf("==>%#.0G<==\n\n",-35.1);
56 mprintf("==>%.1g<==\n\n",0.00433);
57 mprintf("==>%.15g<==\n\n",0.0000000345456);
58 mprintf("==>%.1g<==\n\n",11124234534545);
59
60 // format '%e'
61 // =============================================================================
62
63 mprintf("==>%e<==\n\n",-35);
64 mprintf("==>%e<==\n\n",35.55);
65 mprintf("==>%+e<==\n\n",35.55);
66 mprintf("==>%e<==\n\n",35.551234567890);
67 mprintf("==>%e<==\n\n",0.00433);
68 mprintf("==>%e<==\n\n",0.0000000345456);
69 mprintf("==>%e<==\n\n",11124234534545);
70 mprintf("==>%E<==\n\n",11124234534545);
71
72 mprintf("==>%15e<==\n\n",-35);
73 mprintf("==>%15e<==\n\n",0.00433);
74 mprintf("==>%15e<==\n\n",0.0000000345456);
75 mprintf("==>%+15e<==\n\n",0.0000000345456);
76 mprintf("==>%15e<==\n\n",11124234534545);
77
78 mprintf("==>%.1e<==\n\n",-35);
79 mprintf("==>%.0e<==\n\n",-35.1);
80 mprintf("==>%#.0e<==\n\n",-35.1);
81 mprintf("==>%.1e<==\n\n",0.00433);
82 mprintf("==>%.15e<==\n\n",0.0000000345456);
83 mprintf("==>%.1e<==\n\n",11124234534545);
84
85 // format '%c'
86 // =============================================================================
87
88 mprintf("==>%c<==\n\n","t");
89 mprintf("==>%10c<==\n\n","t");
90 mprintf("==>%10.3c<==\n\n","t");
91 mprintf("==>%-10c<==\n\n","t");
92
93 // format '%s'
94 // =============================================================================
95
96 mprintf("==>%s<==\n\n","text");
97 mprintf("==>%10s<==\n\n","text");
98 mprintf("==>%10.3s<==\n\n","text");
99 mprintf("==>%-10s<==\n\n","text");
100 mprintf("==>%s<==\n\n","t");
101
102 // format '%x'
103 // =============================================================================
104
105 mprintf("==>%x<==\n\n",123);
106 mprintf("==>%.10x<==\n\n",123);
107 mprintf("==>%x<==\n\n",-123);
108 mprintf("==>%X<==\n\n",-123);
109 mprintf("==>%#.3X<==\n\n",12);
110
111 // Vectorisation
112 // =============================================================================
113
114 // test 1
115
116 A = "row "+string(1:10)';
117 B = [ ..
118     50.153416    28.06498     40.948255 ; ..
119     43.685876    12.800585    87.841258 ; ..
120     26.931248    77.831286    11.383597 ; ..
121     63.257449    21.190304    19.983377 ; ..
122     40.51954     11.213547    56.186607 ; ..
123     91.847078    68.56896     58.961773 ; ..
124     4.3733433    15.312167    68.539797 ; ..
125     48.185089    69.708506    89.062247 ; ..
126     26.39556     84.155184    50.422128 ; ..
127     41.481037    40.620248    34.936154 ];
128
129 mprintf("==>%10s : %08.4f %08.4f %08.4f<==\n\n",A,B);
130
131 // test 2
132
133 C = [ ..
134     50.153416    28.06498  ; ..
135     43.685876    12.800585 ; ..
136     26.931248    77.831286 ; ..
137     63.257449    21.190304 ; ..
138     40.51954     11.213547 ; ..
139     91.847078    68.56896  ; ..
140     4.3733433    15.312167 ; ..
141     48.185089    69.708506 ; ..
142     26.39556     84.155184 ; ..
143     41.481037    40.620248 ];
144
145
146 D = [ ..
147     40.948255 ; ..
148     87.841258 ; ..
149     11.383597 ; ..
150     19.983377 ; ..
151     56.186607 ; ..
152     58.961773 ; ..
153     68.539797 ; ..
154     89.062247 ; ..
155     50.422128 ; ..
156     34.936154 ];
157
158 mprintf("==>%10s : %08.4f %08.4f %08.4f<==\n\n",A,C,D);
159
160 // Booleans
161 // =============================================================================
162 n = [%pi ; %e];
163 b = [%T ; %F];
164 for f = ["d" "i" "u" "o" "x" "X" "g" "G"]
165     mprintf("%"+f+"\n", b);
166     mprintf("%"+f+" %d\n", b, n);
167     if and(f <> ["u" "o" "x" "X"])  // http://bugzilla.scilab.org/16563
168         mprintf("%2$"+f+" %1$d\n", n, b);
169     end
170 end
171 // %f
172 msprintf("%f\n", b);
173 mprintf("%f %d\n", b, n);
174 mprintf("%2$f %1$d\n", n, b);
175 // %e
176 mprintf("%e\n", b);
177 mprintf("%e %d\n", b, n);
178 mprintf("%2$e %1$d\n", n, b);
179 // %E
180 mprintf("%E\n", b);
181 mprintf("%E %d\n", b, n);
182 mprintf("%2$E %1$d\n", n, b);
183 // %s, %c
184 for f = ["s" "c"]
185     mprintf("%"+f+"\n", b);
186     mprintf("%"+f+" %d\n", b, n);
187     mprintf("%2$"+f+" %1$d\n", n, b);
188 end