mfprintf: implicit loop over column vectors now prints a new line after each iteratio...
[scilab.git] / scilab / modules / fileio / tests / unit_tests / mfprintf.tst
1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2015 - Scilab Enterprises - John GLIKSBERG
4 // Copyright (C) ????-2008 - INRIA
5 // Copyright (C) ????-2008 - ENPC
6 //
7 //  This file is distributed under the same license as the Scilab package.
8 // =============================================================================
9
10 // <-- CLI SHELL MODE -->
11
12 function [rep]=Fprintf(varargin)
13     fd = mopen(TMPDIR+"/fprintf.rep","w");
14     varargin(0)=fd;
15     mfprintf(varargin(:));
16     mclose(fd);
17     fd  = mopen(TMPDIR+"/fprintf.rep","r");
18     str = mgetl(fd);
19     mclose(fd);
20     rep = str;
21 endfunction
22
23 function [y]=bugnum(str1,str2,str3)
24     [lhs,rhs] = argn(0);
25     if rhs==3 then
26         y = or(str1<>str2) & or(str1<>str3);
27     else
28         y = or(str1<>str2);
29     end
30 endfunction
31
32 // test format "%f"
33 // =============================================================================
34
35 if bugnum(Fprintf("%f",-35),"-35.000000" ) then pause,end
36 if bugnum(Fprintf("%f",35.55),"35.550000" ) then pause,end
37 if bugnum(Fprintf("%f",0.00433),"0.004330" , " .004330" ) then pause,end
38 if bugnum(Fprintf("%f",0.0000000345456),"0.000000" , " .000000" ) then pause,end
39 if bugnum(Fprintf("%f",1112423453),"1112423453.000000" ) then pause,end
40
41 if bugnum(Fprintf("%15f",-35),"     -35.000000" ) then pause,end
42 if bugnum(Fprintf("%15f",0.00433),"       0.004330","        .004330" ) then pause,end
43 if bugnum(Fprintf("%15f",0.0000000345456),"       0.000000" ,"        .000000" ) then pause,end
44 if bugnum(Fprintf("%15f",1112423453),"1112423453.000000" ) then pause,end
45
46 if bugnum(Fprintf("%.1f",-35),"-35.0" ) then pause,end
47 if bugnum(Fprintf("%.0f",-35),"-35" ) then pause,end
48 if bugnum(Fprintf("%#.0f",-35),"-35." ) then pause,end
49 if bugnum(Fprintf("%.1f",0.00433),"0.0"," .0") then pause,end
50 if bugnum(Fprintf("%.15f",0.0000000345456),"0.000000034545600" ," .000000034545600" ) then pause,end
51 if bugnum(Fprintf("%.1f",11124234534545),"11124234534545.0" ) then pause,end
52
53 // test format "%g"
54 // =============================================================================
55
56 if bugnum(Fprintf("%g",-35),"-35" ) then pause,end
57 if bugnum(Fprintf("%g",35.55),"35.55" ) then pause,end
58 if bugnum(Fprintf("%g",35.551234567890),"35.5512" ) then pause,end
59 if bugnum(Fprintf("%+g",35.551234567890),"+35.5512" ) then pause,end
60 if bugnum(Fprintf("%g",0.00433),"0.00433" ," .00433" ) then pause,end
61 if bugnum(Fprintf("%g",0.0000000345456),"3.45456e-08","3.45456e-008" ) then pause,end
62 if bugnum(Fprintf("%g",11124234534545),"1.11242e+13","1.11242e+013" ) then pause,end
63
64 if bugnum(Fprintf("%15g",-35),"            -35" ) then pause,end
65 if bugnum(Fprintf("%15g",0.00433),"        0.00433","         .00433" ) then pause,end
66 if bugnum(Fprintf("%15g",0.0000000345456),"    3.45456e-08","   3.45456e-008" ) then pause,end
67 if bugnum(Fprintf("%15g",11124234534545),"    1.11242e+13","   1.11242e+013" ) then pause,end
68
69 if bugnum(Fprintf("%.1g",-35.1),"-4e+01","-4e+001" ) then pause,end
70 if bugnum(Fprintf("%.0g",-35.1),"-4e+01","-4e+001"  ) then pause,end
71 if bugnum(Fprintf("%#.0g",-35.1),"-4.e+01","-4.e+001" ) then pause,end
72 if bugnum(Fprintf("%#.0G",-35.1),"-4.E+01","-4.E+001" ) then pause,end
73 if bugnum(Fprintf("%.1g",0.00433),"0.004" ," .004" ) then pause,end
74 if bugnum(Fprintf("%.15g",0.0000000345456),"3.45456e-08","3.45456e-008" ) then pause,end
75 if bugnum(Fprintf("%.1g",11124234534545),"1e+13","1e+013" ) then pause,end
76
77 // test format "%e"
78 // =============================================================================
79
80 if bugnum(Fprintf("%e",-35),"-3.500000e+01","-3.500000e+001" ) then pause,end
81 if bugnum(Fprintf("%e",35.55),"3.555000e+01","3.555000e+001" ) then pause,end
82 if bugnum(Fprintf("%+e",35.55),"+3.555000e+01","+3.555000e+001" ) then pause,end
83 if bugnum(Fprintf("%e",35.551234567890),"3.555123e+01","3.555123e+001" ) then pause,end
84 if bugnum(Fprintf("%e",0.00433),"4.330000e-03","4.330000e-003" ) then pause,end
85 if bugnum(Fprintf("%e",0.0000000345456),"3.454560e-08","3.454560e-008" ) then pause,end
86 if bugnum(Fprintf("%e",11124234534545),"1.112423e+13","1.112423e+013" ) then pause,end
87 if bugnum(Fprintf("%E",11124234534545),"1.112423E+13","1.112423E+013" ) then pause,end
88
89 if bugnum(Fprintf("%15e",-35),"  -3.500000e+01"," -3.500000e+001" ) then pause,end
90 if bugnum(Fprintf("%15e",0.00433),"   4.330000e-03","  4.330000e-003" ) then pause,end
91 if bugnum(Fprintf("%15e",0.0000000345456),"   3.454560e-08","  3.454560e-008" ) then pause,end
92 if bugnum(Fprintf("%+15e",0.0000000345456),"  +3.454560e-08"," +3.454560e-008" ) then pause,end
93 if bugnum(Fprintf("%15e",11124234534545),"   1.112423e+13","  1.112423e+013" ) then pause,end
94
95 if bugnum(Fprintf("%.1e",-35),"-3.5e+01","-3.5e+001" ) then pause,end
96 if bugnum(Fprintf("%.0e",-35.1),"-4e+01" ,"-4e+001" ) then pause,end
97 if bugnum(Fprintf("%#.0e",-35.1),"-4.e+01","-4.e+001" ) then pause,end
98 if bugnum(Fprintf("%.1e",0.00433),"4.3e-03","4.3e-003" ) then pause,end
99 if bugnum(Fprintf("%.15e",0.0000000345456),"3.454560000000000e-08","3.454560000000000e-008" ) then pause,end
100 if bugnum(Fprintf("%.1e",11124234534545),"1.1e+13","1.1e+013" ) then pause,end
101
102 // test format "%c"
103 // =============================================================================
104
105 if bugnum(Fprintf("%c","t"),"t" ) then pause,end
106 if bugnum(Fprintf("%10c","t"),"         t" ) then pause,end
107 if bugnum(Fprintf("%10.3c","t"),"         t" ) then pause,end
108 if bugnum(Fprintf("%-10c","t"),"t         " ) then pause,end
109
110 // test format "%s"
111 // =============================================================================
112 if bugnum(Fprintf("%s","text"),"text" ) then pause,end
113 if bugnum(Fprintf("%10s","text"),"      text" ) then pause,end
114 if bugnum(Fprintf("%10.3s","text"),"       tex" ) then pause,end
115 if bugnum(Fprintf("%-10s","text"),"text      " ) then pause,end
116
117 if bugnum(Fprintf("%s","t"),"t" ) then pause,end
118
119 // test format "%x"
120 // =============================================================================
121 if bugnum(Fprintf("%x",123),"7b" ) then pause,end
122 if bugnum(Fprintf("%.10x",123),"000000007b" ) then pause,end
123 if bugnum(Fprintf("%x",-123),"ffffff85" ) then pause,end
124 if bugnum(Fprintf("%X",-123),"FFFFFF85" ) then pause,end
125 if bugnum(Fprintf("%#.3X",12),"0X00C" ) then pause,end
126
127 //----------test format %o
128 //if bugnum(Fprintf('%015o',-12),'000037777777764' ) then pause,end
129
130 //----------test column vector input
131 if bugnum(Fprintf("%s\n", ["a";"b"]), ["a";"b"]) then pause,end
132