Assert

Assert Commit Details

Date:2011-04-13 14:11:58 (7 years 3 months ago)
Author:Michael Baudin
Commit:122
Parents: 121
Message:Back-ported the localization changes from Scilab/master (error messages).
Changes:
M/help/en_US/support/assert_csvread.xml
M/help/en_US/update_help.sce
M/changelog.txt
M/macros/assert_generror.sci
M/macros/assert_checkalmostequal.sci
M/macros/assert_checkequal.sci
M/etc/assert.start
M/help/en_US/assert_checkerror.xml
M/macros/assert_cond2reltol.sci
M/macros/assert_checkfalse.sci
M/macros/assert_checkfilesequal.sci
M/macros/assert_checktrue.sci
M/macros/assert_comparecomplex.sci
M/macros/assert_computedigits.sci
M/macros/assert_cond2reqdigits.sci

File differences

macros/assert_cond2reltol.sci
9393
9494
9595
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
96
13197
13298
13399
......
142108
143109
144110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Michael Baudin, Digiteo, 2010
//
[lhs,rhs]=argn()
if ( and ( rhs <> [1 2] ) ) then
errmsg = sprintf ( gettext ( "%s: Unexpected number of input arguments : %d provided while %d to %d are expected.") , "assert_cond2reltol" , rhs , 1 , 2 )
error(errmsg)
end
//
// Get arguments
condition = varargin ( 1 )
offset = argindefault ( rhs , varargin , 2 , 0 )
//
// Check types of variables
if ( typeof(condition) <> "constant" ) then
errmsg = sprintf ( gettext ( "%s: Unexpected type of input argument #%d : variable %s has type %s while %s is expected.") , "assert_cond2reltol" , 1 , "condition" , typeof(condition) , "constant" )
error(errmsg)
end
if ( typeof(offset) <> "constant" ) then
errmsg = sprintf ( gettext ( "%s: Unexpected type of input argument #%d : variable %s has type %s while %s is expected.") , "assert_cond2reltol" , 2 , "offset" , typeof(offset) , "constant" )
error(errmsg)
end
//
// Check size of variables
// Let the user and assert_expandvar manage this.
//
// Check content of variables
if ( or ( condition < 0 ) ) then
errmsg = sprintf ( gettext ( "%s: Unexpected content of input argument #%d : variable %s has negative entries.") , "assert_cond2reltol" , 1 , "condition" )
error(errmsg)
end
//
[condition,offset] = assert_expandvar (condition,offset)
//
d = assert_cond2reqdigits ( condition , offset , 10 )
rtol = 10^-d
endfunction
function argin = argindefault ( rhs , vararglist , ivar , default )
function argin = argindefault ( rhs , vararglist , ivar , default )
// Returns the value of the input argument #ivar.
// If this argument was not provided, or was equal to the
// empty matrix, returns the default value.
end
endfunction
[lhs,rhs]=argn()
if ( and ( rhs <> [1 2] ) ) then
errmsg = sprintf ( gettext ( "%s: Wrong number of input arguments: %d to %d expected.") , "assert_cond2reltol" , 1 , 2 )
error(errmsg)
end
//
// Get arguments
condition = varargin ( 1 )
offset = argindefault ( rhs , varargin , 2 , 0 )
//
// Check types of variables
if ( typeof(condition) <> "constant" ) then
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix expected.\n") , "assert_cond2reltol" , 1 )
error(errmsg)
end
if ( typeof(offset) <> "constant" ) then
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix expected.\n") , "assert_cond2reltol" , 2 )
error(errmsg)
end
//
// Check size of variables
// Let the user and assert_expandvar manage this.
//
// Check content of variables
if ( or ( condition < 0 ) ) then
errmsg = sprintf ( gettext ( "%s: Wrong value for input argument #%d: Must be > %d.\n") , "assert_cond2reltol" , 1 , 0 )
error(errmsg)
end
//
[condition,offset] = assert_expandvar (condition,offset)
//
d = assert_cond2reqdigits ( condition , offset , 10 )
rtol = 10^-d
endfunction
macros/assert_checkfilesequal.sci
149149
150150
151151
152
152
153153
154154
155155
......
164164
165165
166166
167
167
168168
169169
170170
171
171
172172
173173
174174
......
180180
181181
182182
183
183
184184
185185
186186
187
187
188188
189189
190190
191191
192192
193193
194
194
195195
196196
197197
......
200200
201201
202202
203
203
204204
205205
206206
......
212212
213213
214214
215
215
216216
217217
218218
......
222222
223223
224224
225
225
226226
227227
228228
......
260260
261261
262262
263
263
264264
265265
266266
267267
268268
269269
270
270
271271
272272
273273
......
278278
279279
280280
281
[lhs,rhs]=argn()
if ( and ( rhs <> [ 2 3 ] ) ) then
errmsg = sprintf ( gettext ( "%s: Unexpected number of input arguments : %d provided while %d to %d are expected.") , "assert_checkfilesequal" , rhs , 2 , 3 )
errmsg = sprintf ( gettext ( "%s: Wrong number of input arguments: %d to %d expected.") , "assert_checkfilesequal" , 2 , 3 )
error(errmsg)
end
//
//
// Check types of variables
if ( typeof(filecomp) <> "string" ) then
errmsg = sprintf ( gettext ( "%s: Expected type ""%s"" for input argument %s #%d, but got %s instead.") , "assert_checkfilesequal" , "string" , "filecomp" , 1 , typeof(filecomp) )
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix of strings expected.\n") , "assert_checkfilesequal" , 1 )
error(errmsg)
end
if ( typeof(fileref) <> "string" ) then
errmsg = sprintf ( gettext ( "%s: Expected type ""%s"" for input argument %s #%d, but got %s instead.") , "assert_checkfilesequal" , "string" , "fileref" , 2 , typeof(fileref) )
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix of strings expected.\n") , "assert_checkfilesequal" , 2 )
error(errmsg)
end
if ( compfun <> [] ) then
//
// Check sizes of variables
if ( size(filecomp,"*") <> 1 ) then
errmsg = sprintf ( gettext ( "%s: Wrong size for input argument #%d: %s: Expected size %d, but got %d instead.") , "assert_checkfilesequal" , 1 , "filecomp" , 1 , size(filecomp,"*") )
errmsg = sprintf ( gettext ( "%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n") , "assert_checkfilesequal" , 1 , 1 , 1 )
error(errmsg)
end
if ( size(fileref,"*") <> 1 ) then
errmsg = sprintf ( gettext ( "%s: Wrong size for input argument #%d: %s: Expected size %d, but got %d instead.") , "assert_checkfilesequal" , 2 , "fileref" , 1 , size(fileref,"*") )
errmsg = sprintf ( gettext ( "%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n") , "assert_checkfilesequal" , 2 , 1 , 1 )
error(errmsg)
end
//
// Test if both files exist on disk
if ( fileinfo(filecomp) == [] ) then
flag = %f
errmsg = sprintf ( gettext ( "%s: Computed file ""%s"" does not exist on disk.") , "assert_checkfilesequal" , filecomp )
errmsg = sprintf ( gettext ( "%s: The file %s does not exist.\n") , "assert_checkfilesequal" , filecomp )
if ( lhs < 2 ) then
assert_generror ( errmsg )
else
end
if ( fileinfo(fileref) == [] ) then
flag = %f
errmsg = sprintf ( gettext ( "%s: Reference file ""%s"" does not exist on disk.") , "assert_checkfilesequal" , fileref )
errmsg = sprintf ( gettext ( "%s: The file %s does not exist.\n") , "assert_checkfilesequal" , fileref )
if ( lhs < 2 ) then
assert_generror ( errmsg )
else
[fdc,err] = mopen(filecomp,"r")
if ( err <> 0 ) then
flag = %f
errmsg = sprintf ( gettext ( "%s: Unable to open computed file ""%s"".") , "assert_checkfilesequal" , filecomp )
errmsg = sprintf ( gettext ( "%s: Cannot open file %s.\n") , "assert_checkfilesequal" , filecomp )
if ( lhs < 2 ) then
assert_generror ( errmsg )
else
[fdr,err] = mopen(fileref,"r")
if ( err <> 0 ) then
flag = %f
errmsg = sprintf ( gettext ( "%s: Unable to open reference file ""%s"".") , "assert_checkfilesequal" , fileref )
errmsg = sprintf ( gettext ( "%s: Cannot open file %s.\n") , "assert_checkfilesequal" , fileref )
if ( lhs < 2 ) then
assert_generror ( errmsg )
else
err=mclose(fdc)
if ( err <> 0 ) then
flag = %f
errmsg = sprintf ( gettext ( "%s: Unable to close computed file ""%s"": error = %d.") , "assert_checkfilesequal" , filecomp , err )
errmsg = sprintf ( gettext ( "%s: Cannot close file %s.\n") , "assert_checkfilesequal" , filecomp )
// It may happen that we overwrite the content of the errmsg varaiable.
// For example, we are there, while the file contents were different.
// We consider that that not being able to close the file is a bigger issue,
end
err=mclose(fdr)
if ( err <> 0 ) then
errmsg = sprintf ( gettext ( "%s: Unable to close reference file ""%s"": error = %d.") , "assert_checkfilesequal" , fileref , err )
errmsg = sprintf ( gettext ( "%s: Cannot close file %s.\n") , "assert_checkfilesequal" , fileref )
// It may happen that we overwrite the content of the errmsg varaiable.
// For example, we are there, while the file contents were different.
// We consider that that not being able to close the file is a bigger issue,
assert_generror ( errmsg )
end
endfunction
macros/assert_checkfalse.sci
5454
5555
5656
57
57
5858
5959
6060
6161
6262
63
63
6464
6565
6666
......
8282
8383
8484
85
[lhs,rhs]=argn()
if ( rhs <> 1 ) then
errmsg = sprintf ( gettext ( "%s: Unexpected number of input arguments : %d provided while %d are expected.") , "assert_checkfalse" , rhs , 1 )
errmsg = sprintf ( gettext ( "%s: Wrong number of input arguments: %d expected.\n") , "assert_checkfalse" , 1 )
error(errmsg)
end
//
// Check types of variables
if ( typeof(condition) <> "boolean" ) then
errmsg = sprintf ( gettext ( "%s: Expected boolean variable, but got %s instead.") , "assert_checkfalse" , typeof(condition) )
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Boolean matrix expected.\n") , "assert_checkfalse" , 1 )
error(errmsg)
end
//
end
end
endfunction
macros/assert_checkequal.sci
7171
7272
7373
74
74
7575
7676
7777
......
9292
9393
9494
95
95
9696
9797
9898
9999
100100
101
101
102102
103103
104104
......
106106
107107
108108
109
110
111
109
112110
113111
114112
......
156154
157155
158156
159
160
161
157
162158
163159
164160
......
166162
167163
168164
169
//
//
// Copyright (C) 2000 - INRIA - Carlos Klimann
// Copyright (C) 2010 - DIGITEO - Michael Baudin
// Copyright (C) 2010 - 2011 - DIGITEO - Michael Baudin
//This function returns in vector nonan the values
//(ignoring the NANs) of a vector or matrix x and in the
//corresponding places of vector numb the indexes of the
[lhs,rhs]=argn()
if ( rhs <> 2 ) then
errmsg = sprintf ( gettext ( "%s: Unexpected number of input arguments : %d provided while %d are expected.") , "assert_checkequal" , rhs , 2 )
errmsg = sprintf ( gettext ( "%s: Wrong number of input arguments: %d expected.\n") , "assert_checkequal" , 2 )
error(errmsg)
end
//
// Check types of variables
if ( typeof(computed) <> typeof(expected) ) then
errmsg = sprintf ( gettext ( "%s: Variable typeof(computed) = %s while typeof(expected) = %s: inconsistent match.") , "assert_checkequal" , typeof(computed) , typeof(expected) )
errmsg = sprintf ( gettext ( "%s: Incompatible input arguments #%d and #%d: Same types expected.\n" ) , "assert_checkequal" , 1 , 2 )
error(errmsg)
end
//
ncom = size(computed)
nexp = size(expected)
if ( or(ncom <> nexp) ) then
cstr = "[" + strcat(string(ncom)," ") + "]"
estr = "[" + strcat(string(nexp)," ") + "]"
errmsg = sprintf ( gettext ( "%s: We have size(computed) = %s while size(expected) = %s: not consistent comparison.") , "assert_checkequal" , cstr , estr )
errmsg = sprintf ( gettext ( "%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n") , "assert_checkequal" , 1 , 2 )
error(errmsg)
end
//
else
cstr = "[" + string(computed(1)) + " ...]"
end
errmsg = msprintf(gettext(..
"%s: Assertion failed: expected = %s while computed = %s"), ..
"assert_checkequal",estr,cstr)
errmsg = msprintf(gettext("%s: Assertion failed: expected = %s while computed = %s"),"assert_checkequal",estr,cstr)
if ( lhs < 2 ) then
// If no output variable is given, generate an error
assert_generror ( errmsg )
end
endfunction
macros/assert_checktrue.sci
5454
5555
5656
57
57
5858
5959
6060
6161
6262
63
63
6464
6565
6666
......
8282
8383
8484
85
[lhs,rhs]=argn()
if ( rhs <> 1 ) then
errmsg = sprintf ( gettext ( "%s: Unexpected number of input arguments : %d provided while %d are expected.") , "assert_checktrue" , rhs , 1 )
errmsg = sprintf ( gettext ( "%s: Wrong number of input arguments: %d expected.\n") , "assert_checktrue" , 1 )
error(errmsg)
end
//
// Check types of variables
if ( typeof(condition) <> "boolean" ) then
errmsg = sprintf ( gettext ( "%s: Expected boolean variable, but got %s instead.") , "assert_checktrue" , typeof(condition) )
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Boolean matrix expected.\n" ) , "assert_checktrue" , 1 )
error(errmsg)
end
//
end
end
endfunction
macros/assert_comparecomplex.sci
118118
119119
120120
121
121
122122
123123
124124
......
130130
131131
132132
133
133
134134
135135
136136
137
137
138138
139139
140140
141
141
142142
143143
144144
145
145
146146
147147
148148
149149
150150
151
151
152152
153153
154154
155
155
156156
157157
158158
159
159
160160
161161
162162
163
163
164164
165165
166166
167167
168168
169
169
170170
171171
172172
173
173
174174
175175
176176
......
249249
250250
251251
252
[lhs,rhs]=argn()
if ( and(rhs <> [2 3 4] ) ) then
errmsg = sprintf ( gettext ( "%s: Unexpected number of input arguments : %d provided while %d to %d are expected.") , "assert_comparecomplex" , rhs , 2 , 4 )
errmsg = sprintf ( gettext ( "%s: Wrong number of input arguments: %d to %d expected.") , "assert_comparecomplex" , 2 , 4 )
error(errmsg)
end
//
//
// Check types of variables
if ( typeof(a) <> "constant" ) then
errmsg = sprintf ( gettext ( "%s: Unexpected type of input argument #%d : variable %s has type %s while %s is expected.") , "assert_comparecomplex" , 1 , "a" , typeof(a) , "constant" )
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix expected.\n") , "assert_comparecomplex" , 1 )
error(errmsg)
end
if ( typeof(a) <> "constant" ) then
errmsg = sprintf ( gettext ( "%s: Unexpected type of input argument #%d : variable %s has type %s while %s is expected.") , "assert_comparecomplex" , 2 , "b" , typeof(b) , "constant" )
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix expected.\n") , "assert_comparecomplex" , 2 )
error(errmsg)
end
if ( typeof(reltol) <> "constant" ) then
errmsg = sprintf ( gettext ( "%s: Unexpected type of input argument #%d : variable %s has type %s while %s is expected.") , "assert_comparecomplex" , 3 , "reltol" , typeof(reltol) , "constant" )
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix expected.\n") , "assert_comparecomplex" , 3 )
error(errmsg)
end
if ( typeof(abstol) <> "constant" ) then
errmsg = sprintf ( gettext ( "%s: Unexpected type of input argument #%d : variable %s has type %s while %s is expected.") , "assert_comparecomplex" , 4 , "abstol" , typeof(abstol) , "constant" )
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix expected.\n") , "assert_comparecomplex" , 4 )
error(errmsg)
end
//
// Check sizes of variables
if ( size(a,"*") <> 1 ) then
errmsg = sprintf ( gettext ( "%s: Unexpected size of input argument #%d : variable %s has size %d while %d is expected.") , "assert_comparecomplex" , 1 , "a" , size(a,"*") , 1 )
errmsg = sprintf ( gettext ( "%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n") , "assert_comparecomplex" , 1 , 1 , 1 )
error(errmsg)
end
if ( size(b,"*") <> 1 ) then
errmsg = sprintf ( gettext ( "%s: Unexpected size of input argument #%d : variable %s has size %d while %d is expected.") , "assert_comparecomplex" , 2 , "b" , size(b,"*") , 1 )
errmsg = sprintf ( gettext ( "%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n") , "assert_comparecomplex" , 2 , 1 , 1 )
error(errmsg)
end
if ( size(reltol,"*") <> 1 ) then
errmsg = sprintf ( gettext ( "%s: Unexpected size of input argument #%d : variable %s has size %d while %d is expected.") , "assert_comparecomplex" , 3 , "reltol" , size(reltol,"*") , 1 )
errmsg = sprintf ( gettext ( "%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n") , "assert_comparecomplex" , 3 , 1 , 1 )
error(errmsg)
end
if ( size(abstol,"*") <> 1 ) then
errmsg = sprintf ( gettext ( "%s: Unexpected size of input argument #%d : variable %s has size %d while %d is expected.") , "assert_comparecomplex" , 4 , "abstol" , size(abstol,"*") , 1 )
errmsg = sprintf ( gettext ( "%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n") , "assert_comparecomplex" , 4 , 1 , 1 )
error(errmsg)
end
//
// Check values of variables
if ( reltol < 0 ) then
errmsg = sprintf ( gettext ( "%s: Unexpected value input argument #%d : variable %s has negative entries.") , "assert_comparecomplex" , 3 , "reltol" )
errmsg = sprintf ( gettext ( "%s: Wrong value for input argument #%d: Must be > %d.\n") , "assert_comparecomplex" , 3 , 0 )
error(errmsg)
end
if ( abstol < 0 ) then
errmsg = sprintf ( gettext ( "%s: Unexpected value input argument #%d : variable %s has negative entries.") , "assert_comparecomplex" , 4 , "abstol" )
errmsg = sprintf ( gettext ( "%s: Wrong value for input argument #%d: Must be > %d.\n") , "assert_comparecomplex" , 4 , 0 )
error(errmsg)
end
//
end
end
endfunction
macros/assert_computedigits.sci
9191
9292
9393
94
94
9595
9696
9797
......
100100
101101
102102
103
103
104104
105105
106106
107
107
108108
109109
110110
111111
112112
113
113
114114
115115
116116
117
117
118118
119119
120120
......
190190
191191
192192
193
[lhs,rhs]=argn()
if ( and ( rhs <> [2 3] ) ) then
errmsg = sprintf ( gettext ( "%s: Unexpected number of input arguments : %d provided while from %d to %d are expected.") , "assert_computedigits" , rhs , 2 , 3 )
errmsg = sprintf ( gettext ( "%s: Wrong number of input arguments: %d to %d expected.\n") , "assert_computedigits" , 2 , 3 )
error(errmsg)
end
computed = varargin ( 1 )
//
// Check types of variables
if ( typeof(computed) <> "constant" ) then
errmsg = sprintf ( gettext ( "%s: Unexpected type of input argument #%d : variable %s has type %s while %s is expected.") , "assert_computedigits" , 1 , "computed" , typeof(computed) , "constant" )
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix expected.\n") , "assert_computedigits" , 1 )
error(errmsg)
end
if ( typeof(expected) <> "constant" ) then
errmsg = sprintf ( gettext ( "%s: Unexpected type of input argument #%d : variable %s has type %s while %s is expected.") , "assert_computedigits" , 2 , "expected" , typeof(expected) , "constant" )
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix expected.\n") , "assert_computedigits" , 2 )
error(errmsg)
end
//
// Check sizes of variables
if ( size(expected) <> size(computed) ) then
errmsg = sprintf ( gettext ( "%s: The size of computed is [%d,%d] while the size of expected is [%d,%d].") , "assert_computedigits" , size(expected,"r") , size(expected,"c") , size(computed,"r") , size(computed,"c") )
errmsg = sprintf ( gettext ( "%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n") , "assert_computedigits" , 1 , 2 )
error(errmsg)
end
if ( size(basis,"*") <> 1 ) then
errmsg = sprintf ( gettext ( "%s: Unexpected size of input argument #%d : variable %s has size %d while %d is expected.") , "assert_condnum" , 3 , "basis" , size(basis,"*") , 1 )
errmsg = sprintf ( gettext ( "%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n") , "assert_computedigits" , 3 , 1 , 1 )
error(errmsg)
end
//
end
end
endfunction
macros/assert_cond2reqdigits.sci
120120
121121
122122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
123
173124
174125
175126
......
184135
185136
186137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Michael Baudin, Digiteo, 2010
//
[lhs,rhs]=argn()
if ( and ( rhs <> [1 2 3] ) ) then
errmsg = sprintf ( gettext ( "%s: Unexpected number of input arguments : %d provided while %d to %d are expected.") , "assert_cond2reqdigits" , rhs , 1 , 3 )
error(errmsg)
end
//
// Get arguments
condition = varargin ( 1 )
offset = argindefault ( rhs , varargin , 2 , 0 )
b = argindefault ( rhs , varargin , 3 , 10 )
//
// Check types of variables
if ( typeof(condition) <> "constant" ) then
errmsg = sprintf ( gettext ( "%s: Unexpected type of input argument #%d : variable %s has type %s while %s is expected.") , "assert_cond2reqdigits" , 1 , "condition" , typeof(condition) , "constant" )
error(errmsg)
end
if ( typeof(offset) <> "constant" ) then
errmsg = sprintf ( gettext ( "%s: Unexpected type of input argument #%d : variable %s has type %s while %s is expected.") , "assert_cond2reqdigits" , 2 , "offset" , typeof(offset) , "constant" )
error(errmsg)
end
if ( typeof(b) <> "constant" ) then
errmsg = sprintf ( gettext ( "%s: Unexpected type of input argument #%d : variable %s has type %s while %s is expected.") , "assert_cond2reqdigits" , 3 , "b" , typeof(offset) , "constant" )
error(errmsg)
end
//
// Check size of variables
// Let the user and assert_expandvar manage this.
//
// Check content of variables
if ( or ( condition < 0 ) ) then
errmsg = sprintf ( gettext ( "%s: Unexpected content of input argument #%d : variable %s has negative entries.") , "assert_cond2reqdigits" , 1 , "condition" )
error(errmsg)
end
if ( or ( b < 2 ) ) then
errmsg = sprintf ( gettext ( "%s: Unexpected content of input argument #%d : variable %s has entries lower than %d.") , "assert_cond2reqdigits" , 3 , "b" , 2 )
error(errmsg)
end
//
[condition,offset] = assert_expandvar (condition,offset)
//
backIEEE=ieee()
ieee(2)
//
dmax = -log(2^(-53))/log(b)
lost = min(max(log(condition)/log(b)-offset,0),dmax)
d = dmax - lost
//
ieee(backIEEE)
endfunction
function argin = argindefault ( rhs , vararglist , ivar , default )
function argin = argindefault ( rhs , vararglist , ivar , default )
// Returns the value of the input argument #ivar.
// If this argument was not provided, or was equal to the
// empty matrix, returns the default value.
end
endfunction
[lhs,rhs]=argn()
if ( and ( rhs <> [1 2 3] ) ) then
errmsg = sprintf ( gettext ( "%s: Wrong number of input arguments: %d to %d expected.") , "assert_cond2reqdigits" , 1 , 3 )
error(errmsg)
end
//
// Get arguments
condition = varargin ( 1 )
offset = argindefault ( rhs , varargin , 2 , 0 )
b = argindefault ( rhs , varargin , 3 , 10 )
//
// Check types of variables
if ( typeof(condition) <> "constant" ) then
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix expected.\n") , "assert_cond2reqdigits" , 1 )
error(errmsg)
end
if ( typeof(offset) <> "constant" ) then
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix expected.\n") , "assert_cond2reqdigits" , 2 )
error(errmsg)
end
if ( typeof(b) <> "constant" ) then
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix expected.\n") , "assert_cond2reqdigits" , 3 )
error(errmsg)
end
//
// Check size of variables
// Let the user and assert_expandvar manage this.
//
// Check content of variables
if ( or ( condition < 0 ) ) then
errmsg = sprintf ( gettext ( "%s: Wrong value for input argument #%d: Must be > %d.\n") , "assert_cond2reqdigits" , 1 , 0 )
error(errmsg)
end
if ( or ( b < 2 ) ) then
errmsg = sprintf ( gettext ("%s: Wrong value for input argument #%d: Must be > %d.\n") , "assert_cond2reqdigits" , 3 , 2 )
error(errmsg)
end
//
[condition,offset] = assert_expandvar (condition,offset)
//
backIEEE=ieee()
ieee(2)
//
dmax = -log(2^(-53))/log(b)
lost = min(max(log(condition)/log(b)-offset,0),dmax)
d = dmax - lost
//
ieee(backIEEE)
endfunction
macros/assert_generror.sci
6868
6969
7070
71
71
7272
7373
7474
7575
7676
7777
78
78
7979
8080
8181
82
82
8383
8484
8585
......
8888
8989
9090
91
91
9292
9393
9494
95
95
9696
9797
9898
99
99
100100
101101
102102
103103
104104
105
[lhs,rhs]=argn()
if ( and(rhs <> [1 2] ) ) then
errmsg = sprintf ( gettext ( "%s: Unexpected number of input arguments : %d provided while %d to %d are expected.") , "assert_generror" , rhs , 1 , 2 )
errmsg = sprintf ( gettext ( "%s: Wrong number of input arguments: %d to %d expected.") , "assert_generror" , 1 , 2 )
error(errmsg)
end
errormsg = varargin(1)
//
// Check types of variables
if ( typeof(errormsg) <> "string" ) then
errmsg = sprintf ( gettext ( "%s: Unexpected type of input argument #%d : variable %s has type %s while %s is expected.") , "assert_generror" , 1 , "errormsg" , typeof(errormsg) , "string" )
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix of strings expected.\n") , "assert_generror" , 1 )
error(errmsg)
end
if ( size(errormsg,"*") <> 1 ) then
errmsg = sprintf ( gettext ( "%s: Unexpected size of input argument #%d : variable %s has size %d while %d is expected.") , "assert_generror" , 1 , "errormsg" , size(errormsg,"*") , 1 )
errmsg = sprintf ( gettext ( "%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n") , "assert_generror" , 1 , 1 , 1 )
error(errmsg)
end
//
else
errornb = varargin(2)
if ( size(errornb,"*") <> 1 ) then
errmsg = sprintf ( gettext ( "%s: Unexpected size of input argument #%d : variable %s has size %d while %d is expected.") , "assert_generror" , 2 , "errornb" , size(errornb,"*") , 1 )
errmsg = sprintf ( gettext ( "%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n") , "assert_generror" , 2 , 1 , 1 )
error(errmsg)
end
if ( typeof(errornb) <> "constant" ) then
errmsg = sprintf ( gettext ( "%s: Unexpected type of input argument #%d : variable %s has type %s while %s is expected.") , "assert_generror" , 2 , "errornb" , typeof(errornb) , "constant" )
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix expected.\n") , "assert_generror" , 2 )
error(errmsg)
end
if ( errornb < 0 ) then
errmsg = sprintf ( gettext ( "%s: Unexpected value input argument #%d : variable %s has negative entries.") , "assert_generror" , 2 , "errornb" )
errmsg = sprintf ( gettext ( "%s: Wrong value for input argument #%d: Non-negative integers expected.\n" ) , "assert_generror" , 2 )
error(errmsg)
end
error ( errormsg , errornb )
end
endfunction
macros/assert_checkalmostequal.sci
183183
184184
185185
186
186
187187
188188
189189
......
196196
197197
198198
199
199
200200
201201
202202
203
203
204204
205205
206206
207
207
208208
209209
210210
211
211
212212
213213
214214
215
215
216216
217217
218218
219219
220220
221
221
222222
223223
224224
225
225
226226
227227
228228
229
229
230230
231231
232232
233233
234234
235
235
236236
237237
238238
239
239
240240
241241
242242
243
243
244244
245245
246246
......
248248
249249
250250
251
252
253
251
254252
255253
256254
......
279277
280278
281279
282
283
280
284281
285282
286283
......
349346
350347
351348
352
[lhs,rhs]=argn()
if ( and(rhs <> [2 3 4 5] ) ) then
errmsg = sprintf ( gettext ( "%s: Unexpected number of input arguments : %d provided while %d to %d are expected.") , "assert_checkalmostequal" , rhs , 2 , 5 )
errmsg = sprintf ( gettext ( "%s: Wrong number of input arguments: %d to %d expected.") , "assert_checkalmostequal" , 2 , 5 )
error(errmsg)
end
//
//
// Check types of variables
if ( typeof(computed) <> "constant" ) then
errmsg = sprintf ( gettext ( "%s: Unexpected type of input argument #%d : variable %s has type %s while %s is expected.") , "assert_checkalmostequal" , 1 , "computed" , typeof(computed) , "constant" )
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix expected.\n") , "assert_checkalmostequal" , 1 )
error(errmsg)
end
if ( typeof(expected) <> "constant" ) then
errmsg = sprintf ( gettext ( "%s: Unexpected type of input argument #%d : variable %s has type %s while %s is expected.") , "assert_checkalmostequal" , 2 , "expected" , typeof(expected) , "constant" )
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix expected.\n") , "assert_checkalmostequal" , 2 )
error(errmsg)
end
if ( typeof(reltol) <> "constant" ) then
errmsg = sprintf ( gettext ( "%s: Unexpected type of input argument #%d : variable %s has type %s while %s is expected.") , "assert_checkalmostequal" , 3 , "reltol" , typeof(reltol) , "constant" )
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix expected.\n") , "assert_checkalmostequal" , 3 )
error(errmsg)
end
if ( typeof(abstol) <> "constant" ) then
errmsg = sprintf ( gettext ( "%s: Unexpected type of input argument #%d : variable %s has type %s while %s is expected.") , "assert_checkalmostequal" , 4 , "abstol" , typeof(abstol) , "constant" )
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix expected.\n") , "assert_checkalmostequal" , 4 )
error(errmsg)
end
if ( typeof(comptype) <> "string" ) then
errmsg = sprintf ( gettext ( "%s: Unexpected type of input argument #%d : variable %s has type %s while %s is expected.") , "assert_checkalmostequal" , 5 , "comptype" , typeof(comptype) , "string" )
errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix of strings expected.\n") , "assert_checkalmostequal" , 5 )
error(errmsg)
end
//
// Check sizes of variables
if ( size(reltol,"*") <> 1 ) then
errmsg = sprintf ( gettext ( "%s: Unexpected size of input argument #%d : variable %s has size %d while %d is expected.") , "assert_checkalmostequal" , 3 , "reltol" , size(reltol,"*") , 1 )
errmsg = sprintf ( gettext ( "%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n") , "assert_checkalmostequal" , 3 , 1 , 1 )
error(errmsg)
end
if ( size(abstol,"*") <> 1 ) then
errmsg = sprintf ( gettext ( "%s: Unexpected size of input argument #%d : variable %s has size %d while %d is expected.") , "assert_checkalmostequal" , 4 , "abstol" , size(abstol,"*") , 1 )
errmsg = sprintf ( gettext ( "%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n") , "assert_checkalmostequal" , 4 , 1 , 1 )
error(errmsg)
end
if ( size(comptype,"*") <> 1 ) then
errmsg = sprintf ( gettext ( "%s: Unexpected size of input argument #%d : variable %s has size %d while %d is expected.") , "assert_checkalmostequal" , 5 , "comptype" , size(comptype,"*") , 1 )
errmsg = sprintf ( gettext ( "%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n") , "assert_checkalmostequal" , 5 , 1 , 1 )
error(errmsg)
end
//
// Check values of variables
if ( reltol < 0 ) then
errmsg = sprintf ( gettext ( "%s: Unexpected value input argument #%d : variable %s has negative entries.") , "assert_checkalmostequal" , 3 , "reltol" )
errmsg = sprintf ( gettext ( "%s: Wrong value for input argument #%d: Must be > %d.\n") , "assert_checkalmostequal" , 3 , 0 )
error(errmsg)
end
if ( abstol < 0 ) then
errmsg = sprintf ( gettext ( "%s: Unexpected value input argument #%d : variable %s has negative entries.") , "assert_checkalmostequal" , 4 , "abstol" )
errmsg = sprintf ( gettext ( "%s: Wrong value for input argument #%d: Must be > %d.\n") , "assert_checkalmostequal" , 4 , 0 )
error(errmsg)
end
if ( and ( comptype <> ["matrix" "element"] ) ) then
errmsg = sprintf ( gettext ( "%s: Unexpected value input argument #%d : variable %s has value %s.") , "assert_checkalmostequal" , 5 , "comptype" , comptype )
errmsg = sprintf ( gettext ( "%s: Wrong value for input argument #%d: Must be in the set {%s}.\n") , "assert_checkalmostequal" , 5 , """matrix"",""element""" )
error(errmsg)
end
//
ncom = size(computed)
nexp = size(expected)
if ( or(ncom <> nexp) ) then
cstr = "[" + strcat(string(ncom)," ") + "]"
estr = "[" + strcat(string(nexp)," ") + "]"
errmsg = sprintf ( gettext ( "%s: We have size(computed) = %s while size(expected) = %s: not consistent comparison.") , "assert_checkalmostequal" , cstr , estr )
errmsg = sprintf ( gettext ( "%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n" ) , "assert_checkalmostequal" , 1 , 2 )
error(errmsg)
end
//
end
relstr = string(reltol)
absstr = string(abstol)
errmsg = msprintf(gettext("%s: Assertion failed: expected = %s while computed = %s with reltol=%s, abstol=%s"), ..
"assert_checkalmostequal",estr,cstr,relstr,absstr)
errmsg = msprintf(gettext("%s: Assertion failed: expected = %s while computed = %s"),"assert_checkalmostequal",estr,cstr)
if ( lhs < 2 ) then
// If no output variable is given, generate an error
assert_generror ( errmsg )
end
end
endfunction
changelog.txt
33
44
55
6
7
8
69
710
8
11
12
913
1014
1115
assert (not released yet)
* Fixed ticket #349: The assert_checkequal function did
not manage complex doubles.
* Back-ported the changes from Scilab/master/assert_checkerror.
* Removed automatically generated demos.
* Back-ported the localization changes from Scilab/master (error messages).
assert (1.2)
* Fixed check equal on empty matrix [] - Ticket #193 : http://forge.scilab.org/index.php/p/assert/issues/193/
* Fixed check equal on empty matrix []
Ticket #193 : http://forge.scilab.org/index.php/p/assert/issues/193/
* In assert_csvread, added example of block-by-block read.
assert (1.1)
help/en_US/support/assert_csvread.xml
11
22
33
4
4
55
6
6
77
88
99
......
3232
3333
3434
35
3536
3637
3738
<?xml version="1.0" encoding="UTF-8"?>
<!--
*
*
* This help file was generated from assert_csvread.sci using help_from_sci().
*
*
-->
<refentry version="5.0-subset Scilab" xml:id="assert_csvread" xml:lang="en"
A = assert_csvread ( srcstring , sep , dec , comm , srctype , replacemap )
A = assert_csvread ( srcstring , sep , dec , comm , srctype , replacemap , output )
A = assert_csvread ( srcstring , sep , dec , comm , srctype , replacemap , output , irange )
</synopsis>
</refsynopsisdiv>
help/en_US/update_help.sce
99
1010
1111
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
21912
22013
22114
......
23326
23427
23528
236
29
23730
238
31
23932
24033
24134
......
24841
24942
25043
251
44
25245
253
46
25447
25548
25649
......
26457
26558
26659
267
60
26861
269
62
27063
// Updates the .xml files by deleting existing files and
// creating them again from the .sci with help_from_sci.
function b = isContentUptodate ( content , filename )
// Check if a content matches a file.
//
// Calling Sequence
// b = isContentUptodate ( content , filename )
//
// Parameters
// content : a 1x1 matrix of strings, the new content
// filename : a 1x1 matrix of strings, the file to be checked.
// b : a 1x1 matrix of booleans
//
// Description
// Returns true if the <literal>filename</literal> is up-to-date, that is,
// if the file does not require to be changed.
// The file is to be updated if one of the following conditions is satisfied.
// <itemizedlist>
// <listitem>
// The file does not exist.
// </listitem>
// <listitem>
// The file exists, but its content is not equal to <literal>content</literal>.
// The content comparison ignores the leading and trailing blanks.
// </listitem>
// </itemizedlist>
// Last update : 02/09/2010.
//
// Example
// // TODO...
//
// Author
// 2010 - DIGITEO - Michael Baudin
//
b = %t
if ( fileinfo(filename) == [] ) then
b = %f
else
txt = mgetl(filename)
if ( or ( stripblanks(content) <> stripblanks(txt) ) ) then
b = %f
end
end
endfunction
function b = fileUpdateIfNeeded ( content , filename )
// Update a file if this is needed.
//
// Calling Sequence
// b = fileUpdateIfNeeded ( content , filename )
//
// Parameters
// content : a 1x1 matrix of strings, the new content
// filename : a 1x1 matrix of strings, the file to be checked.
// b : a 1x1 matrix of booleans
//
// Description
// Returns true if the <literal>filename</literal> is up-to-date, that is,
// if the file was not changed.
// Returns false if the file was changed.
// The file is to be updated according to the rules of <literal>isContentUptodate</literal>.
// Generates an error if the file was to be changed, but that was not possible.
// Last update : 02/09/2010.
//
// Example
// // TODO...
//
// Author
// 2010 - DIGITEO - Michael Baudin
//
b = isContentUptodate ( content , filename )
if ( ~b ) then
r = mputl ( content , filename )
if ( ~r ) then
error(sprintf(gettext("%s: Unable to write xml file: %s\n"),"fileUpdateIfNeeded",filename));
end
end
endfunction
function helpupdate ( funarray , helpdir , macrosdir , demosdir , modulename , verbose )
// Update the help and the demos from the .sci files.
//
// Calling Sequence
// updatehelp ( funarray , helpdir , macrosdir , demosdir , modulename , verbose )
//
// Parameters
// funarray : column matrix of strings. The list of functions to update
// helpdir : the help directory
// macrosdir : the macros directory
// demosdir : the demonstration directory
// modulename: a 1x1 matrix of strings, the name of the module to update
// verbose: a 1x1 matrix of booleans, verbose = %t prints messages
// modulename : the name of the module
//
// Description
// Update the .xml help files and the demos scripts
// from the macros corresponding to the function array
// of strings funarray.
// The existing .xml files in the help dir which
// correspond to file in the funarray are deleted (Caution !).
// Generates the .xml and the .sce files from the help_from_sci function.
// Generates a demonstration gateway.
//
// If demosdir is an empty matrix, do not generate the demonstrations.
// Last update : 04/10/2010.
//
// Author
// 2010, Michael Baudin
if ( fileinfo ( helpdir ) == [] ) then
error(sprintf(gettext("%s: Wrong help directory: %s does not exist.\n"),"updatehelp",helpdir));
end
if ( fileinfo ( macrosdir ) == [] ) then
error(sprintf(gettext("%s: Wrong macros directory: %s does not exist.\n"),"updatehelp",macrosdir));
end
if ( demosdir <> [] ) then
if ( fileinfo ( demosdir ) == [] ) then
error(sprintf(gettext("%s: Wrong demos directory: %s does not exist.\n"),"updatehelp",demosdir));
end
end
//
// 2. Generate each .xml and each .sce from the .sci
flist = ls(macrosdir)';
for f = flist
issci = regexp(f,"/(.*).sci/");
kf = find(funarray==basename(f))
if ( issci <> [] & kf <> [] ) then
scifile = fullfile ( macrosdir , f )
if ( verbose ) then
mprintf("Processing %s\n",scifile);
end
funname = funarray(kf)
xmlfile = fullfile ( helpdir , funname + ".xml" )
// Generate the xml and the demo content
[helptxt,demotxt]= help_from_sci (scifile)
// Delete the "info" tag, containing the date (3 lines)
k = find(stripblanks(helptxt)=="<info>")
helptxt(k:k+2) = []
// Update the xml file, if necessary
isuptodate = fileUpdateIfNeeded ( helptxt , xmlfile )
if ( ~isuptodate & verbose ) then
changetxt = "XML Changed"
mprintf(" %s %s\n",changetxt,xmlfile);
end
// Create the demo
if ( demosdir <> [] ) then
demofile = fullfile ( demosdir , funname + ".sce" )
// Update the demo script
header = []
header($+1) = "//"
header($+1) = "// This help file was automatically generated from "+funname+".sci using help_from_sci()."
header($+1) = "// PLEASE DO NOT EDIT"
header($+1) = "//"
footer = []
footer($+1) = msprintf("//\n");
footer($+1) = msprintf("// Load this script into the editor\n");
footer($+1) = msprintf("//\n");
footer($+1) = msprintf("filename = ""%s"";\n",funname + ".sce");
footer($+1) = msprintf("dname = get_absolute_file_path(filename);\n");
footer($+1) = msprintf("editor ( fullfile(dname,filename) );\n");
demotxt = [header;demotxt;footer]
// Update the demo file, if necessary
isuptodate = fileUpdateIfNeeded ( demotxt , demofile )
if ( ~isuptodate & verbose ) then
changetxt = "SCE Changed"
mprintf(" %s %s\n",changetxt,demofile);
end
end
end
end
//
// 3. Generates the Demonstration gateway
// Include all .sce files in the gateway, including
// handcrafted scripts which might have been written
// by the user (and not generated by this function).
// To make so, use the list of .sce files in the demo dir and
/// not simply the funarray.
if ( demosdir <> [] ) then
gatetxt = []
gatetxt ($+1) = "// This help file was automatically generated using helpupdate"
gatetxt ($+1) = "// PLEASE DO NOT EDIT"
gatetxt ($+1) = "demopath = get_absolute_file_path(""" + modulename + ".dem.gateway.sce"");"
gatetxt ($+1) = "subdemolist = ["
flist = ls(demosdir)';
for f = flist
issce = regexp(f,"/(.*).sce/");
isgateway = regexp(f,"/(.*).gateway.sce/");
if ( issce <> [] & isgateway == [] ) then
flen = length(f)
funname = part(f,[1:flen-4])
gatetxt($+1) = """" + funname + """, """ + funname + ".sce""; .."
end
end
//
gatetxt ($+1) = "];"
gatetxt ($+1) = "subdemolist(:,2) = demopath + subdemolist(:,2)"
gatefile = fullfile ( demosdir , modulename+".dem.gateway.sce" )
// Update the gateway file, if necessary
isuptodate = fileUpdateIfNeeded ( gatetxt , gatefile )
if ( ~isuptodate & verbose ) then
changetxt = "SCE Gateway Changed"
mprintf("%s %s\n",changetxt,gatefile);
end
end
endfunction
//
cwd = get_absolute_file_path("update_help.sce");
mprintf("Working dir = %s\n",cwd);
"assert_generror"
];
macrosdir = cwd +"../../macros";
demosdir = cwd +"../../demos";
demosdir = [];
modulename = "assert";
helpupdate ( funmat , helpdir , macrosdir , demosdir , modulename , %t )
helptbx_helpupdate ( funmat , helpdir , macrosdir , demosdir , modulename , %t );
//
// Generate the sorting help
"assert_sortcomplex"
];
macrosdir = cwd +"../../macros";
demosdir = cwd +"../../demos";
demosdir = [];
modulename = "assert";
helpupdate ( funmat , helpdir , macrosdir , demosdir , modulename , %t )
helptbx_helpupdate ( funmat , helpdir , macrosdir , demosdir , modulename , %t );
//
// Generate the support help
"assert_csvread"
];
macrosdir = cwd +"../../macros";
demosdir = cwd +"../../demos";
demosdir = [];
modulename = "assert";
helpupdate ( funmat , helpdir , macrosdir , demosdir , modulename , %t )
helptbx_helpupdate ( funmat , helpdir , macrosdir , demosdir , modulename , %t );
help/en_US/assert_checkerror.xml
11
22
33
4
4
55
6
6
77
88
99
......
2626
2727
2828
29
2930
3031
3132
......
4041
4142
4243
44
45
4346
4447
4548
......
6871
6972
7073
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
7192
7293
94
95
96
97
98
99
100
101
102
103
104
105
73106
74107
75108
......
93126
94127
95128
96
129
130
131
132
133
134
135
136
137
138
139
140
141
142
97143
98144
99145
......
117163
118164
119165
120
166
121167
122168
123169
<?xml version="1.0" encoding="UTF-8"?>
<!--
*
*
* This help file was generated from assert_checkerror.sci using help_from_sci().
*
*
-->
<refentry version="5.0-subset Scilab" xml:id="assert_checkerror" xml:lang="en"
<synopsis>
flag = assert_checkerror ( instr , expectedmsg )
flag = assert_checkerror ( instr , expectedmsg , expectederrnb )
flag = assert_checkerror ( instr , expectedmsg , expectederrnb , a1, ... )
[flag,errmsg] = assert_checkerror ( ... )
</synopsis>
<listitem><para> a 1x1 matrix of strings, the error message to be produced</para></listitem></varlistentry>
<varlistentry><term>expectederrnb :</term>
<listitem><para> a 1x1 matrix of floating point integers, the error number (default expectederrnb=[]).</para></listitem></varlistentry>
<varlistentry><term>a1 :</term>
<listitem><para> an extra localization argument, passed to the <literal>msprintf</literal> function.</para></listitem></varlistentry>
<varlistentry><term>flag :</term>
<listitem><para> a 1x1 matrix of boolean, %t if computed is close to expected, %f if not</para></listitem></varlistentry>
<varlistentry><term>errmsg :</term>
<para>
The goal of this function is to enable the tester to check the error
cases in a simplified framework.
Checking the error messages of a function has the following advantages:
<itemizedlist>
<listitem>
<para>
it checks that the correct error is generated when needed,
</para>
</listitem>
<listitem>
<para>
it checks that the error message is correctly formatted,
</para>
</listitem>
<listitem>
<para>
it checks that the error message is correctly localized.
</para>
</listitem>
</itemizedlist>
</para>
<para>
The expected message can be a localized message.
In this case, the message is compared with the output of
the <literal>gettext</literal> function,
and depends on the local language.
The extra argument <literal>a1</literal> can be used for this purpose,
for example to format the localized message.
All the extra arguments <literal>a1</literal>,
<literal>a2</literal>, ... are automatically passed to the
<literal>msprintf</literal> function before being compared to
the computed error message.
</para>
<para>
</para>
</refsection>
y = x
endfunction
// Our task is to check the error messages produced by this function
// Test which pass : the error message is the expected one
// The two following tests pass: the error message is the expected one.
// We let <literal>assert_checkerror</literal> manage the
// localization, by providing only the localized message and
// the extra parameter <literal>a1</literal>.
lcl1="%s: Wrong number of input argument: %d expected.\n";
lcl2="%s: Wrong type for argument %d: Matrix expected.\n";
assert_checkerror ( "y=f()" , lcl1 , [] , "f" , 1);
assert_checkerror ( "y=f(""a"")" , lcl2 , [] , "f" , 1);
// Test which pass : the error message is the expected one.
// Indeed, if we make the assumption that the current locale language
// is english, we could as well use the following statement.
// But this is not a recommended practice, since the test will
// fail if the current locale is french, for example.
msg1="f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected.";
msg2="f: Unexpected type of input argument #1 : variable x has type string while constant is expected.";
assert_checkerror ( "y=f()" , msg1 );
<refsection>
<title>Authors</title>
<simplelist type="vert">
<member>Copyright (C) 2010 - DIGITEO - Michael Baudin</member>
<member>Copyright (C) 2010 - 2011 - DIGITEO - Michael Baudin</member>
</simplelist>
</refsection>
</refentry>
etc/assert.start
5353
5454
5555
56
56
57
5758
5859
5960
6061
6162
6263
64
6365
6466
6567
// add demos
// =============================================================================
if ( %f ) then
if or(getscilabmode() == ["NW";"STD"]) then
mprintf("\tLoad demos\n");
demoscript = TOOLBOX_NAME + ".dem.gateway.sce"
pathdemos = pathconvert(fullfile(root_tlbx,"demos",demoscript),%f,%t);
add_demo(TOOLBOX_TITLE,pathdemos);
end
end
// =============================================================================

Archive Download the corresponding diff file

Revision: 122