bug 13972 : use of wildcard '*' in printf expressions was not managed
[scilab.git] / scilab / modules / output_stream / tests / unit_tests / msprintf.dia.ref
1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2008 - INRIA
4 // Copyright (C) 2013 - Scilab Enterprises - Adeline CARNIS
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 assert_checkequal(msprintf("%f",-35), "-35.000000");
14 assert_checkequal(msprintf("%f",35.55), "35.550000");
15 assert_checkequal(msprintf("%f",0.00433), "0.004330");
16 assert_checkequal(msprintf("%f",0.0000000345456), "0.000000");
17 assert_checkequal(msprintf("%f",1112423453), "1112423453.000000");
18 assert_checkequal(msprintf("%15f",-35), "     -35.000000");
19 assert_checkequal(msprintf("%15f",0.00433), "       0.004330");
20 assert_checkequal(msprintf("%15f",0.0000000345456), "       0.000000");
21 assert_checkequal(msprintf("%15f",1112423453), "1112423453.000000");
22 assert_checkequal(msprintf("%.1f" ,-35), "-35.0");
23 assert_checkequal(msprintf("%.0f" ,-35), "-35");
24 assert_checkequal(msprintf("%#.0f",-35), "-35.");
25 assert_checkequal(msprintf("%.1f" ,0.00433), "0.0");
26 assert_checkequal(msprintf("%.15f",0.0000000345456), "0.000000034545600");
27 assert_checkequal(msprintf("%.1f" ,11124234534545), "11124234534545.0");
28 // format '%g'
29 // =============================================================================
30 assert_checkequal(msprintf("%g" ,-35), "-35");
31 assert_checkequal(msprintf("%g" ,35.55), "35.55");
32 assert_checkequal(msprintf("%g" ,35.551234567890), "35.5512");
33 assert_checkequal(msprintf("%+g",35.551234567890), "+35.5512");
34 assert_checkequal(msprintf("%g" ,0.00433), "0.00433");
35 assert_checkequal(msprintf("%g" ,0.0000000345456), "3.45456e-08");
36 assert_checkequal(msprintf("%g" ,11124234534545), "1.11242e+13");
37 assert_checkequal(msprintf("%15g",-35), "            -35");
38 assert_checkequal(msprintf("%15g",0.00433), "        0.00433");
39 assert_checkequal(msprintf("%15g",0.0000000345456), "    3.45456e-08");
40 assert_checkequal(msprintf("%15g",11124234534545), "    1.11242e+13");
41 assert_checkequal(msprintf("%.1g",-35.1), "-4e+01");
42 assert_checkequal(msprintf("%.0g",-35.1), "-4e+01");
43 assert_checkequal(msprintf("%#.0g",-35.1), "-4.e+01");
44 assert_checkequal(msprintf("%#.0G",-35.1), "-4.E+01");
45 assert_checkequal(msprintf("%.1g",0.00433), "0.004");
46 assert_checkequal(msprintf("%.15g",0.0000000345456), "3.45456e-08");
47 assert_checkequal(msprintf("%.1g",11124234534545), "1e+13");
48 // format '%e'
49 // =============================================================================
50 assert_checkequal(msprintf("%e",-35), "-3.500000e+01");
51 assert_checkequal(msprintf("%e",35.55), "3.555000e+01");
52 assert_checkequal(msprintf("%+e",35.55), "+3.555000e+01");
53 assert_checkequal(msprintf("%e",35.551234567890), "3.555123e+01");
54 assert_checkequal(msprintf("%e",0.00433), "4.330000e-03");
55 assert_checkequal(msprintf("%e",0.0000000345456), "3.454560e-08");
56 assert_checkequal(msprintf("%e",11124234534545), "1.112423e+13");
57 assert_checkequal(msprintf("%E",11124234534545), "1.112423E+13");
58 assert_checkequal(msprintf("%15e",-35), "  -3.500000e+01");
59 assert_checkequal(msprintf("%15e",0.00433), "   4.330000e-03");
60 assert_checkequal(msprintf("%15e",0.0000000345456), "   3.454560e-08");
61 assert_checkequal(msprintf("%+15e",0.0000000345456), "  +3.454560e-08");
62 assert_checkequal(msprintf("%15e",11124234534545), "   1.112423e+13");
63 assert_checkequal(msprintf("%.1e",-35), "-3.5e+01");
64 assert_checkequal(msprintf("%.0e",-35.1), "-4e+01");
65 assert_checkequal(msprintf("%.1e",0.00433), "4.3e-03");
66 assert_checkequal(msprintf("%.15e",0.0000000345456), "3.454560000000000e-08");
67 assert_checkequal(msprintf("%.1e",11124234534545), "1.1e+13");
68 // format '%c'
69 // =============================================================================
70 assert_checkequal(msprintf("%c","t"), "t");
71 assert_checkequal(msprintf("%10c","t"), "         t");
72 assert_checkequal(msprintf("%10.3c","t"), "         t");
73 assert_checkequal(msprintf("%-10c","t"), "t         ");
74 // format '%s'
75 // =============================================================================
76 assert_checkequal(msprintf("%s","text"), "text");
77 assert_checkequal(msprintf("%10s","text"), "      text");
78 assert_checkequal(msprintf("%10.3s","text"), "       tex");
79 assert_checkequal(msprintf("%-10s","text"), "text      ");
80 assert_checkequal(msprintf("%s","t"), "t");
81 // format '%x'
82 // =============================================================================
83 assert_checkequal(msprintf("%x",123), "7b");
84 assert_checkequal(msprintf("%.10x",123), "000000007b");
85 assert_checkequal(msprintf("%x",-123), "ffffff85");
86 assert_checkequal(msprintf("%X",-123), "FFFFFF85");
87 assert_checkequal(msprintf("%#.3X",12), "0X00C");
88 // format '%o'
89 // =============================================================================
90 assert_checkequal(msprintf("%015o",-12), "000037777777764");
91 // Vectorisation
92 // =============================================================================
93 nb_row = 10000;
94 // test 1
95 A = "row "+string(1:nb_row)';
96 B = 100*rand(nb_row,3);
97 C = msprintf("%10s => %08.4f %08.4f %08.4f\n",A,B);
98 assert_checkequal(size(C), [nb_row,1]);
99 for i=1:nb_row
100     assert_checkequal(length(C(i)), 40);
101 end
102 // test 2
103 B = 100*rand(nb_row,2);
104 C = 100*rand(nb_row,1);
105 D = msprintf("%10s => %08.4f %08.4f %08.4f\n",A,B,C);
106 assert_checkequal(size(D), [nb_row,1]);
107 for i=1:nb_row
108     assert_checkequal(size(D), [nb_row,1]);
109 end
110 // test 3
111 B = 100*rand(nb_row,1);
112 C = 100*rand(nb_row,1);
113 D = 100*rand(nb_row,1);
114 E = msprintf("%10s => %08.4f %08.4f %08.4f\n",A,B,C,D);
115 assert_checkequal(size(E), [nb_row,1]);
116 for i=1:nb_row
117     assert_checkequal(size(E), [nb_row,1]);
118 end
119 // test 4
120 B = 100*rand(nb_row,1);
121 assert_checkfalse(execstr("msprintf(""%10s => %08.4f %08.4f %08.4f\n"",A,B,B);","errcatch")     == 0);
122 refMsg = msprintf(_("%s: Wrong number of input arguments: data doesn''t fit with format.\n"), "msprintf");
123 assert_checkerror("msprintf(""%10s => %08.4f %08.4f %08.4f\n"",A,B,B);", refMsg);
124 // No arg
125 assert_checkfalse(execstr("msprintf();","errcatch")     == 0);
126 refMsg = msprintf(_("%s: Wrong number of input arguments: at least %d expected.\n"), "msprintf", 1);
127 assert_checkerror("msprintf();", refMsg);
128 // overload: Arg not managed
129 s=poly(0,"s");
130 p=1+s+2*s^2;
131 assert_checkfalse(execstr("msprintf(""plop"",p);","errcatch") <> 999);
132 assert_checkfalse(execstr("msprintf(""%s %s"",""plop"");","errcatch")     <> 999);
133 refMsg = msprintf(_("%s: Wrong number of input arguments: data doesn''t fit with format.\n"), "msprintf");
134 assert_checkerror("msprintf(""%s %s"",""plop"");", refMsg);