assert_checkequal
Check that computed and expected are equal.
Syntax
assert_checkequal ( computed , expected ) flag = assert_checkequal ( computed , expected ) [flag,errmsg] = assert_checkequal ( computed , expected )
Parameters
- computed:
the computed result
- expected :
the expected result
- flag :
a boolean, %t if computed is equal to expected, %f if not
- errmsg :
a string, the error message. If flag==%t, then errormsg=="". If flag==%f, then errmsg contains the error message.
Description
Performs silently if computed
and expected
are equal.
For complex numbers: We compare first the real parts. In case of equality, we compare the imaginary parts.
Matching Nan values are always considered equal.
1/%z
and 2/(2*%z)
are not equal: For the time
being, Scilab does not normalize equivalent rationals.
In containers, matching void
elements are considered equal.
If the comparison shows that computed is equal to expected,
if the errmsg output variable is not used, an error is generated,
if the errmsg output variable is used, no error is generated.
Examples
Tests with success:
assert_checkequal ( %T , %T ); [flag , errmsg] = assert_checkequal ( [%T %F], [%T %F] ); assert_checkequal ( %nan , %nan ); c = complex(1, %nan) assert_checkequal (c, c); assert_checkequal ( sparse(%nan) , sparse(%nan) ); assert_checkequal ( 2:$-1, 2:$-1 ); assert_checkequal ( ["abc" "" ascii([9 10 13])], ["abc" "" ascii([9 10 13])] ); assert_checkequal ( [gdf(), gda()], [gdf(), gda()]); assert_checkequal ( list() , list() ); assert_checkequal ( list(1,,3), list(1,,3) ); assert_checkequal ( list(1,,list(,4)), list(1,,list(,4)) ); assert_checkequal ( list(%nan,,7) , list(%nan,,7) ); sine = sin; assert_checkequal ( sin, sine ); cosinus = cosd; assert_checkequal ( cosinus, cosd ); assert_checkequal( iolib, iolib );
Tests with failure:
assert_checkequal ( %F , %T ); flag = assert_checkequal ( %F , %T ); // No error produced : [flag , errmsg] = assert_checkequal ( %F , %T ) assert_checkequal ( [1 2], [3 4] ) assert_checkequal ( 1 , [2 3] ) assert_checkequal ( 1 , "b" ) assert_checkequal ( "b", "B" ) assert_checkequal ( 1+%s, 1+%z ) assert_checkequal ( 1/%s, 2/(2*%s) ) assert_checkequal (list(2,,7), list(2,%F,8)); assert_checkequal ( [gdf(), gda()], [gdf(), gdf()] ); assert_checkequal ( sind, cosd ); assert_checkequal ( iolib, corelib );
... --> assert_checkequal (list(2,,7), list(2,%F,8)); at line 22 of function assert_generror ( SCI\modules\..\assert_generror.sci line 33 ) at line 178 of function assert_checkequal ( SCI\modules\..\assert_checkequal.sci line 190 ) assert_checkequal: Assertion failed: expected(2)= F while computed(2)= (void) --> assert_checkequal ( [gdf(), gda()], [gdf(), gdf()] ); at line 22 of function assert_generror ( SCI\modules\..\assert_generror.sci line 33 ) at line 178 of function assert_checkequal ( SCI\modules\..\assert_checkequal.sci line 190 ) assert_checkequal: Assertion failed: expected(2)= Figure(uid:55) while computed(2)= Axes(uid:85) --> assert_checkequal ( sind, cosd ); at line 22 of function assert_generror ( SCI\modules\..\assert_generror.sci line 33 ) at line 82 of function assert_checkequal ( SCI\modules\..\assert_checkequal.sci line 94 ) assert_checkequal: Assertion failed: expected= cosd() while computed= sind() --> assert_checkequal ( iolib, corelib ); at line 22 of function assert_generror ( SCI\modules\..\assert_generror.sci line 33 ) at line 95 of function assert_checkequal ( SCI\modules\..\assert_checkequal.sci line 107 ) assert_checkequal: Assertion failed: expected= lib@SCI\modules\core\macros\ while .. computed= lib@SCI\modules\io\macros\
Bibliography
"Automated Software Testing for Matlab", Steven Eddins, 2009
History
Version | Description |
5.4.0 | Function introduced |
6.1.0 |
|
6.1.1 | Matching NaN or void elements in simple or nested containers are now considered equal. |
Report an issue | ||
<< assert_checkalmostequal | Assert | assert_checkerror >> |