Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2023.0.0 - Français


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

VersionDescription
5.4.0 Function introduced
6.1.0
  • The comparison of two implicit lists, Scilab functions, Scilab libraries, built-in functions or graphic handles is now always possible and properly done.
  • In two lists, void and Nan elements are now supported, and matching ones are considered as equal.
  • Nan are now supported in input sparse matrices and are considered as equal.
  • When the test fails while inputs are arrays, the message now indicates the index of the first mismatching element.
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 >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Mar 27 10:12:45 GMT 2023