Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.0 - Português

Change language to:
English - Français - 日本語 - Русский

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
See the recommended documentation of this function

Ajuda do Scilab >> Ferramentas de Desenvolvimento > Assert > assert_checkequal

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.

If the type of both input arguments is 1 (i.e. a matrix of real or complex numbers), we check that non-nan values are equal (matching Nan values are considered equal).

For complex numbers: We compare first the real parts. In case of equality, we compare the imaginary parts.

1/%z and 2/(2*%z) are not equal: For the time being, Scilab does not normalize equivalent rationals.

In two lists, 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\

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.

Bibliography

"Automated Software Testing for Matlab", Steven Eddins, 2009

Report an issue
<< assert_checkalmostequal Assert assert_checkerror >>

Copyright (c) 2022-2023 (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:
Tue Feb 25 08:52:43 CET 2020