SEP #20 : Sparse Matrices Algorithms
SEP #21 : Nelder-Mead Optimization Algorithm
SEP #22 : Sorting Algorithms
-SEP #23 : Extend «diary()»
+SEP #23 : Extend «diary()»
SEP #24 : Introduce an easy way to manage sub chapters in the documentation
SEP #25 : Extend "fileinfo" to manage a column vector as input argument
SEP #26 : Extend "strsplit" to manage a column vector as input argument
SEP #48 : Scilab Preferences
SEP #49 : repmat function
SEP #50 : Xcos Help Folders
-SEP #51 : Linear Programming
\ No newline at end of file
+SEP #51 : Linear Programming
+SEP #52 : Assert
+
* mgetl, exec, fscanfMat functions manage files encoded as UTF-8 with BOM.
+New functions
+=============
+
+* The assert module provides a set of assertion functions.
+ The goal of this module is to provide functions to check the
+ behavior of some other functions, for example in unit tests.
+ We emphasize the use of consistent tools for testing numerical
+ issues, with the goal of testing numerical algorithms more easily.
+ In particular, we provide a comparison function for two floating
+ point numbers, which allows to check that two numbers are
+ "numerically almost equal", i.e. that the relative error is small.
+ This automatically fixes the bug #4381.
+
Bug Fixes:
==========
* SSE is now enabled by default under GNU/Linux with 32 bit CPU (it is already
the case under 64 bit CPU).
Pentium III class (or equivalent) with SSE instructions is required.
+=======
+* bug 8608 - dec2hex, hex2dec, dec2oct, oct2dec, code have been simplified and optimized.
+
Source: modules\{#DEVTOOLS}\macros\buildmacros.bat; DestDir: {app}\modules\{#DEVTOOLS}\macros; Components: {#COMPN_DEVTOOLS}
Source: modules\{#DEVTOOLS}\macros\cleanmacros.bat; DestDir: {app}\modules\{#DEVTOOLS}\macros; Components: {#COMPN_DEVTOOLS}
;
+Source: modules\{#DEVTOOLS}\macros\assert\lib; DestDir: {app}\modules\{#DEVTOOLS}\macros\assert; Components: {#COMPN_DEVTOOLS}
+Source: modules\{#DEVTOOLS}\macros\assert\names; DestDir: {app}\modules\{#DEVTOOLS}\macros\assert; Components: {#COMPN_DEVTOOLS}
+Source: modules\{#DEVTOOLS}\macros\assert\*.bin; DestDir: {app}\modules\{#DEVTOOLS}\macros\assert; Components: {#COMPN_DEVTOOLS}
+Source: modules\{#DEVTOOLS}\macros\assert\*.sci; DestDir: {app}\modules\{#DEVTOOLS}\macros\assert; Components: {#COMPN_DEVTOOLS}
+Source: modules\{#DEVTOOLS}\macros\assert\buildmacros.sce; DestDir: {app}\modules\{#DEVTOOLS}\macros\assert; Components: {#COMPN_DEVTOOLS}
+Source: modules\{#DEVTOOLS}\macros\assert\buildmacros.bat; DestDir: {app}\modules\{#DEVTOOLS}\macros\assert; Components: {#COMPN_DEVTOOLS}
+Source: modules\{#DEVTOOLS}\macros\assert\cleanmacros.bat; DestDir: {app}\modules\{#DEVTOOLS}\macros\assert; Components: {#COMPN_DEVTOOLS}
+;
;Source: modules\{#DEVTOOLS}\demos\*.*; DestDir: {app}\modules\{#DEVTOOLS}\demos; Flags: recursesubdirs; Components: {#COMPN_DEVTOOLS}
;
;Source: modules\{#DEVTOOLS}\examples\*.*; DestDir: {app}\modules\{#DEVTOOLS}\examples; Flags: recursesubdirs; Components: {#COMPN_DEVTOOLS}
// Load functions libraries
// =============================================================================
load('SCI/modules/development_tools/macros/lib');
+load('SCI/modules/development_tools/macros/assert/lib');
--- /dev/null
+title = Assert
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ * Copyright (C) 2010-2011 - DIGITEO - Michael Baudin
+-->
+<refentry
+ xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns:mml="http://www.w3.org/1998/Math/MathML"
+ xmlns:db="http://docbook.org/ns/docbook"
+ version="5.0-subset Scilab"
+ xml:lang="fr"
+ xml:id="assert_overview">
+ <info>
+ <pubdate>$LastChangedDate: 16-12-2008 $</pubdate>
+ </info>
+
+ <refnamediv>
+ <refname>Assert Overview</refname>
+
+ <refpurpose>An overview of the Assert toolbox.</refpurpose>
+ </refnamediv>
+
+ <refsection>
+ <title>Purpose</title>
+
+ <para>
+ The goal of this module is to provide functions to check the
+ behavior of some other functions, for example in unit tests.
+ We emphasize the use of consistent tools for testing numerical issues,
+ with the goal of testing numerical algorithms more easily.
+ In particular, we provide a comparison function for two floating
+ point numbers, which allows to check that two numbers are "numerically almost equal",
+ i.e. that the relative error is small.
+ </para>
+
+ </refsection>
+
+ <refsection>
+ <title>Quick start</title>
+
+ <para>
+ The <literal>assert_checktrue</literal> function allows to
+ check that a matrix of booleans is true.
+ The following assertion fails and generate an error.
+ </para>
+
+ <programlisting role="example">
+ <![CDATA[
+assert_checktrue ( [%t %F] );
+ ]]>
+ </programlisting>
+
+ <para>
+ The <literal>assert_checkequal</literal> function allows to
+ check that two variables are equal.
+ The following assertion is a success and runs silently.
+ </para>
+
+ <programlisting role="example">
+ <![CDATA[
+assert_checkequal ( %nan , %nan );
+ ]]>
+ </programlisting>
+
+ <para>
+ The <literal>assert_checkalmostequal</literal> function allows to
+ check that a computed result is close to an expected result.
+ In the following script, we check that <literal>computed=1.23456</literal>
+ is close to <literal>expected=1.23457</literal>, but that
+ 11 digits have been lost with respect to the maximum
+ achievable accuracy.
+ </para>
+
+ <programlisting role="example">
+ <![CDATA[
+assert_checkalmostequal ( 1.23456 , 1.23457 , 1.e11*%eps );
+ ]]>
+ </programlisting>
+
+ <para>
+ A particular feature of the module is that all the assert functions
+ have the same output arguments.
+ This feature allows to get a uniform behavior and supports a
+ simple management of the errors in the case where an assertion is
+ not satisfied.
+ For example, consider the function <literal>assert_checktrue</literal>,
+ which calling sequence is:
+ </para>
+
+ <programlisting role="example">
+ <![CDATA[
+flag = assert_checktrue ( condition )
+flag = assert_checktrue ( condition )
+[flag,errmsg] = assert_checktrue ( condition )
+ ]]>
+ </programlisting>
+
+ <para>
+ If any entry in condition is false,
+ <itemizedlist>
+ <listitem>
+ <para>
+ if the errmsg output variable is not used, an error is generated,
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ if the errmsg output variable is used, no error is generated.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </para>
+
+ <para>
+ The reason of this behavior is to be able to use assertions
+ both in scripts (e.g. unit tests) and in functions.
+ For example, in a typical unit test, the statement:
+ </para>
+
+ <programlisting role="example">
+ <![CDATA[
+assert_checktrue ( 1+1==12 );
+ ]]>
+ </programlisting>
+
+ <para>
+ will generate an error, as expected.
+ On the other hand, consider the situation where we want to insert
+ assertions checkings in a function.
+ We might want to manage the case where the assertion fails.
+ In this case, the calling sequence <literal>assert_checktrue ( condition )</literal>
+ generates an error, which interrupts the execution.
+ We may want to avoid this, by catching the error generated by
+ <literal>assert_checktrue</literal>.
+ This requires to use the <literal>execstr</literal> function and
+ may lead to the following source code.
+ </para>
+
+ <programlisting role="example">
+ <![CDATA[
+function y = myfunction ( x )
+ ierr=execstr("assert_checktrue ( x==12 )","errcatch");
+ if ( ierr <> 0 ) then
+ error("Oups!")
+ end
+ y=x
+endfunction
+ ]]>
+ </programlisting>
+
+ <para>
+ In this case, we suggest to use instead the calling
+ sequence <literal>[flag,errmsg] = assert_checktrue ( condition )</literal>,
+ which simplifies the processing of the error.
+ </para>
+
+ <programlisting role="example">
+ <![CDATA[
+function y = myfunction2 ( x )
+ [flag,errmsg] = assert_checktrue ( x==12 )
+ if ( ~flag ) then
+ error("Oups!")
+ end
+ y=x
+endfunction
+ ]]>
+ </programlisting>
+
+ </refsection>
+
+ <refsection>
+ <title>Authors</title>
+
+ <simplelist type="vert">
+ <member>2008-2009 - INRIA - Michael Baudin</member>
+ <member>2009-2011 - DIGITEO - Michael Baudin</member>
+ </simplelist>
+ </refsection>
+
+</refentry>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ *
+ * Copyright (C) 2011 - DIGITEO - Michael Baudin
+ *
+ -->
+
+<refentry version="5.0-subset Scilab" xml:id="assert_checkalmostequal" xml:lang="en"
+ xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns:ns3="http://www.w3.org/1999/xhtml"
+ xmlns:mml="http://www.w3.org/1998/Math/MathML"
+ xmlns:db="http://docbook.org/ns/docbook">
+
+
+ <refnamediv>
+ <refname>assert_checkalmostequal</refname><refpurpose>Check that computed and expected are numerically close.</refpurpose>
+ </refnamediv>
+
+
+
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ flag = assert_checkalmostequal ( computed , expected )
+ flag = assert_checkalmostequal ( computed , expected , reltol )
+ flag = assert_checkalmostequal ( computed , expected , reltol , abstol )
+ flag = assert_checkalmostequal ( computed , expected , reltol , abstol , comptype )
+ [flag,errmsg] = assert_checkalmostequal ( ... )
+
+ </synopsis>
+</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>computed:</term>
+ <listitem><para> a 1x1 matrix of doubles, the computed result</para></listitem></varlistentry>
+ <varlistentry><term>expected :</term>
+ <listitem><para> a 1x1 matrix of doubles, the expected result</para></listitem></varlistentry>
+ <varlistentry><term>reltol :</term>
+ <listitem><para> a 1x1 matrix of doubles, the relative tolerance (default reltol=sqrt(%eps)).</para></listitem></varlistentry>
+ <varlistentry><term>abstol :</term>
+ <listitem><para> a 1x1 matrix of doubles, the absolute tolerance (default abstol=0).</para></listitem></varlistentry>
+ <varlistentry><term>comptype :</term>
+ <listitem><para> a 1x1 matrix of strings, "matrix" or "element" (default comptype="matrix"). The comparison type.</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>
+ <listitem><para> a 1x1 matrix of strings, the error message. If flag==%t, then errormsg=="". If flag==%f, then errmsg contains the error message.</para></listitem></varlistentry>
+ </variablelist>
+</refsection>
+
+<refsection>
+ <title>Description</title>
+ <para>
+Performs silently if the two matrices of doubles or complex doubles
+computed and expected are close.
+The variables computed and expected can be exchanged without changing the result.
+ </para>
+ <para>
+Any optional input argument equal to the empty matrix is replaced by its default value.
+ </para>
+ <para>
+We use the following algorithm.
+We compare first the real parts. In case of equality, we compare the imaginary parts.
+ </para>
+ <para>
+The condition used is mixed relative and absolute:
+<programlisting>
+( |e-c| <= reltol * max(|e|,|c|) + abstol )
+</programlisting>
+If comptype="matrix", the norm is used.
+If comptype="element", the absolute value are used and the two matrices are
+almost equal if all the conditions are true.
+ </para>
+ <para>
+If the IEEE values %inf, -%inf or %nan values are in the matrices,
+then they are almost equal only if the IEEE values are
+at the same indices in the matrices.
+ </para>
+ <para>
+The default comparison is based on a relative error, ensuring that 8 digits are common.
+This allows to assert the number of significant digits in the computed result.
+ </para>
+ <para>
+This procedure only works when the computed and expected variables
+are matrices of doubles.
+It will generate an error in any other case.
+ </para>
+ <para>
+If the comparison shows that computed is not almost equal to expected,
+<itemizedlist>
+<listitem>if the errmsg output variable is not used, an error is generated,</listitem>
+<listitem>if the errmsg output variable is used, no error is generated.</listitem>
+</itemizedlist>
+ </para>
+ <para>
+In the process of comparing the values, we separate %nan, +%inf, -%inf and remaining values.
+Comparing nan values between them is not possible. This is why we compare the
+indices where %nan value occurs.
+If we form differences of infinity values, we produce %nan values.
+This is why we compare the indices where +%inf values occurs.
+We do the same for -%inf values.
+Then, the non-nan, non-infinity values are actually compared.
+ </para>
+ <para>
+The default value comptype="matrix" option performs the comparison for the matrices as a whole,
+the norm of the difference of the matrices is used.
+The comptype="element" option performs the comparison elementwise, i.e.
+all the elements of the matrices must be almost equal.
+ </para>
+ <para>
+In general, the relative tolerance should be
+set to a multiple of the machine precision %eps.
+The relative tolerance should also be chosen with the lowest
+possible magnitude, that is, we shoud configure
+the tolerance as accurately as possible.
+During the process of configuring the relative tolerance, we
+suggest to use the following values, in that order :
+0 (all digits correct), %eps, 10*%eps, 100*%eps, 1.e3*%eps, 1.e4*%eps, ...,
+1.e17*%eps (no digit correct).
+See below for examples of this.
+ </para>
+ <para>
+This function takes into account for complex numbers.
+We first compare the real parts of the input arguments.
+If this fails, we immediately return.
+If this succeeds, we compare the imaginary parts of the input arguments.
+ </para>
+ <para>
+</para>
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+// Comparisons which are successful.
+// Relative error :
+assert_checkalmostequal ( 1 , 1 );
+assert_checkalmostequal ( 1 , 1 , %eps );
+assert_checkalmostequal ( ones(10,1) , ones(10,1) , %eps );
+// Absolute error :
+assert_checkalmostequal ( 1.23456789123456789e-30 , 0 , 0 , 1.e-10 );
+assert_checkalmostequal ( [1 %nan], [1 %nan] , 0 , %eps );
+
+// Comparisons which are failures.
+// Error message produced :
+assert_checkalmostequal ( 1 , 2 , %eps );
+// Error message produced :
+flag = assert_checkalmostequal ( 1 , 2 , %eps )
+// No error message produced :
+[flag,errmsg] = assert_checkalmostequal ( 1 , 2 , %eps )
+assert_checkalmostequal ( 1 , [2 3] , %eps );
+assert_checkalmostequal ( [%nan 1], [1 %nan] , %eps );
+assert_checkalmostequal ( 1 + 5 * %eps , 1 , %eps );
+assert_checkalmostequal ( 1.23456789123456789e-30 , 1.3e-30 , %eps );
+
+// In the case where expected is nonzero, the
+// tolerance for relative error should be a
+// multiple of %eps.
+// The following test is a success and shows
+// that less than 11 digits are lost with respect
+// to the maximum possible accuracy.
+assert_checkalmostequal ( 1.23456 , 1.23457 , 1.e11*%eps );
+
+// We cannot exchange the relative and absolute tolerances.
+// The following test pass: we use an absolute tolerance
+// because the expected value is zero.
+assert_checkalmostequal ( 1.23456789e-30 , 0 , 0 , 1.e-10 );
+// The following test fail: we use a relative tolerance.
+assert_checkalmostequal ( 0 , 1.23456789e-30 , 1.e-10 );
+
+// We must configure the tolerance as tightly as possible.
+// The following test fails, because the tolerance is too small
+// with respect to the given numbers.
+assert_checkalmostequal ( 1.23456 , 1.23457 , %eps );
+// In order to get the number of common digits:
+assert_computedigits(1.23456 , 1.23457)
+// which returns 5.09...
+// We now make a judgment on the accuracy and conclude it is acceptable:
+assert_checkalmostequal ( 1.23456 , 1.23457 , 1.e-5 );
+
+// We give here a practical example of the use of assert_checkalmostequal.
+// We solve an averagely ill-conditionned system of linear
+// equations, based on the Hilbert matrix.
+n = 6;
+// The expected value is set by ourselves.
+expected = ones(n,1);
+A = testmatrix("hilb",n);
+// We compute the condition number of the matrix : ~10^8
+ceil(log10(cond(A)))
+// This means that the number of digits lost,
+// predicted by theory, is 8.
+// The right-hand side is computed given A and expected.
+b = A * expected;
+// In this case, a Gauss algorithm with partial
+// pivoting is used.
+computed = A\b;
+// The following test fails: we have lost some digits.
+assert_checkalmostequal(computed,expected,%eps)
+// We compute the actual number of common digits: from 10 to 12
+assert_computedigits(computed, expected)
+// We accept this computation.
+// The following test pass.
+assert_checkalmostequal(computed,expected,1.e5*%eps);
+
+// The following test pass.
+assert_checkalmostequal ( [1 1.e5] , [2 1.e5] , 1.e-3 )
+// We see that 1 is not almost equal to 2: we must use the elementwise comparison.
+// The following test does not pass.
+assert_checkalmostequal ( [1 1.e5] , [2 1.e5] , 1.e-3 , [] , "element" )
+
+// The following test pass.
+// It is non-trivial to take into account for IEEE values.
+[flag,errmsg] = assert_checkalmostequal ( [1.2345 %inf -%inf %nan] , [1.2346 %inf -%inf %nan] , 1.e-4 )
+
+// This function takes into account for complex numbers.
+// The following test pass.
+assert_checkalmostequal ( 1+%i , 1+(1+1.e-4)*%i , 1.e-3 , [], "element" );
+// The following test fails.
+assert_checkalmostequal ( 1+%i , 1+(1+1.e-4)*%i , 1.e-5 , [], "element" );
+
+ ]]></programlisting>
+</refsection>
+
+<refsection>
+ <title>Authors</title>
+ <simplelist type="vert">
+ <member>Copyright (C) 2009 - 2011 - DIGITEO - Michael Baudin</member>
+ <member>Copyright (C) 2008 - 2009 - INRIA - Michael Baudin</member>
+ </simplelist>
+</refsection>
+</refentry>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ *
+ * Copyright (C) 2011 - DIGITEO - Michael Baudin
+ *
+ -->
+
+<refentry version="5.0-subset Scilab" xml:id="assert_checkequal" xml:lang="en"
+ xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns:ns3="http://www.w3.org/1999/xhtml"
+ xmlns:mml="http://www.w3.org/1998/Math/MathML"
+ xmlns:db="http://docbook.org/ns/docbook">
+
+
+ <refnamediv>
+ <refname>assert_checkequal</refname><refpurpose>Check that computed and expected are equal.</refpurpose>
+ </refnamediv>
+
+
+
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ assert_checkequal ( computed , expected )
+ flag = assert_checkequal ( computed , expected )
+ [flag,errmsg] = assert_checkequal ( computed , expected )
+
+ </synopsis>
+</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>computed:</term>
+ <listitem><para> the computed result</para></listitem></varlistentry>
+ <varlistentry><term>expected :</term>
+ <listitem><para> the expected result</para></listitem></varlistentry>
+ <varlistentry><term>flag :</term>
+ <listitem><para> a 1x1 matrix of boolean, %t if computed is equal to expected, %f if not</para></listitem></varlistentry>
+ <varlistentry><term>errmsg :</term>
+ <listitem><para> a 1x1 matrix of strings, the error message. If flag==%t, then errormsg=="". If flag==%f, then errmsg contains the error message.</para></listitem></varlistentry>
+ </variablelist>
+</refsection>
+
+<refsection>
+ <title>Description</title>
+ <para>
+Performs silently if computed and expected are equal.
+ </para>
+ <para>
+If the type of both input arguments is 1 (i.e. a real matrix),
+we check that non-nan values are equal.
+ </para>
+ <para>
+We compare first the real parts. In case of equality, we compare the imaginary parts.
+ </para>
+ <para>
+If the comparison shows that computed is equal to expected,
+and if the errmsg output variable is not used, an error is generated.
+If the comparison shows that computed is equal to expected,
+and if the errmsg output variable is used, no error is generated.
+ </para>
+ <para>
+</para>
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+// Tests with success
+assert_checkequal ( %T , %T );
+flag = assert_checkequal ( list() , list() );
+[flag , errmsg] = assert_checkequal ( [%T %F], [%T %F] );
+assert_checkequal ( %nan , %nan );
+
+// 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" )
+
+ ]]></programlisting>
+</refsection>
+
+<refsection>
+ <title>Authors</title>
+ <simplelist type="vert">
+ <member>Copyright (C) 2009 - 2011 - DIGITEO - Michael Baudin</member>
+ </simplelist>
+</refsection>
+
+<refsection>
+ <title>Bibliography</title>
+ <para>"Automated Software Testing for Matlab", Steven Eddins, 2009</para>
+</refsection>
+</refentry>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ *
+ * Copyright (C) 2011 - DIGITEO - Michael Baudin
+ *
+ -->
+
+<refentry version="5.0-subset Scilab" xml:id="assert_checkerror" xml:lang="en"
+ xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns:ns3="http://www.w3.org/1999/xhtml"
+ xmlns:mml="http://www.w3.org/1998/Math/MathML"
+ xmlns:db="http://docbook.org/ns/docbook">
+
+
+ <refnamediv>
+ <refname>assert_checkerror</refname><refpurpose>Check that an instruction produces the expected error.</refpurpose>
+ </refnamediv>
+
+
+
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ flag = assert_checkerror ( instr , expectedmsg )
+ flag = assert_checkerror ( instr , expectedmsg , expectederrnb )
+ [flag,errmsg] = assert_checkerror ( ... )
+
+ </synopsis>
+</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>instr:</term>
+ <listitem><para> a 1x1 matrix of strings, an expression to evaluate</para></listitem></varlistentry>
+ <varlistentry><term>expectedmsg :</term>
+ <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>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>
+ <listitem><para> a 1x1 matrix of strings, the error message. If flag==%t, then errormsg=="". If flag==%f, then errmsg contains the error message.</para></listitem></varlistentry>
+ </variablelist>
+</refsection>
+
+<refsection>
+ <title>Description</title>
+ <para>
+If the expression does not generate an error, then assert_checkerror generates an error.
+Performs silently if the evaluated expression generates the expected error message.
+If the error number is provided, we additionnally check that the generated error number matches the
+expected one.
+ </para>
+ <para>
+The string matching is strict string equality: no pattern or regular expression can be used.
+ </para>
+ <para>
+If the error message is not expected or the error number is not expected,
+<itemizedlist>
+<listitem>if the errmsg output variable is not used, an error is generated,</listitem>
+<listitem>if the errmsg output variable is used, no error is generated.</listitem>
+</itemizedlist>
+ </para>
+ <para>
+The goal of this function is to enable the tester to check the error
+cases in a simplified framework.
+ </para>
+ <para>
+</para>
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+// This function generates an error when
+// * the number of input arguments in wrong
+// * the type of x is wrong
+function y = f(x)
+[lhs,rhs]=argn()
+if ( rhs <> 1 ) then
+errmsg = sprintf ( gettext ( "%s: Unexpected number of input arguments : %d provided while %d to %d are expected.") , "f" , rhs , 1 , 1 )
+error(errmsg)
+end
+if ( typeof(x) <> "constant" ) then
+localstr = gettext ( "%s: Unexpected type of input argument #%d : variable %s has type %s while %s is expected.")
+errmsg = sprintf ( localstr , "f" , 1 , "x" , typeof(x) , "constant" )
+error(errmsg,123456789)
+end
+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
+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 );
+assert_checkerror ( "y=f(""a"")" , msg2 );
+// Also check the error number
+assert_checkerror ( "y=f()" , msg1 , 10000 );
+assert_checkerror ( "y=f(""a"")" , msg2 , 123456789 );
+// Test which fail
+assert_checkerror ( "y=f()" , "oups" );
+assert_checkerror ( "y=f()" , msg1 , 12 );
+
+// When errmsg is given as output argument, no error is generated
+// A test which pass: flag is %t, errmsg is empty
+[flag,errmsg] = assert_checkerror ( "y=f()" , msg1 )
+// A test which fail: flag is %f, errmsg is not empty
+[flag,errmsg] = assert_checkerror ( "y=f()" , "oups" )
+
+ ]]></programlisting>
+</refsection>
+
+<refsection>
+ <title>Authors</title>
+ <simplelist type="vert">
+ <member>Copyright (C) 2010 - DIGITEO - Michael Baudin</member>
+ </simplelist>
+</refsection>
+</refentry>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ *
+ * Copyright (C) 2011 - DIGITEO - Michael Baudin
+ *
+ -->
+
+<refentry version="5.0-subset Scilab" xml:id="assert_checkfalse" xml:lang="en"
+ xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns:ns3="http://www.w3.org/1999/xhtml"
+ xmlns:mml="http://www.w3.org/1998/Math/MathML"
+ xmlns:db="http://docbook.org/ns/docbook">
+
+
+ <refnamediv>
+ <refname>assert_checkfalse</refname><refpurpose>Check that condition is false.</refpurpose>
+ </refnamediv>
+
+
+
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ flag = assert_checkfalse ( condition )
+ flag = assert_checkfalse ( condition )
+ [flag,errmsg] = assert_checkfalse ( condition )
+
+ </synopsis>
+</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>condition:</term>
+ <listitem><para> a matrix of booleans</para></listitem></varlistentry>
+ <varlistentry><term>flag :</term>
+ <listitem><para> a 1x1 matrix of boolean, %t if condition is false, %f if not</para></listitem></varlistentry>
+ <varlistentry><term>errmsg :</term>
+ <listitem><para> a 1x1 matrix of strings, the error message. If flag==%t, then errormsg=="". If flag==%f, then errmsg contains the error message.</para></listitem></varlistentry>
+ </variablelist>
+</refsection>
+
+<refsection>
+ <title>Description</title>
+ <para>
+Performs silently if all entries in <literal>condition</literal> are false.
+ </para>
+ <para>
+Generates an error if any entry in <literal>condition</literal>
+is true.
+Generates an error if <literal>condition</literal> is not a boolean.
+ </para>
+ <para>
+If any entry in condition is true,
+<itemizedlist>
+<listitem>if the errmsg output variable is not used, an error is generated,</listitem>
+<listitem>if the errmsg output variable is used, no error is generated.</listitem>
+</itemizedlist>
+ </para>
+ <para>
+</para>
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+// Tests which pass
+assert_checkfalse ( %f );
+flag = assert_checkfalse ( %f )
+[flag,errmsg] = assert_checkfalse ( %f )
+[flag,errmsg] = assert_checkfalse ( [%f %f] );
+
+// Tests which fail
+assert_checkfalse ( [%t %f] );
+flag = assert_checkfalse ( [%t %f] )
+// No error generated
+[flag,errmsg] = assert_checkfalse ( [%t %f] )
+
+// Wrong calls
+assert_checkfalse ( "a" )
+
+ ]]></programlisting>
+</refsection>
+
+<refsection>
+ <title>Authors</title>
+ <simplelist type="vert">
+ <member>Copyright (C) 2009 - 2011 - DIGITEO - Michael Baudin</member>
+ </simplelist>
+</refsection>
+</refentry>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ *
+ * Copyright (C) 2011 - DIGITEO - Michael Baudin
+ *
+ -->
+
+<refentry version="5.0-subset Scilab" xml:id="assert_checkfilesequal" xml:lang="en"
+ xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns:ns3="http://www.w3.org/1999/xhtml"
+ xmlns:mml="http://www.w3.org/1998/Math/MathML"
+ xmlns:db="http://docbook.org/ns/docbook">
+
+
+ <refnamediv>
+ <refname>assert_checkfilesequal</refname><refpurpose>Check two files are equal.</refpurpose>
+ </refnamediv>
+
+
+
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ flag = assert_checkfilesequal ( filecomp , fileref )
+ flag = assert_checkfilesequal ( filecomp , fileref , compfun )
+ [flag,errmsg] = assert_checkfilesequal ( ... )
+
+ </synopsis>
+</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>filecomp :</term>
+ <listitem><para> a 1x1 matrix of strings, the computed file.</para></listitem></varlistentry>
+ <varlistentry><term>fileref :</term>
+ <listitem><para> a 1x1 matrix of strings, the reference file.</para></listitem></varlistentry>
+ <varlistentry><term>compfun :</term>
+ <listitem><para> a function or a list, the comparison function (default compfun = []). If no comparison function is used, the equality operator "==" is used. See below for details.</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>
+ <listitem><para> a 1x1 matrix of strings, the error message. If flag==%t, then errormsg=="". If flag==%f, then errmsg contains the error message.</para></listitem></varlistentry>
+ </variablelist>
+</refsection>
+
+<refsection>
+ <title>Description</title>
+ <para>
+Performs silently if the files are equal.
+Generates an error if filecomp or fileref do not exist.
+Generates an error if the content of the files are not equal.
+ </para>
+ <para>
+If the files are not equal,
+<itemizedlist>
+<listitem>if the errmsg output variable is not used, an error is generated,</listitem>
+<listitem>if the errmsg output variable is used, no error is generated.</listitem>
+</itemizedlist>
+ </para>
+ <para>
+If the comparison function compfun is a function, it should have header areequal = compfun ( txtcomp , txtref )
+where txtcomp is the content of the computed file, txtref is the content of the reference file and areequal
+is a boolean. The areequal boolean is true if the two contents are equal.
+If compfun is a list, it should be list (cf,a1,a2,...), where cf is a comparison function,
+and the arguments a1, a2, will be automatically be appended at the
+end of the calling sequence of cf.
+ </para>
+ <para>
+</para>
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+//
+// Prepare data for the tests
+// fileref1 : three lines of text.
+// filecomp1 : == fileref1
+// filecomp2 : <> fileref1
+fileref1 = fullfile(TMPDIR,"fileref.txt");
+txt1 = [
+"Line #1"
+"Line #2"
+"Line #3"
+];
+fd = mopen(fileref1,"w");
+mputl(txt1,fd);
+mclose(fd);
+filecomp1 = fullfile(TMPDIR,"filecomp1.txt");
+fd = mopen(filecomp1,"w");
+mputl(txt1,fd);
+mclose(fd);
+filecomp2 = fullfile(TMPDIR,"filecomp2.txt");
+txt2 = [
+"Line #1"
+"Line #4"
+"Line #3"
+];
+fd = mopen(filecomp2,"w");
+mputl(txt2,fd);
+mclose(fd);
+
+// A test which pass
+flag = assert_checkfilesequal ( filecomp1 , fileref1 )
+[flag,errmsg] = assert_checkfilesequal ( filecomp1 , fileref1 )
+
+// Failure: filecomp2 <> fileref1
+// Error generated
+flag = assert_checkfilesequal ( filecomp2 , fileref1 )
+// No error generated
+[flag,errmsg] = assert_checkfilesequal ( filecomp2 , fileref1 )
+
+// Prepare data for the tests
+// fileref2 == filecomp3, given that comment lines are ignored.
+// fileref2 <> filecomp4, given that comment lines are ignored.
+// Notice that the comments are inserted at different positions in the files:
+// sometimes at the begining, sometimes in the middle.
+fileref2 = fullfile(TMPDIR,"fileref2.txt");
+txt = [
+"// bla 2"
+"Line #1"
+"// bla 2"
+"Line #2"
+"Line #3"
+];
+fd = mopen(fileref2,"w");
+mputl(txt,fd);
+mclose(fd);
+filecomp3 = fullfile(TMPDIR,"filecomp3.txt");
+txt = [
+"Line #1"
+"// bla 5168"
+"Line #2"
+"Line #3"
+"// bla oups"
+];
+fd = mopen(filecomp3,"w");
+mputl(txt,fd);
+mclose(fd);
+filecomp4 = fullfile(TMPDIR,"filecomp4.txt");
+txt = [
+"// bla 3"
+"Line #1"
+"Line #4"
+"// bla 5168"
+"Line #3"
+"// bla oups"
+];
+fd = mopen(filecomp4,"w");
+mputl(txt,fd);
+mclose(fd);
+
+// A test with a comparison function which ignores comment lines.
+function otxt = myfilter ( itxt )
+nr = size(itxt,"r")
+// This is the pattern for a comment line of the form "// blabla"
+pattern = "/\/\/.*/"
+k = 1
+for i = 1 : nr
+start = regexp(itxt(i),pattern)
+if ( start == [] ) then
+otxt(k) = itxt(i)
+k = k + 1
+end
+end
+endfunction
+function areequal = mycompfun ( ctxt , etxt )
+ctxt = myfilter ( ctxt )
+etxt = myfilter ( etxt )
+areequal = ( ctxt == etxt )
+endfunction
+//
+// A test which pass
+[flag,errmsg] = assert_checkfilesequal ( filecomp3 , fileref2 , mycompfun )
+// A test which fails
+[flag,errmsg] = assert_checkfilesequal ( filecomp4 , fileref2 , mycompfun )
+
+ ]]></programlisting>
+</refsection>
+
+<refsection>
+ <title>Authors</title>
+ <simplelist type="vert">
+ <member>Copyright (C) 2009 - 2011 - DIGITEO - Michael Baudin</member>
+ </simplelist>
+</refsection>
+</refentry>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ *
+ * Copyright (C) 2011 - DIGITEO - Michael Baudin
+ *
+ -->
+
+<refentry version="5.0-subset Scilab" xml:id="assert_checktrue" xml:lang="en"
+ xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns:ns3="http://www.w3.org/1999/xhtml"
+ xmlns:mml="http://www.w3.org/1998/Math/MathML"
+ xmlns:db="http://docbook.org/ns/docbook">
+
+
+ <refnamediv>
+ <refname>assert_checktrue</refname><refpurpose>Check that condition is true.</refpurpose>
+ </refnamediv>
+
+
+
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ flag = assert_checktrue ( condition )
+ flag = assert_checktrue ( condition )
+ [flag,errmsg] = assert_checktrue ( condition )
+
+ </synopsis>
+</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>condition:</term>
+ <listitem><para> a matrix of booleans</para></listitem></varlistentry>
+ <varlistentry><term>flag :</term>
+ <listitem><para> a 1x1 matrix of boolean, %t if condition is true, %f if not</para></listitem></varlistentry>
+ <varlistentry><term>errmsg :</term>
+ <listitem><para> a 1x1 matrix of strings, the error message. If flag==%t, then errormsg=="". If flag==%f, then errmsg contains the error message.</para></listitem></varlistentry>
+ </variablelist>
+</refsection>
+
+<refsection>
+ <title>Description</title>
+ <para>
+Performs silently if all entries in <literal>condition</literal> are true.
+ </para>
+ <para>
+Generates an error if any entry in the <literal>condition</literal> matrix
+is false.
+Generates an error if <literal>condition</literal> is not a boolean.
+ </para>
+ <para>
+If any entry in condition is false,
+<itemizedlist>
+<listitem>if the errmsg output variable is not used, an error is generated,</listitem>
+<listitem>if the errmsg output variable is used, no error is generated.</listitem>
+</itemizedlist>
+ </para>
+ <para>
+</para>
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+// Tests which pass
+assert_checktrue ( %t );
+flag = assert_checktrue ( %t )
+[flag,errmsg] = assert_checktrue ( %t )
+[flag,errmsg] = assert_checktrue ( [%t %t] );
+
+// Tests which fail
+assert_checktrue ( [%t %f] );
+flag = assert_checktrue ( [%t %f] )
+// No error generated
+[flag,errmsg] = assert_checktrue ( [%t %f] )
+
+// Wrong calls
+assert_checktrue ( "a" )
+
+ ]]></programlisting>
+</refsection>
+
+<refsection>
+ <title>Authors</title>
+ <simplelist type="vert">
+ <member>Copyright (C) 2009 - 2011 - DIGITEO - Michael Baudin</member>
+ </simplelist>
+</refsection>
+</refentry>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ *
+ * Copyright (C) 2011 - DIGITEO - Michael Baudin
+ *
+ -->
+
+<refentry version="5.0-subset Scilab" xml:id="assert_comparecomplex" xml:lang="en"
+ xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns:ns3="http://www.w3.org/1999/xhtml"
+ xmlns:mml="http://www.w3.org/1998/Math/MathML"
+ xmlns:db="http://docbook.org/ns/docbook">
+
+
+ <refnamediv>
+ <refname>assert_comparecomplex</refname><refpurpose>Compare complex numbers with a tolerance.</refpurpose>
+ </refnamediv>
+
+
+
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ order = assert_comparecomplex ( a , b )
+ order = assert_comparecomplex ( a , b , reltol )
+ order = assert_comparecomplex ( a , b , reltol , abstol )
+
+ </synopsis>
+</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>a :</term>
+ <listitem><para> a 1x1 matrix of doubles, the first value to be compared</para></listitem></varlistentry>
+ <varlistentry><term>b :</term>
+ <listitem><para> a 1x1 matrix of doubles, the second value to be compared</para></listitem></varlistentry>
+ <varlistentry><term>reltol :</term>
+ <listitem><para> a 1x1 matrix of doubles, the relative tolerance (default reltol=sqrt(%eps)).</para></listitem></varlistentry>
+ <varlistentry><term>abstol :</term>
+ <listitem><para> a 1x1 matrix of doubles, the absolute tolerance (default abstol=0).</para></listitem></varlistentry>
+ <varlistentry><term>order :</term>
+ <listitem><para> a 1x1 matrix of floating point integers, the order. Returns order=0 is a is almost equal to b, order=-1 if a < b, order=+1 if a > b.</para></listitem></varlistentry>
+ </variablelist>
+</refsection>
+
+<refsection>
+ <title>Description</title>
+ <para>
+Compare first by real parts, then by imaginary parts.
+Takes into account numerical accuracy issues, by using
+a mixed relative and absolute tolerance criteria.
+ </para>
+ <para>
+Any optional input argument equal to the empty matrix is replaced by its default value.
+ </para>
+ <para>
+We use the following algorithm.
+ </para>
+ <para>
+We compare first the real parts. In case of tie, we compare the imaginary parts.
+ </para>
+ <para>
+We process the IEEE values and choose the order : -%inf < 0 < %inf < %nan.
+If none of the values is special, we use the condition :
+<programlisting>
+cond = ( abs(a-b) <= reltol * max(abs(a),abs(b)) + abstol )
+</programlisting>
+ </para>
+ <para>
+This algorithm is designed to be used into sorting
+algorithms.
+It allows to take into account for the portability issues
+related to the outputs of functions producing
+matrix of complex doubles.
+If this algorithm is plugged into a sorting function,
+it allows to consistently produce a sorted matrix,
+where the order can be independent of the operating system,
+the compiler or other forms of issues modifying the
+order (but not the values).
+ </para>
+ <para>
+</para>
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+// Compare real values
+assert_comparecomplex ( 1 , -1 ) // 1
+assert_comparecomplex ( -1 , 1 ) // -1
+assert_comparecomplex ( 1 , 1 ) // 0
+
+// Compare complex values #1
+assert_comparecomplex ( 1+2*%i , 1+3*%i ) // -1
+assert_comparecomplex ( 1+3*%i , 1+2*%i ) // 1
+assert_comparecomplex ( 1+2*%i , 1+2*%i ) // 0
+
+// Compare complex values #2
+assert_comparecomplex ( 1+%i , -1+%i ) // 1
+assert_comparecomplex ( -1+%i , 1+%i ) // -1
+assert_comparecomplex ( 1+%i , 1+%i ) // 0
+[order,msg] = assert_comparecomplex ( 1+%i , 1+%i )
+
+// Compare with tolerances : equality cases
+assert_comparecomplex ( 1.2345+%i , 1.2346+%i , %eps , 1.e-3 ) // 0
+assert_comparecomplex ( 1.2345+%i , 1.2346+%i , 1.e12*%eps , 0 ) // 0
+assert_comparecomplex ( 1+1.2345*%i , 1+1.2347*%i , %eps , 1.e-3 ) // 0
+assert_comparecomplex ( 1+1.2345*%i , 1+1.2347*%i , 1.e12*%eps , 0 ) // 0
+
+// Compare more realistic data
+x = [
+-0.123452 - 0.123454 * %i
+-0.123451 + 0.123453 * %i
+0.123458 - 0.123459 * %i
+0.123456 + 0.123457 * %i
+];
+// Consider less than 4 significant digits
+for i = 1 : size(x,"*")-1
+order = assert_comparecomplex ( x(i) , x(i+1) , 1.e-4 );
+mprintf("compare(x(%d),x(%d))=%d\n",i,i+1,order)
+end
+
+// Compare data from bug #415
+x = [
+-1.9914145
+-1.895889
+-1.6923826
+-1.4815461
+-1.1302576
+-0.5652256 - 0.0655080 * %i
+-0.5652256 + 0.0655080 * %i
+0.3354023 - 0.1602902 * %i
+0.3354023 + 0.1602902 * %i
+1.3468911
+1.5040136
+1.846668
+1.9736772
+1.9798866
+];
+// Consider less than 4 significant digits
+for i = 1 : size(x,"*")-1
+order = assert_comparecomplex ( x(i) , x(i+1) , 1.e-5 );
+mprintf("compare(x(%d),x(%d))=%d\n",i,i+1,order)
+end
+
+ ]]></programlisting>
+</refsection>
+
+<refsection>
+ <title>Authors</title>
+ <simplelist type="vert">
+ <member>Copyright (C) 2009 - 2011 - DIGITEO - Michael Baudin</member>
+ </simplelist>
+</refsection>
+
+<refsection>
+ <title>Bibliography</title>
+ <para>http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/polynomials/tests/nonreg_tests/bug_415.tst;h=0c716a3bed0dfb72c831972d19dbb0814dffde2b;hb=HEAD</para>
+ <para>http://gitweb.scilab.org/?p=scilab.git;a=blob_plain;f=scilab/modules/cacsd/tests/nonreg_tests/bug_68.tst;h=920d091d089b61bf961ea9e888b4d7d469942a14;hb=4ce3d4109dd752fce5f763be71ea639e09a12630</para>
+</refsection>
+</refentry>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ *
+ * Copyright (C) 2011 - DIGITEO - Michael Baudin
+ *
+ -->
+
+<refentry version="5.0-subset Scilab" xml:id="assert_computedigits" xml:lang="en"
+ xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns:ns3="http://www.w3.org/1999/xhtml"
+ xmlns:mml="http://www.w3.org/1998/Math/MathML"
+ xmlns:db="http://docbook.org/ns/docbook">
+
+
+ <refnamediv>
+ <refname>assert_computedigits</refname><refpurpose>Returns the number of significant digits in computed result.</refpurpose>
+ </refnamediv>
+
+
+
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ d = assert_computedigits ( computed , expected )
+ d = assert_computedigits ( computed , expected , basis )
+
+ </synopsis>
+</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>computed :</term>
+ <listitem><para> a matrix of doubles, the computed value</para></listitem></varlistentry>
+ <varlistentry><term>expected :</term>
+ <listitem><para> a matrix of doubles, the expected value</para></listitem></varlistentry>
+ <varlistentry><term>basis :</term>
+ <listitem><para> a 1x1 matrix of floating point integers, the basis (default basis=10)</para></listitem></varlistentry>
+ <varlistentry><term>d :</term>
+ <listitem><para> a matrix of doubles, the number of significant digits.</para></listitem></varlistentry>
+ </variablelist>
+</refsection>
+
+<refsection>
+ <title>Description</title>
+ <para>
+Computes the number of significant digits in a computed
+result with respect to a nonzero expected result, using the formula:
+ </para>
+ <para>
+<latex>
+\begin{eqnarray}
+d = - \frac{\log_{10} ( r )}{\log_{10}(basis)}
+\end{eqnarray}
+</latex>
+ </para>
+ <para>
+where r is the relative error defined by
+ </para>
+ <para>
+<latex>
+\begin{eqnarray}
+r = \frac{|computed - expected|}{|expected|}
+\end{eqnarray}
+</latex>
+ </para>
+ <para>
+Any optional input argument equal to the empty matrix is replaced by its default value.
+ </para>
+ <para>
+The number of significant digits is between dmin = 0 and dmax = -log10(2^(-53)) which
+is approximately 15.95 ~ 16.
+In base 2, the number of significant bits is 53.
+ </para>
+ <para>
+If expected is equal to computed, then d is set to its maximum value, i.e. dmax.
+If not, if expected is zero and computed is nonzero, then d is set to its minimum
+value, i.e. dmin=0.
+ </para>
+ <para>
+The values of computed and expected cannot be exchanged, since the relative
+error is based on the expected value.
+ </para>
+ <para>
+The computation separates the real part and the imaginary parts of the
+values.
+The returned number of digits is the minimum of the number of digits for the
+real and imaginary parts.
+ </para>
+ <para>
+TODO : use computedigits inside a assert_digits ( computed , expected , dmin ) function
+ </para>
+ <para>
+TODO : add a comptype option to make the comparison "matrix" (current is "element")
+ </para>
+ <para>
+</para>
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+d = assert_computedigits ( 1 , 1 ) // d ~ 16
+d = assert_computedigits ( 1 , 1 , 2 ) // d = 53
+d = assert_computedigits ( 0 , 0 ) // d ~ 16
+d = assert_computedigits ( 1 , 0 ) // d = 0
+d = assert_computedigits ( 0 , 1 ) // d = 0
+d = assert_computedigits ( 3.1415926 , %pi ) // d ~ 8
+d = assert_computedigits ( 3.1415926 , %pi , 2 ) // d ~ 26
+d = assert_computedigits ( [0 0 1 1] , [0 1 0 1] ) // d ~ [16 0 0 16]
+d = assert_computedigits(ones(3,2),ones(3,2)) // d ~ 16 * ones(3,2)
+d = assert_computedigits(1.224646799D-16,8.462643383D-18) // d = 0
+
+// Check IEEE values
+// d ~ [16 0 0 0]
+d = assert_computedigits([%nan %nan %nan %nan],[%nan %inf -%inf 0])
+// d ~ [0 16 0 0]
+d = assert_computedigits([%inf %inf %inf %inf],[%nan %inf -%inf 0])
+// d = [0 0 16 0]
+d = assert_computedigits([-%inf -%inf -%inf -%inf],[%nan %inf -%inf 0])
+// d = [0 0 0 16]
+d = assert_computedigits([0 0 0 0],[%nan %inf -%inf 0])
+
+// Check complex values
+d = assert_computedigits ( 1.2345 + %i*6.7891 , 1.23456789 + %i*6.789123456 ) // d ~ 4
+
+ ]]></programlisting>
+</refsection>
+
+<refsection>
+ <title>Authors</title>
+ <simplelist type="vert">
+ <member>Copyright (C) 2009 - 2011 - DIGITEO - Michael Baudin</member>
+ </simplelist>
+</refsection>
+</refentry>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ *
+ * Copyright (C) 2011 - DIGITEO - Michael Baudin
+ *
+ -->
+
+<refentry version="5.0-subset Scilab" xml:id="assert_cond2reltol" xml:lang="en"
+ xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns:ns3="http://www.w3.org/1999/xhtml"
+ xmlns:mml="http://www.w3.org/1998/Math/MathML"
+ xmlns:db="http://docbook.org/ns/docbook">
+
+
+ <refnamediv>
+ <refname>assert_cond2reltol</refname><refpurpose>Suggests a relative error, computed from the condition number.</refpurpose>
+ </refnamediv>
+
+
+
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ rtol = assert_cond2reltol ( condition )
+ rtol = assert_cond2reltol ( condition , offset )
+
+ </synopsis>
+</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>condition :</term>
+ <listitem><para> a matrix of doubles, the condition number. The condition number must be strictly positive.</para></listitem></varlistentry>
+ <varlistentry><term>offset :</term>
+ <listitem><para> a matrix of doubles, a shift for the number of required decimal digits (default offset=0). For example, offset=1 increases the accuracy requirement (decreases the relative tolerance by a factor 10^-1), offset=-1 decreases the accuracy requirement (increases the relative tolerance by a factor 10^1).</para></listitem></varlistentry>
+ <varlistentry><term>rtol :</term>
+ <listitem><para> a matrix of doubles, the relative tolerance. The relative tolerance is strictly positive, lower than 1.</para></listitem></varlistentry>
+ </variablelist>
+</refsection>
+
+<refsection>
+ <title>Description</title>
+ <para>
+Depending on the condition number, returns the corresponding relative tolerance.
+ </para>
+ <para>
+Any optional parameter equal to the empty matrix [] is set to its default value.
+ </para>
+ <para>
+We emphasize that this relative tolerance is only a suggestion.
+Indeed, there may be correct reasons of using a lower or a higher relative tolerance.
+ </para>
+ <para>
+<itemizedlist>
+<listitem>
+Consider the case where an excellent algorithm is able to make accurate computations,
+even for an ill-conditionned problem.
+In this case, we may require more accuracy (positive offset).
+</listitem>
+<listitem>
+Consider the case where there is a trade-off between performance and accuracy, where performance wins.
+In this case, we may require less accuracy (negative offset).
+</listitem>
+</itemizedlist>
+ </para>
+ <para>
+Any scalar input argument is expanded to a matrix of doubles of the same size as the other input arguments.
+ </para>
+ <para>
+We compute the number of required digits d, then the relative tolerance is 10^-d.
+ </para>
+ <para>
+</para>
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+assert_cond2reltol ( 0 ) // 1.110D-16
+assert_cond2reltol ( 1 ) // 1.110D-16
+assert_cond2reltol ( 1.e1 ) // 1.110D-15
+assert_cond2reltol ( 1.e2 ) // 1.110D-14
+assert_cond2reltol ( 1.e3 ) // 1.110D-13
+assert_cond2reltol ( 1.e16 ) // 1
+assert_cond2reltol ( 1.e17 ) // 1
+assert_cond2reltol ( 1.e18 ) // 1
+
+// Matrix input.
+condition = [0,1,10,100,1000,1.D13,1.D14,1.D15,1.D16,1.D17,1.D18];
+expected = [1.110D-16 1.110D-16 1.110D-15 1.110D-14 1.110D-13 0.0011102 0.0111022 0.1110223 1. 1. 1.];
+assert_cond2reltol ( condition )
+
+// Using offset
+// Negative offset : require less accuracy
+assert_cond2reltol ( 1.e2 , [0 -1] ) // [1.1D-14 1.1D-13]
+// Positive offset : requires more accuracy
+// See that the impact of offset is constrained.
+assert_cond2reltol ( 1.e2 , [0 1 2 3] ) // [1.1D-14 1.1D-15 1.1D-16 1.1D-16]
+// Negative offset
+// See that the impact of offset is constrained.
+assert_cond2reltol ( 1.e14 , [0 -1 -2 -3] ) // [1.1D-02 1.1D-01 1 1]
+
+// Plot the relative tolerance depending on the condition
+condition = logspace(0,18,1000);
+r = assert_cond2reltol ( condition );
+plot(condition,r)
+h=gcf();
+h.children.log_flags="lln";
+h.children.children.children.thickness=4;
+xt = h.children.x_ticks;
+xt.locations = 10^(0:2:18)';
+xt.labels = ["10^0";"10^2";"10^4";"10^6";"10^8";"10^10";"10^12";"10^14";"10^16";"10^18"];
+h.children.x_ticks=xt;
+yt = h.children.y_ticks;
+yt.locations = 10^-(0:2:18)';
+yt.labels = ["10^0";"10^-2";"10^-4";"10^-6";"10^-8";"10^-10";"10^-12";"10^-14";"10^-16";"10^-18"];
+h.children.y_ticks=yt;
+xtitle("Relative tolerance","Condition","Relative tolerance");
+r = assert_cond2reltol ( condition , +3 );
+plot(condition,r,"r")
+r = assert_cond2reltol ( condition , -3 );
+plot(condition,r,"g")
+legend(["Offset=0","Offset=+3","Offset=-3"]);
+
+ ]]></programlisting>
+</refsection>
+
+<refsection>
+ <title>Authors</title>
+ <simplelist type="vert">
+ <member>Copyright (C) 2009 - 2011 - DIGITEO - Michael Baudin</member>
+ </simplelist>
+</refsection>
+</refentry>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ *
+ * Copyright (C) 2011 - DIGITEO - Michael Baudin
+ *
+ -->
+
+<refentry version="5.0-subset Scilab" xml:id="assert_cond2reqdigits" xml:lang="en"
+ xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns:ns3="http://www.w3.org/1999/xhtml"
+ xmlns:mml="http://www.w3.org/1998/Math/MathML"
+ xmlns:db="http://docbook.org/ns/docbook">
+
+
+ <refnamediv>
+ <refname>assert_cond2reqdigits</refname><refpurpose>Suggests the number of required digits, given the condition number.</refpurpose>
+ </refnamediv>
+
+
+
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ d = assert_cond2reqdigits ( condition )
+ d = assert_cond2reqdigits ( condition , offset )
+ d = assert_cond2reqdigits ( condition , offset , b )
+
+ </synopsis>
+</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>condition :</term>
+ <listitem><para> a matrix of doubles, the condition number. The condition number must be strictly positive.</para></listitem></varlistentry>
+ <varlistentry><term>offset :</term>
+ <listitem><para> a matrix of doubles, a shift for the number of required base-b digits (default offset=0). For example, offset=-1 produces a smaller number of required digits (reduces the required accuracy), offset=1 produces a larger number of required digits (increases the required accuracy).</para></listitem></varlistentry>
+ <varlistentry><term>b :</term>
+ <listitem><para> a matrix of floating point integers, the b (default b = 10).</para></listitem></varlistentry>
+ <varlistentry><term>d :</term>
+ <listitem><para> a matrix of doubles, the number of required digits. This is a positive real, between 0 and 15.95, if b=10 or between 0 and 53, if b=2.</para></listitem></varlistentry>
+ </variablelist>
+</refsection>
+
+<refsection>
+ <title>Description</title>
+ <para>
+Depending on the condition number, returns the corresponding number of required decimal digits.
+ </para>
+ <para>
+Any optional parameter equal to the empty matrix [] is set to its default value.
+ </para>
+ <para>
+We emphasize that this number of required digits is only a suggestion.
+Indeed, there may be correct reasons of using a lower or a higher relative tolerance.
+ </para>
+ <para>
+<itemizedlist>
+<listitem>
+Consider the case where an excellent algorithm is able to make accurate computations,
+even for an ill-conditionned problem.
+In this case, we may require more accuracy (positive offset).
+</listitem>
+<listitem>
+Consider the case where there is a trade-off between performance and accuracy, where performance wins.
+In this case, we may require less accuracy (negative offset).
+</listitem>
+</itemizedlist>
+ </para>
+ <para>
+Any scalar input argument is expanded to a matrix of doubles of the same size as the other input arguments.
+ </para>
+ <para>
+The algorithm is the following.
+We compute the base-10 logarithm of condition, then subtract the offset.
+This number represents the expected number of lost digits.
+We project it into the interval [0,dmax], where dmax -log10(2^(-53)) is the maximum
+achievable number of accurate digits for doubles.
+We compute the number of required digits d, by difference between dmax and the number
+of lost digits.
+Then the relative tolerance is 10^-d.
+ </para>
+ <para>
+</para>
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+assert_cond2reqdigits ( 0 ) // 15.95459
+assert_cond2reqdigits ( 1 ) // 15.95459
+assert_cond2reqdigits ( 1.e1 ) // 14.95459
+assert_cond2reqdigits ( 1.e2 ) // 13.95459
+assert_cond2reqdigits ( 1.e3 ) // 12.95459
+assert_cond2reqdigits ( 1.e16 ) // 0
+assert_cond2reqdigits ( 1.e17 ) // 0
+assert_cond2reqdigits ( 1.e18 ) // 0
+
+// Matrix input.
+condition = [0,1,10,100,1000,1.D13,1.D14,1.D15,1.D16,1.D17,1.D18];
+assert_cond2reqdigits ( condition )
+
+// Using offset
+// Netative offset : decrease number of required digits (requires less accuracy)
+assert_cond2reqdigits ( 1.e2 , [0 -1] ) // [13.95459 12.95459]
+// Positive offset : increase number of required digits (requires more accuracy)
+// See that the impact of offset is constrained.
+assert_cond2reqdigits ( 1.e2 , [0 1 2 3] ) // [13.95459 14.95459 15.95459 15.95459]
+// Netative offset (requires less accuracy)
+// See that the impact of offset is constrained.
+assert_cond2reqdigits ( 1.e14 , [0 -1 -2 -3] ) // [1.9545898 0.9545898 0. 0.]
+
+// Using base-2
+assert_cond2reqdigits ( 0 , [] , 2 ) // 53
+assert_cond2reqdigits ( 1 , [] , 2 ) // 53
+assert_cond2reqdigits ( 1.e1 , [] , 2 ) // 49.678072
+assert_cond2reqdigits ( 1.e2 , [] , 2 ) // 46.356144
+assert_cond2reqdigits ( 1.e3 , [] , 2 ) // 43.034216
+assert_cond2reqdigits ( 1.e16 , [] , 2 ) // 0
+assert_cond2reqdigits ( 1.e17 , [] , 2 ) // 0
+assert_cond2reqdigits ( 1.e18 , [] , 2 ) // 0
+
+// Plot the number of required decimal digits depending on the condition
+condition = logspace(0,18,1000);
+d = assert_cond2reqdigits ( condition );
+plot(condition,d)
+h=gcf();
+h.children.log_flags="lnn";
+h.children.children.children.thickness=4;
+xt = h.children.x_ticks;
+xt.locations = 10^(0:2:18)';
+xt.labels = ["10^0";"10^2";"10^4";"10^6";"10^8";"10^10";"10^12";"10^14";"10^16";"10^18"];
+h.children.x_ticks=xt;
+xtitle("Number of required digits","Condition","Required decimal digits");
+
+// Plot the number of required binary digits depending on the condition
+condition = logspace(0,18,1000);
+d = assert_cond2reqdigits ( condition , [] , 2 );
+plot(condition,d)
+h=gcf();
+h.children.log_flags="lnn";
+h.children.children.children.thickness=4;
+xt = h.children.x_ticks;
+xt.locations = 10^(0:2:18)';
+xt.labels = ["10^0";"10^2";"10^4";"10^6";"10^8";"10^10";"10^12";"10^14";"10^16";"10^18"];
+h.children.x_ticks=xt;
+xtitle("Number of required digits","Condition","Required binary digits");
+d = assert_cond2reqdigits ( condition , +10 , 2 );
+plot(condition,d,"r")
+d = assert_cond2reqdigits ( condition , -10 , 2 );
+plot(condition,d,"g")
+legend(["Offset=0","Offset=+10","Offset=-10"]);
+
+ ]]></programlisting>
+</refsection>
+
+<refsection>
+ <title>Authors</title>
+ <simplelist type="vert">
+ <member>Copyright (C) 2009 - 2011 - DIGITEO - Michael Baudin</member>
+ </simplelist>
+</refsection>
+</refentry>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ *
+ * Copyright (C) 2011 - DIGITEO - Michael Baudin
+ *
+ -->
+
+<refentry version="5.0-subset Scilab" xml:id="assert_generror" xml:lang="en"
+ xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns:ns3="http://www.w3.org/1999/xhtml"
+ xmlns:mml="http://www.w3.org/1998/Math/MathML"
+ xmlns:db="http://docbook.org/ns/docbook">
+
+
+ <refnamediv>
+ <refname>assert_generror</refname><refpurpose>Generates an error.</refpurpose>
+ </refnamediv>
+
+
+
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ assert_generror ( errormsg )
+ assert_generror ( errormsg , errornb )
+
+ </synopsis>
+</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>expectedmsg :</term>
+ <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>
+ </variablelist>
+</refsection>
+
+<refsection>
+ <title>Description</title>
+ <para>
+Calls the error function, with the given arguments.
+ </para>
+ <para>
+This function is called by the assert_check* function each time an error
+produced by the wrong match between expected and computed outputs is generated.
+In the case where a assert_check* function receives a wrong number of input arguments,
+a wrong number of ouput arguments, a wrong type of input argument or a wrong content
+of input arguments, the regular error function is called.
+This function can be customized to modify the behaviour of the assert_check* functions.
+ </para>
+ <para>
+</para>
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+// Both these calls generate an error
+assert_generror ( "oups" );
+assert_generror ( "oups" , 123456789 );
+
+// The following call generates an error.
+assert_checktrue ( [%t %f] );
+//
+// Define our own error handler
+function myerror ( varargin )
+[lhs,rhs]=argn()
+errormsg = varargin(1)
+if ( rhs == 1 ) then
+mprintf( "myerror: %s\n", errormsg )
+else
+errornb = varargin(2)
+mprintf( "myerror: %s (%d)\n", errormsg , errornb )
+end
+endfunction
+//
+// Configure the new error handler
+back=funcprot();
+funcprot(0);
+olderrorfunction = assert_generror;
+assert_generror = myerror;
+funcprot(back);
+//
+// Check that the new error handler is in place
+assert_checktrue ( [%t %f] );
+//
+// Put back the regular error handler in place
+back=funcprot();
+funcprot(0);
+assert_generror = olderrorfunction;
+funcprot(back);
+
+ ]]></programlisting>
+</refsection>
+
+<refsection>
+ <title>Authors</title>
+ <simplelist type="vert">
+ <member>Copyright (C) 2010 - 2011 - DIGITEO - Michael Baudin</member>
+ </simplelist>
+</refsection>
+</refentry>
--- /dev/null
+// Copyright (C) 2008 - 2009 - INRIA - Michael Baudin
+// Copyright (C) 2009 - 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+function [flag,errmsg] = assert_checkalmostequal ( varargin )
+ // Check that computed and expected are numerically close.
+
+ [lhs,rhs]=argn()
+ if ( and(rhs <> [2 3 4 5] ) ) then
+ errmsg = sprintf ( gettext ( "%s: Wrong number of input arguments: %d to %d expected.") , "assert_checkalmostequal" , 2 , 5 )
+ error(errmsg)
+ end
+ //
+ // Get arguments
+ computed = varargin(1)
+ expected = varargin(2)
+ reltol = argindefault ( rhs , varargin , 3 , sqrt(%eps) )
+ abstol = argindefault ( rhs , varargin , 4 , 0 )
+ comptype = argindefault ( rhs , varargin , 5 , "matrix" )
+ //
+ // Check types of variables
+ if ( typeof(computed) <> "constant" ) then
+ 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: Wrong type for argument %d: Matrix expected.\n") , "assert_checkalmostequal" , 2 )
+ error(errmsg)
+ end
+ if ( typeof(reltol) <> "constant" ) then
+ 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: Wrong type for argument %d: Matrix expected.\n") , "assert_checkalmostequal" , 4 )
+ error(errmsg)
+ end
+ if ( typeof(comptype) <> "string" ) then
+ 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: 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: 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: 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: 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: 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: Wrong value for input argument #%d: Must be in the set {%s}.\n") , "assert_checkalmostequal" , 5 , """matrix"",""element""" )
+ error(errmsg)
+ end
+ //
+ // Proceed...
+ ncom = size(computed)
+ nexp = size(expected)
+ if ( or(ncom <> nexp) ) then
+ errmsg = sprintf ( gettext ( "%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n" ) , "assert_checkalmostequal" , 1 , 2 )
+ error(errmsg)
+ end
+ //
+ areequal_re = assert_arealmostequal ( real(computed) , real(expected) , reltol , abstol , comptype )
+ if ( areequal_re ) then
+ areequal = assert_arealmostequal ( imag(computed) , imag(expected) , reltol , abstol , comptype )
+ else
+ areequal = %f
+ end
+ //
+ if ( areequal ) then
+ flag = %t
+ errmsg = ""
+ else
+ flag = %f
+ // Change the message if the matrix contains more than one value
+ if ( size(expected,"*") == 1 ) then
+ estr = string(expected)
+ else
+ estr = "[" + string(expected(1)) + " ...]"
+ end
+ if ( size(computed,"*") == 1 ) then
+ cstr = string(computed)
+ else
+ cstr = "[" + string(computed(1)) + " ...]"
+ end
+ relstr = string(reltol)
+ absstr = string(abstol)
+ 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
+
+// Returns the indices where
+// * kpinf : x(kpinf) == +%inf,
+// * kninf : x(kninf) == -%inf,
+// * knan : x(knan) is a %nan
+// * kreg : x(kreg) is not an infinity, not a nan
+// * xreg = x(kreg)
+// These 4 sets of indices have no intersection.
+//
+// Example :
+// x = [1 2 3 -%inf %inf %nan %inf %nan -%inf 4 5 6]
+// [kpinf , kninf , knan , kreg , xreg] = infnanindices ( x )
+// xreg = [1 2 3 4 5 6]
+// kreg = [1 2 3 10 11 12]
+// knan = [6 8]
+// kninf = [4 9]
+// kpinf = [5 7]
+function [kpinf , kninf , knan , kreg , xreg] = infnanindices ( x )
+ kpinf = find(x==%inf)
+ kninf = find(x==-%inf)
+ knan = find(isnan(x))
+ kreg = find(abs(x)<>%inf & ~isnan(x))
+ xreg = x(kreg)
+endfunction
+
+
+function areequal = assert_arealmostequal ( computed , expected , reltol , abstol , comptype )
+ //
+ // Decompose the expected value into nan indices, inf indices and regular indices
+ // This allows to solve the following issue:
+ // if computed is %inf and expected is %inf, the difference is %nan,
+ // which makes the computations fail.
+ [kcpinf , kcninf , kcnan , kcreg , creg] = infnanindices ( computed )
+ [kepinf , keninf , kenan , kereg , ereg] = infnanindices ( expected )
+ //
+ if ( comptype == "matrix" ) then
+ areclose = ( norm ( creg - ereg ) <= reltol * max(norm(ereg),norm(creg) ) + abstol )
+ else
+ entries = ( abs(creg-ereg) <= reltol * max(abs(ereg),abs(creg)) + abstol )
+ // Compute the global condition from the entries conditions
+ areclose = and(entries)
+ end
+ // The regular values must be almost equal and
+ // * the +%inf must be at the same place,
+ // * the -%inf must be at the same place,
+ // * the %nan must be at the same place.
+ areequal = ( areclose & and(kcpinf == kepinf) & and(kcninf == keninf) & and(kcnan == kenan) )
+endfunction
+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.
+ if ( rhs < ivar ) then
+ argin = default
+ else
+ if ( vararglist(ivar) <> [] ) then
+ argin = vararglist(ivar)
+ else
+ argin = default
+ end
+ end
+endfunction
+
--- /dev/null
+// Copyright (C) 2008-2009 - INRIA - Michael Baudin
+// Copyright (C) 2010 - 2011 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+function [flag,errmsg] = assert_checkequal ( computed , expected )
+ // Check that computed and expected are equal.
+
+ function flag = comparedoubles ( computed , expected )
+ [cnonan , cnumb] = mythrownan(computed)
+ [enonan , enumb] = mythrownan(expected)
+ if ( and(enonan == cnonan) & and(enumb == cnumb) ) then
+ flag = %t
+ else
+ flag = %f
+ end
+ endfunction
+
+ function [nonan,numb] = mythrownan(x)
+ //
+ //
+ // Copyright (C) 2000 - INRIA - Carlos Klimann
+ // 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
+ //value.
+ //
+ //For a vector or matrix x, [nonan,numb]=thrownan(x)
+ //considers x, whatever his dimensions are, like a linear
+ //vector (columns first).
+ //
+ //
+ [lhs,rhs]=argn(0)
+ if ( rhs<>1 ) then
+ error(msprintf(gettext("%s: Wrong number of input argument: %d expected.\n"),"thrownan",1))
+ end
+ numb=find(bool2s(~isnan(x)))
+ nonan=x(~isnan(x))
+ endfunction
+
+ [lhs,rhs]=argn()
+ if ( rhs <> 2 ) then
+ 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: Incompatible input arguments #%d and #%d: Same types expected.\n" ) , "assert_checkequal" , 1 , 2 )
+ error(errmsg)
+ end
+ //
+ // Check sizes of variables
+ ncom = size(computed)
+ nexp = size(expected)
+ if ( or(ncom <> nexp) ) then
+ errmsg = sprintf ( gettext ( "%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n") , "assert_checkequal" , 1 , 2 )
+ error(errmsg)
+ end
+ //
+ if ( type(computed) == 1 & type(expected) == 1 ) then
+ // These are two matrices of doubles
+ cisreal = isreal(computed)
+ eisreal = isreal(expected)
+ if ( cisreal & ~eisreal ) then
+ errmsg = sprintf ( gettext ( "%s: Computed is real, but expected is complex.") , "assert_checkequal" )
+ error(errmsg)
+ end
+ if ( ~cisreal & eisreal ) then
+ errmsg = sprintf ( gettext ( "%s: Computed is complex, but expected is real.") , "assert_checkequal" )
+ error(errmsg)
+ end
+ if ( cisreal & eisreal ) then
+ flag = comparedoubles ( computed , expected )
+ else
+ flagreal = comparedoubles ( real(computed) , real(expected) )
+ if ( flagreal ) then
+ flagimag = comparedoubles ( imag(computed) , imag(expected) )
+ flag = flagimag
+ else
+ flag = %f
+ end
+ end
+ else
+ if ( and ( computed == expected ) ) then
+ flag = %t
+ else
+ flag = %f
+ end
+ end
+ if ( flag == %t ) then
+ errmsg = ""
+ else
+ // Change the message if the matrix contains more than one value
+ if ( size(expected,"*") == 1 ) then
+ estr = string(expected)
+ else
+ estr = "[" + string(expected(1)) + " ...]"
+ end
+ if ( size(computed,"*") == 1 ) then
+ cstr = string(computed)
+ else
+ cstr = "[" + string(computed(1)) + " ...]"
+ end
+ 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
+ end
+endfunction
+
+
--- /dev/null
+// Copyright (C) 2010 - 2011 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+function [flag,errmsg] = assert_checkerror ( varargin )
+ // Check that an instruction produces the expected error.
+
+ [lhs,rhs]=argn()
+ if ( and(rhs <> [2 3] ) ) then
+ errmsg = sprintf ( gettext ( "%s: Wrong number of input arguments: %d to %d expected.") , "assert_checkerror" , 2 , 3 )
+ error(errmsg)
+ end
+ //
+ // Get arguments
+ instr = varargin(1)
+ expectedmsg = varargin(2)
+ expectederrnb = argindefault ( rhs , varargin , 3 , [] )
+ //
+ // Check types of variables
+ if ( typeof(instr) <> "string" ) then
+ errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix of strings expected.\n") , "assert_checkerror" , 1 )
+ error(errmsg)
+ end
+ if ( typeof(expectedmsg) <> "string" ) then
+ errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix of strings expected.\n") , "assert_checkerror" , 2 )
+ error(errmsg)
+ end
+ if ( typeof(expectederrnb) <> "constant" ) then
+ errmsg = sprintf ( gettext ( "%s: Wrong type for argument %d: Matrix expected.\n") , "assert_checkerror" , 3 )
+ error(errmsg)
+ end
+ //
+ // Check sizes of variables
+ if ( size(instr,"*") <> 1 ) then
+ errmsg = sprintf ( gettext ( "%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n") , "assert_checkerror" , 1 , 1 , 1 )
+ error(errmsg)
+ end
+ if ( size(expectedmsg,"*") <> 1 ) then
+ errmsg = sprintf ( gettext ( "%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n") , "assert_checkerror" , 2 , 1 , 1 )
+ error(errmsg)
+ end
+ if ( expectederrnb <> [] ) then
+ if ( size(expectederrnb,"*") <> 1 ) then
+ errmsg = sprintf ( gettext ( "%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n") , "assert_checkerror" , 3 , 1 , 1 )
+ error(errmsg)
+ end
+ end
+ //
+ // Check values of variables
+ if ( expectederrnb <> [] ) then
+ if ( expectederrnb < 0 ) then
+ errmsg = sprintf ( gettext ( "%s: Wrong value for input argument #%d: Non-negative integers expected.\n" ) , "assert_checkerror" , 3 )
+ error(errmsg)
+ end
+ end
+ //
+ // Proceed...
+ compierr = execstr(instr,"errcatch")
+ //
+ // Check that an error is produced
+ if ( compierr == 0 ) then
+ localstr = gettext ( "%s: No error was produced while evaluating ""%s"".")
+ errmsg = sprintf ( localstr , "assert_checkerror" , instr )
+ error(errmsg)
+ end
+ //
+ // Get the error
+ compmsg = lasterror()
+ //
+ // Initialize output arguments
+ flag = %t
+ errmsg = ""
+ //
+ // Check the error message
+ if ( expectedmsg <> compmsg ) then
+ flag = %f
+ localstr = gettext("%s: Assertion failed: expected error message = ""%s"" while computed error message = ""%s"".")
+ errmsg = msprintf(localstr,"assert_checkerror",expectedmsg,compmsg)
+ if ( lhs < 2 ) then
+ // If no output variable is given, generate an error
+ error ( errmsg )
+ else
+ return
+ end
+ end
+ if ( expectederrnb <> [] ) then
+ //
+ // Check the error number
+ if ( expectederrnb <> compierr ) then
+ flag = %f
+ localstr = gettext("%s: Assertion failed: expected error number = %d while computed error number = %d.")
+ errmsg = msprintf(localstr,"assert_checkerror",expectederrnb,compierr)
+ if ( lhs < 2 ) then
+ // If no output variable is given, generate an error
+ error ( errmsg )
+ else
+ return
+ end
+ end
+ end
+endfunction
+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.
+ if ( rhs < ivar ) then
+ argin = default
+ else
+ if ( vararglist(ivar) <> [] ) then
+ argin = vararglist(ivar)
+ else
+ argin = default
+ end
+ end
+endfunction
+
--- /dev/null
+// Copyright (C) 2008-2009 - INRIA - Michael Baudin
+// Copyright (C) 2010 - 2011 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+function [flag,errmsg] = assert_checkfalse ( condition )
+ // Check that condition is false.
+
+ [lhs,rhs]=argn()
+ if ( rhs <> 1 ) then
+ 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: Wrong type for argument %d: Boolean matrix expected.\n") , "assert_checkfalse" , 1 )
+ error(errmsg)
+ end
+ //
+ if ( and(~condition) ) then
+ flag = %t
+ errmsg = ""
+ else
+ flag = %f
+ if ( size(condition,"*") == 1 ) then
+ cstr = string(condition)
+ else
+ cstr = "[" + string(condition(1)) + " ...]"
+ end
+ errmsg = msprintf(gettext("%s: Assertion failed: found false entry in condition = %s"), ..
+ "assert_checkfalse",cstr)
+ if ( lhs < 2 ) then
+ // If no output variable is given, generate an error
+ assert_generror ( errmsg )
+ end
+ end
+endfunction
+
--- /dev/null
+// Copyright (C) 2008-2009 - INRIA - Michael Baudin
+// Copyright (C) 2010 - 2011 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+function [flag,errmsg] = assert_checkfilesequal ( varargin )
+ // Check two files are equal.
+
+ [lhs,rhs]=argn()
+ if ( and ( rhs <> [ 2 3 ] ) ) then
+ errmsg = sprintf ( gettext ( "%s: Wrong number of input arguments: %d to %d expected.") , "assert_checkfilesequal" , 2 , 3 )
+ error(errmsg)
+ end
+ //
+ // Get input arguments
+ filecomp = varargin(1)
+ fileref = varargin(2)
+ if ( rhs <= 2 ) then
+ compfun = []
+ else
+ compfun = varargin(3)
+ end
+ //
+ // Check types of variables
+ if ( typeof(filecomp) <> "string" ) then
+ 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: Wrong type for argument %d: Matrix of strings expected.\n") , "assert_checkfilesequal" , 2 )
+ error(errmsg)
+ end
+ if ( compfun <> [] ) then
+ if ( and ( typeof(compfun) <> [ "function" "list" ] ) ) then
+ errmsg = sprintf ( gettext ( "%s: Expected type ""%s"" or ""%s"" for input argument %s #%d, but got %s instead.") , "assert_checkfilesequal" , "function" , "list" , "compfun" , 3 , typeof(compfun) )
+ error(errmsg)
+ end
+ end
+ //
+ // Check sizes of variables
+ if ( size(filecomp,"*") <> 1 ) then
+ 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: %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: The file %s does not exist.\n") , "assert_checkfilesequal" , filecomp )
+ if ( lhs < 2 ) then
+ assert_generror ( errmsg )
+ else
+ return
+ end
+ end
+ if ( fileinfo(fileref) == [] ) then
+ flag = %f
+ errmsg = sprintf ( gettext ( "%s: The file %s does not exist.\n") , "assert_checkfilesequal" , fileref )
+ if ( lhs < 2 ) then
+ assert_generror ( errmsg )
+ else
+ return
+ end
+ end
+ //
+ // Open files
+ [fdc,err] = mopen(filecomp,"r")
+ if ( err <> 0 ) then
+ flag = %f
+ errmsg = sprintf ( gettext ( "%s: Cannot open file %s.\n") , "assert_checkfilesequal" , filecomp )
+ if ( lhs < 2 ) then
+ assert_generror ( errmsg )
+ else
+ return
+ end
+ end
+ [fdr,err] = mopen(fileref,"r")
+ if ( err <> 0 ) then
+ flag = %f
+ errmsg = sprintf ( gettext ( "%s: Cannot open file %s.\n") , "assert_checkfilesequal" , fileref )
+ if ( lhs < 2 ) then
+ assert_generror ( errmsg )
+ else
+ return
+ end
+ end
+ //
+ // Get contents
+ txtcomp = mgetl(fdc)
+ txtref = mgetl(fdr)
+ //
+ // Compare contents
+ if ( compfun <> [] ) then
+ if ( typeof(compfun) == "function" ) then
+ areeq = compfun ( txtcomp , txtref )
+ else
+ // compfun is a list
+ cf = compfun(1)
+ areeq = cf ( txtcomp , txtref , compfun(2:$) )
+ end
+ else
+ areeq = ( txtcomp == txtref )
+ end
+ if ( areeq ) then
+ flag = %t
+ errmsg = ""
+ else
+ flag = %f
+ errmsg = msprintf(gettext("%s: The content of computed file ""%s"" is different from the content of reference file ""%s""."), ..
+ "assert_checkfilesequal",filecomp,fileref)
+ // Do not generate the error now: let us close the files before!
+ end
+ //
+ // Close the files
+ err=mclose(fdc)
+ if ( err <> 0 ) then
+ flag = %f
+ 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: 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,
+ end
+
+ if ( ~flag & lhs < 2 ) then
+ // If no output variable is given, generate an error
+ assert_generror ( errmsg )
+ end
+endfunction
+
--- /dev/null
+// Copyright (C) 2008-2009 - INRIA - Michael Baudin
+// Copyright (C) 2010 - 2011 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+function [flag,errmsg] = assert_checktrue ( condition )
+ // Check that condition is true.
+
+ [lhs,rhs]=argn()
+ if ( rhs <> 1 ) then
+ 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: Wrong type for argument %d: Boolean matrix expected.\n" ) , "assert_checktrue" , 1 )
+ error(errmsg)
+ end
+ //
+ if ( and(condition) ) then
+ flag = %t
+ errmsg = ""
+ else
+ flag = %f
+ if ( size(condition,"*") == 1 ) then
+ cstr = string(condition)
+ else
+ cstr = "[" + string(condition(1)) + " ...]"
+ end
+ errmsg = msprintf(gettext("%s: Assertion failed: found false entry in condition = %s"), ..
+ "assert_checktrue",cstr)
+ if ( lhs < 2 ) then
+ // If no output variable is given, generate an error
+ assert_generror ( errmsg )
+ end
+ end
+endfunction
+
--- /dev/null
+// Copyright (C) 2008-2009 - INRIA - Michael Baudin
+// Copyright (C) 2010 - 2011 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+function order = assert_comparecomplex ( varargin )
+ // Compare complex numbers with a tolerance.
+
+ [lhs,rhs]=argn()
+ if ( and(rhs <> [2 3 4] ) ) then
+ errmsg = sprintf ( gettext ( "%s: Wrong number of input arguments: %d to %d expected.") , "assert_comparecomplex" , 2 , 4 )
+ error(errmsg)
+ end
+ //
+ // Get arguments
+ a = varargin(1)
+ b = varargin(2)
+ reltol = argindefault ( rhs , varargin , 3 , sqrt(%eps) )
+ abstol = argindefault ( rhs , varargin , 4 , 0 )
+ //
+ // Check types of variables
+ if ( typeof(a) <> "constant" ) then
+ 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: Wrong type for argument %d: Matrix expected.\n") , "assert_comparecomplex" , 2 )
+ error(errmsg)
+ end
+ if ( typeof(reltol) <> "constant" ) then
+ 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: 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: 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: 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: 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: 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: 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: Wrong value for input argument #%d: Must be > %d.\n") , "assert_comparecomplex" , 4 , 0 )
+ error(errmsg)
+ end
+ //
+ ord_re = assert_compdata ( real(a) , real(b) , reltol , abstol )
+ if ( ord_re == 0 ) then
+ // Tie on the real part: compare imaginary parts
+ ord_im = assert_compdata ( imag(a) , imag(b) , reltol , abstol )
+ if ( ord_im == 0 ) then
+ // Tie on imaginary parts too: two numbers are "equal"
+ order = 0
+ elseif ( ord_im == -1 ) then
+ order = -1
+ else
+ order = 1
+ end
+ elseif ( ord_re == -1 ) then
+ order = -1
+ else
+ order = 1
+ end
+endfunction
+
+function order = assert_compdata ( a , b , reltol , abstol )
+ if ( a == %inf ) then
+ if ( isnan(b) ) then
+ order = -1
+ elseif ( b == %inf ) then
+ order = 0
+ else
+ order = 1
+ end
+ elseif ( a == -%inf ) then
+ if ( b == -%inf ) then
+ order = 0
+ else
+ order = -1
+ end
+ elseif ( isnan(a) ) then
+ if ( isnan(b) ) then
+ order = 0
+ else
+ order = 1
+ end
+ else
+ if ( isnan(b) ) then
+ order = -1
+ elseif ( b == -%inf ) then
+ order = 1
+ elseif ( b == %inf ) then
+ order = -1
+ else
+ areequal = abs ( a - b ) <= reltol * max ( abs(a) , abs(b) ) + abstol
+ if ( areequal ) then
+ order = 0
+ elseif ( a < b ) then
+ order = -1
+ else
+ order = 1
+ end
+ end
+ end
+endfunction
+
+
+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.
+ if ( rhs < ivar ) then
+ argin = default
+ else
+ if ( vararglist(ivar) <> [] ) then
+ argin = vararglist(ivar)
+ else
+ argin = default
+ end
+ end
+endfunction
+
--- /dev/null
+// Copyright (C) 2008-2009 - INRIA - Michael Baudin
+// Copyright (C) 2010 - 2011 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+function d = assert_computedigits ( varargin )
+ // Returns the number of significant digits in computed result.
+
+ [lhs,rhs]=argn()
+ if ( and ( rhs <> [2 3] ) ) then
+ errmsg = sprintf ( gettext ( "%s: Wrong number of input arguments: %d to %d expected.\n") , "assert_computedigits" , 2 , 3 )
+ error(errmsg)
+ end
+ computed = varargin ( 1 )
+ expected = varargin ( 2 )
+ basis = argindefault ( rhs , varargin , 3 , 10 )
+ //
+ // Check types of variables
+ if ( typeof(computed) <> "constant" ) then
+ 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: 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: 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: Wrong size for input argument #%d: %d-by-%d matrix expected.\n") , "assert_computedigits" , 3 , 1 , 1 )
+ error(errmsg)
+ end
+ //
+ nre = size(expected,"r")
+ nce = size(expected,"c")
+ // Update shape
+ expected = expected (:)
+ computed = computed (:)
+ //
+ d = zeros(expected)
+ //
+ n = size(expected,"*")
+ for i = 1 : n
+ dre = computedigits_data ( real(expected(i)) , real(computed(i)) , basis )
+ dim = computedigits_data ( imag(expected(i)) , imag(computed(i)) , basis )
+ d(i) = min(dre,dim)
+ end
+ //
+ // Reshape
+ d = matrix(d,nre,nce)
+endfunction
+
+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.
+ if ( rhs < ivar ) then
+ argin = default
+ else
+ if ( vararglist(ivar) <> [] ) then
+ argin = vararglist(ivar)
+ else
+ argin = default
+ end
+ end
+endfunction
+function d = computedigits_data ( expected , computed , basis )
+ dmin = 0
+ dmax = -log(2^(-53))/log(basis)
+ //
+ if ( isnan(expected) & isnan(computed) ) then
+ d = dmax
+ elseif ( isnan(expected) & ~isnan(computed) ) then
+ d = dmin
+ elseif ( ~isnan(expected) & isnan(computed) ) then
+ d = dmin
+ // From now, both expected and computed are non-nan
+ elseif ( expected == 0 & computed == 0 ) then
+ d = dmax
+ elseif ( expected == 0 & computed <> 0 ) then
+ d = dmin
+ // From now, expected is non-zero
+ elseif ( expected == computed ) then
+ d = dmax
+ // From now, expected and computed are different
+ elseif ( expected == %inf & computed <> %inf ) then
+ d = dmin
+ elseif ( expected == -%inf & computed <> -%inf ) then
+ d = dmin
+ // From now, neither of computed, nor expected is infinity
+ else
+ // The max function does not ensure that the sign bit of d is positive.
+ // For example :
+ // ieee(2); z=max(-0,0); 1/z is -%inf
+ // To force this, consider the special case where the relative error is
+ // larger than 1.
+ relerr = abs(computed-expected) / abs(expected)
+ if ( relerr >= 1 ) then
+ d = dmin
+ else
+ sigdig = -log ( relerr ) / log(basis)
+ d = max ( sigdig , dmin )
+ end
+ end
+endfunction
+
--- /dev/null
+// Copyright (C) 2010 - 2011 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+function rtol = assert_cond2reltol ( varargin )
+ // Suggests a relative error, computed from the condition number.
+
+ function varargout = assert_expandvar ( varargin )
+ // Expand variables so that they all have the same shape.
+ //
+ // Calling Sequence
+ // ovar1 = assert_expandvar ( ivar1 )
+ // [ ovar1 , ovar2 ] = assert_expandvar ( ivar1 , ivar2 )
+ // [ ovar1 , ovar2 , ovar3 ] = assert_expandvar ( ivar1 , ivar2 , ivar3 )
+ // [ ovar1 , ovar2 , ovar3 , ovar4 ] = assert_expandvar ( ivar1 , ivar2 , ivar3 , ivar4 )
+ //
+ // Parameters
+ // ivar1 : input variable #1
+ // ovar1 : output variable #1
+ //
+ // Description
+ // This function allows to expand input arguments of
+ // computationnal functions.
+ // If scalars are input, expand it to the size of other other variables.
+ //
+ // If matrices are input, all must have the same shape: if not, an error is generated.
+ //
+ // Examples
+ // // Expand ovar1 to [1 1 1]
+ // [ ovar1 , ovar2 ] = assert_expandvar ( 1 , [2 3 4] )
+ //
+ // // Expand ovar2 to [4 4 4]
+ // [ ovar1 , ovar2 ] = assert_expandvar ( [1 2 3] , 4 )
+ //
+ // // Expand ovar2 to [4 4 4]'
+ // [ ovar1 , ovar2 ] = assert_expandvar ( [1 2 3]' , 4 )
+ //
+ // Authors
+ // Michael Baudin - 2009-2010 - DIGITEO
+
+ [lhs,rhs]=argn()
+ if ( rhs <> lhs ) then
+ errmsg = sprintf ( gettext ( "%s: The number of output arguments %d do not match the number of input arguments %d.") , "assert_expandvar" , lhs , rhs )
+ error(errmsg)
+ end
+
+ //
+ // Check if there is one argument which is a matrix.
+ // imat is the index of the input argument which is a matrix.
+ istherematrix = %f
+ imat = 0
+ for ivar = 1 : rhs
+ if ( size ( varargin(ivar) , "*" ) <> 1 ) then
+ istherematrix = %t
+ imat = ivar
+ break
+ end
+ end
+ // If there is no matrix, returns the output arguments as is.
+ if ( ~istherematrix ) then
+ for ovar = 1 : lhs
+ varargout ( ovar ) = varargin ( ovar )
+ end
+ return
+ end
+ // If there is one matrix, get its size.
+ nbrows = size ( varargin ( imat ) , "r" )
+ nbcols = size ( varargin ( imat ) , "c" )
+ // Check that all matrices have the same shape.
+ for ivar = 1 : rhs
+ nbi = size ( varargin ( ivar ) , "*" )
+ if ( nbi <> 1 ) then
+ nbrowsi = size ( varargin ( ivar ) , "r" )
+ nbcolsi = size ( varargin ( ivar ) , "c" )
+ if ( nbrowsi <> nbrows | nbcolsi <> nbcols ) then
+ errmsg = msprintf(gettext("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), "assert_expandvar" , ivar , nbrows , nbcols );
+ error(errmsg)
+ end
+ end
+ end
+ // Expand all input arguments which are scalar up to this shape.
+ for ivar = 1 : rhs
+ if ( size ( varargin(ivar) , "*" ) == 1 ) then
+ varargin ( ivar ) = varargin ( ivar ) * ones ( nbrows , nbcols )
+ end
+ end
+ // Set all output variables
+ for ovar = 1 : lhs
+ varargout ( ovar ) = varargin ( ovar )
+ end
+ endfunction
+
+ 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.
+ if ( rhs < ivar ) then
+ argin = default
+ else
+ if ( vararglist(ivar) <> [] ) then
+ argin = vararglist(ivar)
+ else
+ argin = default
+ end
+ 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
+
--- /dev/null
+// Copyright (C) 2010 - 2011 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+function d = assert_cond2reqdigits ( varargin )
+ // Suggests the number of required digits, given the condition number.
+
+
+ function varargout = assert_expandvar ( varargin )
+ // Expand variables so that they all have the same shape.
+ //
+ // Calling Sequence
+ // ovar1 = assert_expandvar ( ivar1 )
+ // [ ovar1 , ovar2 ] = assert_expandvar ( ivar1 , ivar2 )
+ // [ ovar1 , ovar2 , ovar3 ] = assert_expandvar ( ivar1 , ivar2 , ivar3 )
+ // [ ovar1 , ovar2 , ovar3 , ovar4 ] = assert_expandvar ( ivar1 , ivar2 , ivar3 , ivar4 )
+ //
+ // Parameters
+ // ivar1 : input variable #1
+ // ovar1 : output variable #1
+ //
+ // Description
+ // This function allows to expand input arguments of
+ // computationnal functions.
+ // If scalars are input, expand it to the size of other other variables.
+ //
+ // If matrices are input, all must have the same shape: if not, an error is generated.
+ //
+ // Examples
+ // // Expand ovar1 to [1 1 1]
+ // [ ovar1 , ovar2 ] = assert_expandvar ( 1 , [2 3 4] )
+ //
+ // // Expand ovar2 to [4 4 4]
+ // [ ovar1 , ovar2 ] = assert_expandvar ( [1 2 3] , 4 )
+ //
+ // // Expand ovar2 to [4 4 4]'
+ // [ ovar1 , ovar2 ] = assert_expandvar ( [1 2 3]' , 4 )
+ //
+ // Authors
+ // Michael Baudin - 2009-2010 - DIGITEO
+
+ [lhs,rhs]=argn()
+ if ( rhs <> lhs ) then
+ errmsg = sprintf ( gettext ( "%s: The number of output arguments %d do not match the number of input arguments %d.") , "assert_expandvar" , lhs , rhs )
+ error(errmsg)
+ end
+
+ //
+ // Check if there is one argument which is a matrix.
+ // imat is the index of the input argument which is a matrix.
+ istherematrix = %f
+ imat = 0
+ for ivar = 1 : rhs
+ if ( size ( varargin(ivar) , "*" ) <> 1 ) then
+ istherematrix = %t
+ imat = ivar
+ break
+ end
+ end
+ // If there is no matrix, returns the output arguments as is.
+ if ( ~istherematrix ) then
+ for ovar = 1 : lhs
+ varargout ( ovar ) = varargin ( ovar )
+ end
+ return
+ end
+ // If there is one matrix, get its size.
+ nbrows = size ( varargin ( imat ) , "r" )
+ nbcols = size ( varargin ( imat ) , "c" )
+ // Check that all matrices have the same shape.
+ for ivar = 1 : rhs
+ nbi = size ( varargin ( ivar ) , "*" )
+ if ( nbi <> 1 ) then
+ nbrowsi = size ( varargin ( ivar ) , "r" )
+ nbcolsi = size ( varargin ( ivar ) , "c" )
+ if ( nbrowsi <> nbrows ) then
+ errmsg = msprintf(gettext("%s: Expected %d rows in input argument #%d, but found %d rows instead."), "assert_expandvar" , nbrows , ivar , nbrowsi );
+ error(errmsg)
+ end
+ if ( nbcolsi <> nbcols ) then
+ errmsg = msprintf(gettext("%s: Expected %d columns in input argument #%d, but found %d columns instead."), "assert_expandvar" , nbcols , ivar , nbcolsi );
+ error(errmsg)
+ end
+ end
+ end
+ // Expand all input arguments which are scalar up to this shape.
+ for ivar = 1 : rhs
+ if ( size ( varargin(ivar) , "*" ) == 1 ) then
+ varargin ( ivar ) = varargin ( ivar ) * ones ( nbrows , nbcols )
+ end
+ end
+ // Set all output variables
+ for ovar = 1 : lhs
+ varargout ( ovar ) = varargin ( ovar )
+ end
+ endfunction
+
+ 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.
+ if ( rhs < ivar ) then
+ argin = default
+ else
+ if ( vararglist(ivar) <> [] ) then
+ argin = vararglist(ivar)
+ else
+ argin = default
+ end
+ 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
+
--- /dev/null
+// Copyright (C) 2010 - 2011 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+function assert_generror ( varargin )
+ // Generates an error.
+
+ [lhs,rhs]=argn()
+ if ( and(rhs <> [1 2] ) ) then
+ 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: 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: Wrong size for input argument #%d: %d-by-%d matrix expected.\n") , "assert_generror" , 1 , 1 , 1 )
+ error(errmsg)
+ end
+ //
+ if ( rhs == 1 ) then
+ error ( errormsg )
+ else
+ errornb = varargin(2)
+ if ( size(errornb,"*") <> 1 ) then
+ 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: Wrong type for argument %d: Matrix expected.\n") , "assert_generror" , 2 )
+ error(errmsg)
+ end
+ if ( errornb < 0 ) then
+ 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
+
--- /dev/null
+
+rem Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+rem Copyright (C) 2008 - INRIA
+rem
+rem This file must be used under the terms of the CeCILL.
+rem This source file is licensed as described in the file COPYING, which
+rem you should have received as part of this distribution. The terms
+rem are also available at
+rem http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+@scilex -nwni -e exec('buildmacros.sce');quit;
--- /dev/null
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+tbx_build_macros("assert", get_absolute_file_path('buildmacros.sce'));
+
+clear tbx_build_macros;
--- /dev/null
+
+rem Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+rem Copyright (C) 2008 - INRIA
+rem
+rem This file must be used under the terms of the CeCILL.
+rem This source file is licensed as described in the file COPYING, which
+rem you should have received as part of this distribution. The terms
+rem are also available at
+rem http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+@rm *.bin
+@rm lib
+@rm names
+
--- /dev/null
+// ====================================================================
+// Allan CORNET
+// DIGITEO 2009
+// This file is released into the public domain
+// ====================================================================
+libpath = get_absolute_file_path('cleanmacros.sce');
+
+binfiles = ls(libpath+'/*.bin');
+for i = 1:size(binfiles,'*')
+ mdelete(binfiles(i));
+end
+
+mdelete(libpath+'/names');
+mdelete(libpath+'/lib');
+
+// ====================================================================
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2006-2008 - INRIA - Allan CORNET <allan.cornet@inria.fr>
+// Copyright (C) 2011 - DIGITEO - Michael Baudin
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
end
genlib('development_toolslib','SCI/modules/development_tools/macros',%f,%t);
+genlib('assertlib','SCI/modules/development_tools/macros/assert',%f,%t);
+
--- /dev/null
+// Copyright (C) 2008 - INRIA - Michael Baudin
+// Copyright (C) 2010-2011 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+function flag = MY_assert_equal ( computed , expected )
+ if computed==expected then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then bugmes();quit;end
+endfunction
+function checkassert ( flag , errmsg , ctype )
+ if ( ctype == "success" ) then
+ MY_assert_equal ( (flag==%t) & (errmsg==""), %t )
+ else
+ MY_assert_equal ( (flag==%f) & (errmsg<>""), %t )
+ end
+endfunction
+format("v",10);
+// Check error message when number of arguments is false
+instr = "assert_checkalmostequal ( )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkalmostequal ( 1 )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "[o1,o2,o3]=assert_checkalmostequal ( 1 , 1 , %eps )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 59 );
+//
+//////////////////////////////////////////
+// Check error message when type of arguments is false
+instr = "assert_checkalmostequal ( ""a"" , 2 , %eps )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkalmostequal ( 1 , ""b"" , %eps )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkalmostequal ( 1 , 2 , ""c"" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkalmostequal ( 1 , 2 , %eps , ""c"" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkalmostequal ( 1 , 2 , %eps , 0 , %t )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//////////////////////////////////////////
+// Check error message when size of arguments is false
+instr = "assert_checkalmostequal ( 1 , 2 , [1 1] )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkalmostequal ( 1 , 2 , %eps , [1 1] )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkalmostequal ( 1 , 2 , %eps , 0 , [""a"" ""b""] )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkalmostequal ( 1 , [2 3] , %eps )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//////////////////////////////////////////
+//
+// Check that the error message is correctly handled.
+instr = "assert_checkalmostequal ( 1 , 2 )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+errmsg = lasterror();
+MY_assert_equal ( errmsg , "assert_checkalmostequal: Assertion failed: expected = 2 while computed = 1" );
+//
+// Check that the error message is correctly handled.
+instr = "assert_checkalmostequal ( 1 , 2 , %eps )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+errmsg = lasterror();
+MY_assert_equal ( errmsg , "assert_checkalmostequal: Assertion failed: expected = 2 while computed = 1" );
+//
+// Check that the error message is correctly handled.
+instr = "assert_checkalmostequal ( 1 , 1 , %eps )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 0 );
+errmsg = lasterror();
+MY_assert_equal ( errmsg , [] );
+//
+// Obvious failure : Check the error message
+instr = "assert_checkalmostequal ( zeros(10,1)+1.e-4 , zeros(10,1) , 1.e-5 )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+errmsg = lasterror();
+MY_assert_equal ( errmsg , "assert_checkalmostequal: Assertion failed: expected = [0 ...] while computed = [0.0001 ...]" );
+//////////////////////////////////////////
+//
+//
+// Obvious success
+[flag,errmsg] = assert_checkalmostequal ( 1 , 1 );
+checkassert ( flag , errmsg , "success" );
+// Obvious success
+[flag,errmsg] = assert_checkalmostequal ( 1 , 1 , %eps );
+checkassert ( flag , errmsg , "success" );
+//
+// Obvious success
+[flag,errmsg] = assert_checkalmostequal ( ones(10,1) , ones(10,1) , %eps );
+checkassert ( flag , errmsg , "success" );
+//
+// Obvious success
+[flag,errmsg] = assert_checkalmostequal ( ones(10,1)+%eps , ones(10,1) , %eps );
+checkassert ( flag , errmsg , "success" );
+//
+// Obvious success
+[flag,errmsg] = assert_checkalmostequal ( zeros(10,1) , zeros(10,1) , 1.e-5 );
+checkassert ( flag , errmsg , "success" );
+//
+// Obvious failure
+[flag,errmsg] = assert_checkalmostequal ( 1 , 2 , %eps );
+checkassert ( flag , errmsg , "failure" );
+//
+// Obvious failure
+[flag,errmsg] = assert_checkalmostequal ( zeros(10,1)+1.e-4 , zeros(10,1) , 1.e-5 );
+checkassert ( flag , errmsg , "failure" );
+//
+// Success: not obvious!
+// The two values are equal, very small, but nonzero.
+// The relative tolerance must be used here.
+// If, instead, a bug in the assert function is so that the
+// absolute tolerance is used as 10^-16, then the output
+// of this comparison is wrong.
+[flag,errmsg] = assert_checkalmostequal ( 1.23456789123456789e-30 , 1.23456789123456789e-30 , %eps );
+checkassert ( flag , errmsg , "success" );
+//
+// Failure : not obvious!
+// There is only one significant digit here and we require the
+// maximum precision.
+// The test must fail because the relative tolerance must be used here.
+// If, instead, there is a bug in the comparison and
+// the absolute tolerance is used and set to
+// 10^-16, the output of this test is wrong.
+[flag,errmsg] = assert_checkalmostequal ( 1.23456789123456789e-30 , 1.3e-30 , %eps );
+checkassert ( flag , errmsg , "failure" );
+//
+// Success : not obvious!
+// The expected result is zero, so that the absolute tolerance is used.
+[flag,errmsg] = assert_checkalmostequal ( 1.23456789123456789e-30 , 0 , 0 , 1.e-10 );
+checkassert ( flag , errmsg , "success" );
+//
+// Check that nans are correctly handled
+[flag,errmsg] = assert_checkalmostequal ( [1 %nan], [1 %nan] , %eps );
+checkassert ( flag , errmsg , "success" );
+//
+// Check that nans are correctly handled
+[flag,errmsg] = assert_checkalmostequal ( [1 %nan 1 %nan] , [1 %nan 1 %nan] , %eps );
+checkassert ( flag , errmsg , "success" );
+//
+[flag,errmsg] = assert_checkalmostequal ( [%nan 1], [1 %nan] , %eps );
+checkassert ( flag , errmsg , "failure" );
+//
+// Check that slightly different values cannot pass basic test
+// Simple sequence with default settings
+[flag,errmsg] = assert_checkalmostequal ( 1 + 5 * %eps , 1 , %eps );
+checkassert ( flag , errmsg , "failure" );
+//
+// Customize the relative precision so that a test can pass
+// Simple sequence with default settings
+[flag,errmsg] = assert_checkalmostequal ( 1 + 5 * %eps , 1 , 10*%eps );
+checkassert ( flag , errmsg , "success" );
+//
+// Customize the absolute precision so that a test can pass
+// Simple sequence with default settings
+[flag,errmsg] = assert_checkalmostequal ( 0 + 5 * %eps , 0 , 0 , 10*%eps );
+checkassert ( flag , errmsg , "success" );
+//
+// An example where the relative error is used,
+// with a customized tolerance.
+[flag,errmsg] = assert_checkalmostequal ( 1.23456 , 1.23457 , 1.e11*%eps );
+checkassert ( flag , errmsg , "success" );
+//
+// Put all IEEE values
+[flag,errmsg] = assert_checkalmostequal ( [1.2345 %inf -%inf %nan] , [1.2346 %inf -%inf %nan] , 1.e-4 );
+checkassert ( flag , errmsg , "success" );
+///////////////////////////////////////////////////////////////////////////////
+// Test elementwise algo
+// If "matrix" type is used, this test pass.
+[flag,errmsg] = assert_checkalmostequal ( [1 1.e5] , [2 1.e5] , 1.e-3 , [], "element" );
+checkassert ( flag , errmsg , "failure" );
+//
+// Force the test to pass
+[flag,errmsg] = assert_checkalmostequal ( [1 1.e5] , [1 1.e5] , 1.e-3 , [], "element" );
+checkassert ( flag , errmsg , "success" );
+//
+[flag,errmsg] = assert_checkalmostequal ( [1 %nan] , [2 %nan] , 1.e-3 , [], "element" );
+checkassert ( flag , errmsg , "failure" );
+//
+[flag,errmsg] = assert_checkalmostequal ( [1 %inf] , [2 %inf] , 1.e-3 , [], "element" );
+checkassert ( flag , errmsg , "failure" );
+//
+[flag,errmsg] = assert_checkalmostequal ( [1 %inf] , [1 %inf] , 1.e-3 , [], "element" );
+checkassert ( flag , errmsg , "success" );
+//
+[flag,errmsg] = assert_checkalmostequal ( [1 %inf -%inf %nan] , [1 %inf -%inf %nan] , 1.e-3 , [], "element" );
+checkassert ( flag , errmsg , "success" );
+//
+[flag,errmsg] = assert_checkalmostequal ( [1 %inf -%inf %nan] , [1 -%inf %inf %nan] , 1.e-3 , [], "element" );
+checkassert ( flag , errmsg , "failure" );
+///////////////////////////////////////////////////////////////////////////////
+// Test complex elementwise algo
+//
+[flag,errmsg] = assert_checkalmostequal ( 1+%i , 1+(1+1.e-4)*%i , 1.e-3 , [], "element" );
+checkassert ( flag , errmsg , "success" );
+[flag,errmsg] = assert_checkalmostequal ( 1+%i , 1+(1+1.e-4)*%i , 1.e-5 , [], "element" );
+checkassert ( flag , errmsg , "failure" );
+//
+// Use absolute tolerance
+[flag,errmsg] = assert_checkalmostequal ( 1+%i , 0 , [], 1.e-3 , "element" );
+checkassert ( flag , errmsg , "failure" );
+//
--- /dev/null
+// Copyright (C) 2008 - INRIA - Michael Baudin
+// Copyright (C) 2010-2011 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+function flag = MY_assert_equal ( computed , expected )
+ if computed==expected then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then pause,end
+endfunction
+
+function checkassert ( flag , errmsg , ctype )
+ if ( ctype == "success" ) then
+ MY_assert_equal ( (flag==%t) & (errmsg==""), %t )
+ else
+ MY_assert_equal ( (flag==%f) & (errmsg<>""), %t )
+ end
+endfunction
+
+
+format("v",10);
+
+// Check error message when number of arguments is false
+instr = "assert_checkalmostequal ( )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkalmostequal ( 1 )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "[o1,o2,o3]=assert_checkalmostequal ( 1 , 1 , %eps )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 59 );
+//
+//////////////////////////////////////////
+// Check error message when type of arguments is false
+instr = "assert_checkalmostequal ( ""a"" , 2 , %eps )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkalmostequal ( 1 , ""b"" , %eps )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkalmostequal ( 1 , 2 , ""c"" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkalmostequal ( 1 , 2 , %eps , ""c"" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkalmostequal ( 1 , 2 , %eps , 0 , %t )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//////////////////////////////////////////
+// Check error message when size of arguments is false
+instr = "assert_checkalmostequal ( 1 , 2 , [1 1] )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkalmostequal ( 1 , 2 , %eps , [1 1] )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkalmostequal ( 1 , 2 , %eps , 0 , [""a"" ""b""] )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkalmostequal ( 1 , [2 3] , %eps )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+
+//////////////////////////////////////////
+//
+// Check that the error message is correctly handled.
+instr = "assert_checkalmostequal ( 1 , 2 )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+errmsg = lasterror();
+MY_assert_equal ( errmsg , "assert_checkalmostequal: Assertion failed: expected = 2 while computed = 1" );
+//
+// Check that the error message is correctly handled.
+instr = "assert_checkalmostequal ( 1 , 2 , %eps )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+errmsg = lasterror();
+MY_assert_equal ( errmsg , "assert_checkalmostequal: Assertion failed: expected = 2 while computed = 1" );
+//
+// Check that the error message is correctly handled.
+instr = "assert_checkalmostequal ( 1 , 1 , %eps )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 0 );
+errmsg = lasterror();
+MY_assert_equal ( errmsg , [] );
+//
+// Obvious failure : Check the error message
+instr = "assert_checkalmostequal ( zeros(10,1)+1.e-4 , zeros(10,1) , 1.e-5 )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+errmsg = lasterror();
+MY_assert_equal ( errmsg , "assert_checkalmostequal: Assertion failed: expected = [0 ...] while computed = [0.0001 ...]" );
+//////////////////////////////////////////
+//
+//
+// Obvious success
+[flag,errmsg] = assert_checkalmostequal ( 1 , 1 );
+checkassert ( flag , errmsg , "success" );
+// Obvious success
+[flag,errmsg] = assert_checkalmostequal ( 1 , 1 , %eps );
+checkassert ( flag , errmsg , "success" );
+//
+// Obvious success
+[flag,errmsg] = assert_checkalmostequal ( ones(10,1) , ones(10,1) , %eps );
+checkassert ( flag , errmsg , "success" );
+//
+// Obvious success
+[flag,errmsg] = assert_checkalmostequal ( ones(10,1)+%eps , ones(10,1) , %eps );
+checkassert ( flag , errmsg , "success" );
+//
+// Obvious success
+[flag,errmsg] = assert_checkalmostequal ( zeros(10,1) , zeros(10,1) , 1.e-5 );
+checkassert ( flag , errmsg , "success" );
+//
+// Obvious failure
+[flag,errmsg] = assert_checkalmostequal ( 1 , 2 , %eps );
+checkassert ( flag , errmsg , "failure" );
+//
+// Obvious failure
+[flag,errmsg] = assert_checkalmostequal ( zeros(10,1)+1.e-4 , zeros(10,1) , 1.e-5 );
+checkassert ( flag , errmsg , "failure" );
+//
+// Success: not obvious!
+// The two values are equal, very small, but nonzero.
+// The relative tolerance must be used here.
+// If, instead, a bug in the assert function is so that the
+// absolute tolerance is used as 10^-16, then the output
+// of this comparison is wrong.
+[flag,errmsg] = assert_checkalmostequal ( 1.23456789123456789e-30 , 1.23456789123456789e-30 , %eps );
+checkassert ( flag , errmsg , "success" );
+//
+// Failure : not obvious!
+// There is only one significant digit here and we require the
+// maximum precision.
+// The test must fail because the relative tolerance must be used here.
+// If, instead, there is a bug in the comparison and
+// the absolute tolerance is used and set to
+// 10^-16, the output of this test is wrong.
+[flag,errmsg] = assert_checkalmostequal ( 1.23456789123456789e-30 , 1.3e-30 , %eps );
+checkassert ( flag , errmsg , "failure" );
+//
+// Success : not obvious!
+// The expected result is zero, so that the absolute tolerance is used.
+[flag,errmsg] = assert_checkalmostequal ( 1.23456789123456789e-30 , 0 , 0 , 1.e-10 );
+checkassert ( flag , errmsg , "success" );
+//
+// Check that nans are correctly handled
+[flag,errmsg] = assert_checkalmostequal ( [1 %nan], [1 %nan] , %eps );
+checkassert ( flag , errmsg , "success" );
+//
+// Check that nans are correctly handled
+[flag,errmsg] = assert_checkalmostequal ( [1 %nan 1 %nan] , [1 %nan 1 %nan] , %eps );
+checkassert ( flag , errmsg , "success" );
+//
+[flag,errmsg] = assert_checkalmostequal ( [%nan 1], [1 %nan] , %eps );
+checkassert ( flag , errmsg , "failure" );
+//
+// Check that slightly different values cannot pass basic test
+// Simple sequence with default settings
+[flag,errmsg] = assert_checkalmostequal ( 1 + 5 * %eps , 1 , %eps );
+checkassert ( flag , errmsg , "failure" );
+//
+// Customize the relative precision so that a test can pass
+// Simple sequence with default settings
+[flag,errmsg] = assert_checkalmostequal ( 1 + 5 * %eps , 1 , 10*%eps );
+checkassert ( flag , errmsg , "success" );
+//
+// Customize the absolute precision so that a test can pass
+// Simple sequence with default settings
+[flag,errmsg] = assert_checkalmostequal ( 0 + 5 * %eps , 0 , 0 , 10*%eps );
+checkassert ( flag , errmsg , "success" );
+//
+// An example where the relative error is used,
+// with a customized tolerance.
+[flag,errmsg] = assert_checkalmostequal ( 1.23456 , 1.23457 , 1.e11*%eps );
+checkassert ( flag , errmsg , "success" );
+//
+// Put all IEEE values
+[flag,errmsg] = assert_checkalmostequal ( [1.2345 %inf -%inf %nan] , [1.2346 %inf -%inf %nan] , 1.e-4 );
+checkassert ( flag , errmsg , "success" );
+
+///////////////////////////////////////////////////////////////////////////////
+// Test elementwise algo
+
+// If "matrix" type is used, this test pass.
+[flag,errmsg] = assert_checkalmostequal ( [1 1.e5] , [2 1.e5] , 1.e-3 , [], "element" );
+checkassert ( flag , errmsg , "failure" );
+//
+// Force the test to pass
+[flag,errmsg] = assert_checkalmostequal ( [1 1.e5] , [1 1.e5] , 1.e-3 , [], "element" );
+checkassert ( flag , errmsg , "success" );
+//
+[flag,errmsg] = assert_checkalmostequal ( [1 %nan] , [2 %nan] , 1.e-3 , [], "element" );
+checkassert ( flag , errmsg , "failure" );
+//
+[flag,errmsg] = assert_checkalmostequal ( [1 %inf] , [2 %inf] , 1.e-3 , [], "element" );
+checkassert ( flag , errmsg , "failure" );
+//
+[flag,errmsg] = assert_checkalmostequal ( [1 %inf] , [1 %inf] , 1.e-3 , [], "element" );
+checkassert ( flag , errmsg , "success" );
+//
+[flag,errmsg] = assert_checkalmostequal ( [1 %inf -%inf %nan] , [1 %inf -%inf %nan] , 1.e-3 , [], "element" );
+checkassert ( flag , errmsg , "success" );
+//
+[flag,errmsg] = assert_checkalmostequal ( [1 %inf -%inf %nan] , [1 -%inf %inf %nan] , 1.e-3 , [], "element" );
+checkassert ( flag , errmsg , "failure" );
+
+///////////////////////////////////////////////////////////////////////////////
+// Test complex elementwise algo
+//
+[flag,errmsg] = assert_checkalmostequal ( 1+%i , 1+(1+1.e-4)*%i , 1.e-3 , [], "element" );
+checkassert ( flag , errmsg , "success" );
+[flag,errmsg] = assert_checkalmostequal ( 1+%i , 1+(1+1.e-4)*%i , 1.e-5 , [], "element" );
+checkassert ( flag , errmsg , "failure" );
+//
+// Use absolute tolerance
+[flag,errmsg] = assert_checkalmostequal ( 1+%i , 0 , [], 1.e-3 , "element" );
+checkassert ( flag , errmsg , "failure" );
+//
+
--- /dev/null
+// Copyright (C) 2008 - INRIA - Michael Baudin
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+function flag = MY_assert_equal ( computed , expected )
+ if ( and ( computed==expected ) ) then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then bugmes();quit;end
+endfunction
+function checkassert ( flag , errmsg , ctype )
+ if ( ctype == "success" ) then
+ MY_assert_equal ( (flag==%t) & (errmsg==""), %t )
+ else
+ MY_assert_equal ( (flag==%f) & (errmsg<>""), %t )
+ end
+endfunction
+format("v",10);
+// Check error message when number of arguments is false
+instr = "assert_checkequal ( )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkequal ( 1 )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "[o1,o2,o3]=assert_checkequal ( 1 , 1 )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 59 );
+//////////////////////////////////////////
+// Check error message when type of arguments is false
+instr = "assert_checkequal ( ""a"" , 2 )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkequal ( 1 , ""b"" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//////////////////////////////////////////
+// Check error message when size of arguments are not equal
+instr = "assert_checkequal ( 1 , [2 3] )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+// Check that the error message is correctly handled.
+instr = "assert_checkequal ( [1 2], [3 4] )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+errmsg = lasterror();
+MY_assert_equal ( errmsg , "assert_checkequal: Assertion failed: expected = [3 ...] while computed = [1 ...]" );
+//
+[flag , errmsg] = assert_checkequal ( %T , %T );
+checkassert ( flag , errmsg , "success" );
+//
+[flag , errmsg] = assert_checkequal ( %F , %T );
+checkassert ( flag , errmsg , "failure" );
+//
+[flag , errmsg] = assert_checkequal ( %nan , %nan );
+checkassert ( flag , errmsg , "success" );
+//
+[flag , errmsg] = assert_checkequal ( list() , list() );
+checkassert ( flag , errmsg , "success" );
+//
+[flag , errmsg] = assert_checkequal ( [%T %F], [%T %F] );
+checkassert ( flag , errmsg , "success" );
+//
+// Test all IEEE values
+[flag , errmsg] = assert_checkequal ( [1 %inf -%inf %nan] , [1 %inf -%inf %nan] );
+checkassert ( flag , errmsg , "success" );
+//
+[flag , errmsg] = assert_checkequal ( [] , [] );
+checkassert ( flag , errmsg , "success" );
+////////////////////////////////////////////////////////
+// Check complex entries.
+[flag , errmsg] = assert_checkequal(complex(%nan,%nan),complex(%nan,0));
+checkassert ( flag , errmsg , "failure" );
+//
+[flag , errmsg] = assert_checkequal(complex(%nan,%inf),complex(%nan,0));
+checkassert ( flag , errmsg , "failure" );
+//
+[flag , errmsg] = assert_checkequal(complex(%nan,%nan),complex(0,%nan));
+checkassert ( flag , errmsg , "failure" );
+//
+[flag , errmsg] = assert_checkequal(complex(%nan,%inf),complex(0,%inf));
+checkassert ( flag , errmsg , "failure" );
+//
+[flag , errmsg] = assert_checkequal(complex(0,%inf),complex(0,%inf));
+checkassert ( flag , errmsg , "success" );
+//
+[flag , errmsg] = assert_checkequal(complex(%nan,%nan),complex(%nan,%nan));
+checkassert ( flag , errmsg , "success" );
+//
+[flag , errmsg] = assert_checkequal(complex(%inf,%nan),complex(%inf,%nan));
+checkassert ( flag , errmsg , "success" );
--- /dev/null
+// Copyright (C) 2008 - INRIA - Michael Baudin
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+function flag = MY_assert_equal ( computed , expected )
+ if ( and ( computed==expected ) ) then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then pause,end
+endfunction
+
+function checkassert ( flag , errmsg , ctype )
+ if ( ctype == "success" ) then
+ MY_assert_equal ( (flag==%t) & (errmsg==""), %t )
+ else
+ MY_assert_equal ( (flag==%f) & (errmsg<>""), %t )
+ end
+endfunction
+
+format("v",10);
+
+// Check error message when number of arguments is false
+instr = "assert_checkequal ( )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkequal ( 1 )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "[o1,o2,o3]=assert_checkequal ( 1 , 1 )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 59 );
+
+//////////////////////////////////////////
+// Check error message when type of arguments is false
+instr = "assert_checkequal ( ""a"" , 2 )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkequal ( 1 , ""b"" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//////////////////////////////////////////
+// Check error message when size of arguments are not equal
+instr = "assert_checkequal ( 1 , [2 3] )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+// Check that the error message is correctly handled.
+instr = "assert_checkequal ( [1 2], [3 4] )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+errmsg = lasterror();
+MY_assert_equal ( errmsg , "assert_checkequal: Assertion failed: expected = [3 ...] while computed = [1 ...]" );
+//
+[flag , errmsg] = assert_checkequal ( %T , %T );
+checkassert ( flag , errmsg , "success" );
+//
+[flag , errmsg] = assert_checkequal ( %F , %T );
+checkassert ( flag , errmsg , "failure" );
+//
+[flag , errmsg] = assert_checkequal ( %nan , %nan );
+checkassert ( flag , errmsg , "success" );
+//
+[flag , errmsg] = assert_checkequal ( list() , list() );
+checkassert ( flag , errmsg , "success" );
+//
+[flag , errmsg] = assert_checkequal ( [%T %F], [%T %F] );
+checkassert ( flag , errmsg , "success" );
+//
+// Test all IEEE values
+[flag , errmsg] = assert_checkequal ( [1 %inf -%inf %nan] , [1 %inf -%inf %nan] );
+checkassert ( flag , errmsg , "success" );
+//
+[flag , errmsg] = assert_checkequal ( [] , [] );
+checkassert ( flag , errmsg , "success" );
+////////////////////////////////////////////////////////
+// Check complex entries.
+[flag , errmsg] = assert_checkequal(complex(%nan,%nan),complex(%nan,0));
+checkassert ( flag , errmsg , "failure" );
+//
+[flag , errmsg] = assert_checkequal(complex(%nan,%inf),complex(%nan,0));
+checkassert ( flag , errmsg , "failure" );
+//
+[flag , errmsg] = assert_checkequal(complex(%nan,%nan),complex(0,%nan));
+checkassert ( flag , errmsg , "failure" );
+//
+[flag , errmsg] = assert_checkequal(complex(%nan,%inf),complex(0,%inf));
+checkassert ( flag , errmsg , "failure" );
+//
+[flag , errmsg] = assert_checkequal(complex(0,%inf),complex(0,%inf));
+checkassert ( flag , errmsg , "success" );
+//
+[flag , errmsg] = assert_checkequal(complex(%nan,%nan),complex(%nan,%nan));
+checkassert ( flag , errmsg , "success" );
+//
+[flag , errmsg] = assert_checkequal(complex(%inf,%nan),complex(%inf,%nan));
+checkassert ( flag , errmsg , "success" );
+
+
+
+
+
--- /dev/null
+// Copyright (C) 2008 - INRIA - Michael Baudin
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+function flag = MY_assert_equal ( computed , expected )
+ if computed==expected then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then bugmes();quit;end
+endfunction
+// Which error number to generate ?
+// 201 "%s: Wrong type for argument %d: Real or complex matrix expected."
+// 209 "%s: Wrong type for argument %d: Matrix expected."
+// 53 "Wrong type for input argument %d: Real or complex matrix expected."
+// 81 "%s: Wrong type for argument %d: Real or complex matrix expected."
+function y = f(x)
+ [lhs,rhs]=argn()
+ if ( rhs <> 1 ) then
+ errmsg = sprintf ( gettext ( "%s: Unexpected number of input arguments : %d provided while %d to %d are expected.") , "f" , rhs , 1 , 1 )
+ error(errmsg)
+ end
+ if ( typeof(x) <> "constant" ) then
+ localstr = gettext ( "%s: Unexpected type of input argument #%d : variable %s has type %s while %s is expected.")
+ errmsg = sprintf ( localstr , "f" , 1 , "x" , typeof(x) , "constant" )
+ error(errmsg,123456789)
+ end
+ y = x
+endfunction
+///////////////////////////////////////////////
+// Check our test-function f (the old shool way)
+MY_assert_equal ( f(2) , 2 );
+//
+instr = "f()";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+lerr = lasterror();
+MY_assert_equal ( lerr , "f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected." );
+//
+instr = "f(""aa"")";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 123456789 );
+lerr = lasterror();
+MY_assert_equal ( lerr , "f: Unexpected type of input argument #1 : variable x has type string while constant is expected." );
+//
+///////////////////////////////////////////////
+// Check the error messages produced by assert_checkerror in case of wrong use of assert_checkerror
+//
+// Check error message when number of input arguments is false
+instr = "assert_checkerror ( )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+lerr = lasterror();
+MY_assert_equal ( lerr , "assert_checkerror: Wrong number of input arguments: 2 to 3 expected." );
+//
+// Check when number of output arguments is false
+//
+instr = "[o1,o2,o3]=assert_checkerror ( ""y=f(1)"" , """" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 59 );
+//
+// Check error message when type of arguments of assert_checkerror is false
+instr = "assert_checkerror ( 1 , """" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+lerr = lasterror();
+MY_assert_equal ( lerr , "assert_checkerror: Wrong type for argument 1: Matrix of strings expected." );
+//
+// Check error message when no error is produced by f
+instr = "assert_checkerror ( ""y=f(1)"" , ""foo"" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+lerr = lasterror();
+MY_assert_equal ( lerr , "assert_checkerror: No error was produced while evaluating ""y=f(1)""." );
+//
+// Check error message when no error is produced by f (and error number is given)
+instr = "assert_checkerror ( ""y=f(1)"" , ""foo"" , 12 )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+lerr = lasterror();
+MY_assert_equal ( lerr , "assert_checkerror: No error was produced while evaluating ""y=f(1)""." );
+//
+///////////////////////////////////////////////
+//
+// Typical use-cases : the test pass
+//
+assert_checkerror ( "y=f()" , "f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected." );
+assert_checkerror ( "y=f(""a"")" , "f: Unexpected type of input argument #1 : variable x has type string while constant is expected." );
+assert_checkerror ( "y=f()" , "f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected." , 10000 );
+assert_checkerror ( "y=f(""a"")" , "f: Unexpected type of input argument #1 : variable x has type string while constant is expected." , 123456789 );
+// Check error message when the good error is produced by f (and errmsg is not given)
+flag = assert_checkerror ( "y=f()" , "f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected." );
+MY_assert_equal ( flag , %t );
+//
+flag = assert_checkerror ( "y=f(""a"")" , "f: Unexpected type of input argument #1 : variable x has type string while constant is expected." );
+MY_assert_equal ( flag , %t );
+//
+// Check error message and error number
+flag = assert_checkerror ( "y=f()" , "f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected." , 10000 );
+MY_assert_equal ( flag , %t );
+//
+flag = assert_checkerror ( "y=f(""a"")" , "f: Unexpected type of input argument #1 : variable x has type string while constant is expected." , 123456789 );
+MY_assert_equal ( flag , %t );
+//
+// Check error message when the good error is produced by f (and errmsg is an output argument)
+[flag,errmsg] = assert_checkerror ( "y=f()" , "f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected." );
+MY_assert_equal ( flag , %t );
+MY_assert_equal ( errmsg , "" );
+//
+// Check error message and error number (and errmsg is given is an output argument)
+[flag,errmsg] = assert_checkerror ( "y=f()" , "f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected." , 10000 );
+MY_assert_equal ( flag , %t );
+MY_assert_equal ( errmsg , "" );
+//
+///////////////////////////////////////////////
+//
+// Typical use-cases : the test fails because the message is no the same
+//
+// Check error message when the wrong error is produced by f (and errmsg is not given)
+instr = "assert_checkerror ( ""y=f()"" , ""oups"" )";
+ierr = execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+lerr = lasterror();
+MY_assert_equal ( lerr , "assert_checkerror: Assertion failed: expected error message = ""oups"" while computed error message = ""f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected.""." );
+//
+instr = "assert_checkerror ( ""y=f(""""a"""")"" , ""oups"" )";
+ierr = execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+lerr = lasterror();
+MY_assert_equal ( lerr , "assert_checkerror: Assertion failed: expected error message = ""oups"" while computed error message = ""f: Unexpected type of input argument #1 : variable x has type string while constant is expected.""." );
+//
+// Check when errmsg is given
+//
+[flag,errmsg]=assert_checkerror ( "y=f()" , "oups" );
+MY_assert_equal ( flag , %f );
+MY_assert_equal ( errmsg , "assert_checkerror: Assertion failed: expected error message = ""oups"" while computed error message = ""f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected.""." );
+//
+[flag,errmsg]=assert_checkerror ( "y=f(""a"")" , "oups" );
+MY_assert_equal ( flag , %f );
+MY_assert_equal ( errmsg , "assert_checkerror: Assertion failed: expected error message = ""oups"" while computed error message = ""f: Unexpected type of input argument #1 : variable x has type string while constant is expected.""." );
+///////////////////////////////////////////////
+//
+// Typical use-cases : the test fails because the error number is no the same
+//
+instr = "assert_checkerror ( ""y=f()"" , ""f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected."" , 12 )";
+ierr = execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+lerr = lasterror();
+MY_assert_equal ( lerr , "assert_checkerror: Assertion failed: expected error number = 12 while computed error number = 10000." );
+//
+[flag,errmsg]=assert_checkerror ( "y=f()" , "f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected." , 12 );
+MY_assert_equal ( flag , %f );
+MY_assert_equal ( errmsg , "assert_checkerror: Assertion failed: expected error number = 12 while computed error number = 10000." );
--- /dev/null
+// Copyright (C) 2008 - INRIA - Michael Baudin
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+function flag = MY_assert_equal ( computed , expected )
+ if computed==expected then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then pause,end
+endfunction
+
+// Which error number to generate ?
+// 201 "%s: Wrong type for argument %d: Real or complex matrix expected."
+// 209 "%s: Wrong type for argument %d: Matrix expected."
+// 53 "Wrong type for input argument %d: Real or complex matrix expected."
+// 81 "%s: Wrong type for argument %d: Real or complex matrix expected."
+
+function y = f(x)
+ [lhs,rhs]=argn()
+ if ( rhs <> 1 ) then
+ errmsg = sprintf ( gettext ( "%s: Unexpected number of input arguments : %d provided while %d to %d are expected.") , "f" , rhs , 1 , 1 )
+ error(errmsg)
+ end
+ if ( typeof(x) <> "constant" ) then
+ localstr = gettext ( "%s: Unexpected type of input argument #%d : variable %s has type %s while %s is expected.")
+ errmsg = sprintf ( localstr , "f" , 1 , "x" , typeof(x) , "constant" )
+ error(errmsg,123456789)
+ end
+ y = x
+endfunction
+
+///////////////////////////////////////////////
+// Check our test-function f (the old shool way)
+MY_assert_equal ( f(2) , 2 );
+//
+instr = "f()";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+lerr = lasterror();
+MY_assert_equal ( lerr , "f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected." );
+//
+instr = "f(""aa"")";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 123456789 );
+lerr = lasterror();
+MY_assert_equal ( lerr , "f: Unexpected type of input argument #1 : variable x has type string while constant is expected." );
+//
+///////////////////////////////////////////////
+// Check the error messages produced by assert_checkerror in case of wrong use of assert_checkerror
+//
+// Check error message when number of input arguments is false
+instr = "assert_checkerror ( )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+lerr = lasterror();
+MY_assert_equal ( lerr , "assert_checkerror: Wrong number of input arguments: 2 to 3 expected." );
+//
+// Check when number of output arguments is false
+//
+instr = "[o1,o2,o3]=assert_checkerror ( ""y=f(1)"" , """" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 59 );
+//
+// Check error message when type of arguments of assert_checkerror is false
+instr = "assert_checkerror ( 1 , """" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+lerr = lasterror();
+MY_assert_equal ( lerr , "assert_checkerror: Wrong type for argument 1: Matrix of strings expected." );
+//
+// Check error message when no error is produced by f
+instr = "assert_checkerror ( ""y=f(1)"" , ""foo"" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+lerr = lasterror();
+MY_assert_equal ( lerr , "assert_checkerror: No error was produced while evaluating ""y=f(1)""." );
+//
+// Check error message when no error is produced by f (and error number is given)
+instr = "assert_checkerror ( ""y=f(1)"" , ""foo"" , 12 )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+lerr = lasterror();
+MY_assert_equal ( lerr , "assert_checkerror: No error was produced while evaluating ""y=f(1)""." );
+//
+///////////////////////////////////////////////
+//
+// Typical use-cases : the test pass
+//
+assert_checkerror ( "y=f()" , "f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected." );
+assert_checkerror ( "y=f(""a"")" , "f: Unexpected type of input argument #1 : variable x has type string while constant is expected." );
+assert_checkerror ( "y=f()" , "f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected." , 10000 );
+assert_checkerror ( "y=f(""a"")" , "f: Unexpected type of input argument #1 : variable x has type string while constant is expected." , 123456789 );
+// Check error message when the good error is produced by f (and errmsg is not given)
+flag = assert_checkerror ( "y=f()" , "f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected." );
+MY_assert_equal ( flag , %t );
+//
+flag = assert_checkerror ( "y=f(""a"")" , "f: Unexpected type of input argument #1 : variable x has type string while constant is expected." );
+MY_assert_equal ( flag , %t );
+//
+// Check error message and error number
+flag = assert_checkerror ( "y=f()" , "f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected." , 10000 );
+MY_assert_equal ( flag , %t );
+//
+flag = assert_checkerror ( "y=f(""a"")" , "f: Unexpected type of input argument #1 : variable x has type string while constant is expected." , 123456789 );
+MY_assert_equal ( flag , %t );
+//
+// Check error message when the good error is produced by f (and errmsg is an output argument)
+[flag,errmsg] = assert_checkerror ( "y=f()" , "f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected." );
+MY_assert_equal ( flag , %t );
+MY_assert_equal ( errmsg , "" );
+//
+// Check error message and error number (and errmsg is given is an output argument)
+[flag,errmsg] = assert_checkerror ( "y=f()" , "f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected." , 10000 );
+MY_assert_equal ( flag , %t );
+MY_assert_equal ( errmsg , "" );
+//
+///////////////////////////////////////////////
+//
+// Typical use-cases : the test fails because the message is no the same
+//
+// Check error message when the wrong error is produced by f (and errmsg is not given)
+instr = "assert_checkerror ( ""y=f()"" , ""oups"" )";
+ierr = execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+lerr = lasterror();
+MY_assert_equal ( lerr , "assert_checkerror: Assertion failed: expected error message = ""oups"" while computed error message = ""f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected.""." );
+//
+instr = "assert_checkerror ( ""y=f(""""a"""")"" , ""oups"" )";
+ierr = execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+lerr = lasterror();
+MY_assert_equal ( lerr , "assert_checkerror: Assertion failed: expected error message = ""oups"" while computed error message = ""f: Unexpected type of input argument #1 : variable x has type string while constant is expected.""." );
+//
+// Check when errmsg is given
+//
+[flag,errmsg]=assert_checkerror ( "y=f()" , "oups" );
+MY_assert_equal ( flag , %f );
+MY_assert_equal ( errmsg , "assert_checkerror: Assertion failed: expected error message = ""oups"" while computed error message = ""f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected.""." );
+//
+[flag,errmsg]=assert_checkerror ( "y=f(""a"")" , "oups" );
+MY_assert_equal ( flag , %f );
+MY_assert_equal ( errmsg , "assert_checkerror: Assertion failed: expected error message = ""oups"" while computed error message = ""f: Unexpected type of input argument #1 : variable x has type string while constant is expected.""." );
+///////////////////////////////////////////////
+//
+// Typical use-cases : the test fails because the error number is no the same
+//
+instr = "assert_checkerror ( ""y=f()"" , ""f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected."" , 12 )";
+ierr = execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+lerr = lasterror();
+MY_assert_equal ( lerr , "assert_checkerror: Assertion failed: expected error number = 12 while computed error number = 10000." );
+//
+[flag,errmsg]=assert_checkerror ( "y=f()" , "f: Unexpected number of input arguments : 0 provided while 1 to 1 are expected." , 12 );
+MY_assert_equal ( flag , %f );
+MY_assert_equal ( errmsg , "assert_checkerror: Assertion failed: expected error number = 12 while computed error number = 10000." );
+
--- /dev/null
+// Copyright (C) 2008 - INRIA - Michael Baudin
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+function flag = MY_assert_equal ( computed , expected )
+ if computed==expected then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then bugmes();quit;end
+endfunction
+function checkassert ( flag , errmsg , ctype )
+ if ( ctype == "success" ) then
+ MY_assert_equal ( (flag==%t) & (errmsg==""), %t )
+ else
+ MY_assert_equal ( (flag==%f) & (errmsg<>""), %t )
+ end
+endfunction
+format("v",10);
+// Check error message when number of arguments is false
+instr = "assert_checkfalse ( )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "[o1,o2,o3]=assert_checkfalse ( %f )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 59 );
+//////////////////////////////////////////
+// Check error message when type of arguments is false
+instr = "assert_checkfalse ( ""a"" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+//
+// Check that the error message is correctly handled.
+instr = "assert_checkfalse ( [%f %t] )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+errmsg = lasterror();
+MY_assert_equal ( errmsg , "assert_checkfalse: Assertion failed: found false entry in condition = [F ...]" );
+//
+[flag,errmsg] = assert_checkfalse ( %f );
+checkassert ( flag , errmsg , "success" );
+//
+[flag,errmsg] = assert_checkfalse ( [%f %f] );
+checkassert ( flag , errmsg , "success" );
+//
+[flag,errmsg] = assert_checkfalse ( %t );
+checkassert ( flag , errmsg , "failure" );
+//
+[flag,errmsg] = assert_checkfalse ( [%t %f] );
+checkassert ( flag , errmsg , "failure" );
--- /dev/null
+// Copyright (C) 2008 - INRIA - Michael Baudin
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+function flag = MY_assert_equal ( computed , expected )
+ if computed==expected then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then pause,end
+endfunction
+
+function checkassert ( flag , errmsg , ctype )
+ if ( ctype == "success" ) then
+ MY_assert_equal ( (flag==%t) & (errmsg==""), %t )
+ else
+ MY_assert_equal ( (flag==%f) & (errmsg<>""), %t )
+ end
+endfunction
+
+format("v",10);
+
+// Check error message when number of arguments is false
+instr = "assert_checkfalse ( )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "[o1,o2,o3]=assert_checkfalse ( %f )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 59 );
+//////////////////////////////////////////
+// Check error message when type of arguments is false
+instr = "assert_checkfalse ( ""a"" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+//
+// Check that the error message is correctly handled.
+instr = "assert_checkfalse ( [%f %t] )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+errmsg = lasterror();
+MY_assert_equal ( errmsg , "assert_checkfalse: Assertion failed: found false entry in condition = [F ...]" );
+//
+[flag,errmsg] = assert_checkfalse ( %f );
+checkassert ( flag , errmsg , "success" );
+//
+[flag,errmsg] = assert_checkfalse ( [%f %f] );
+checkassert ( flag , errmsg , "success" );
+//
+[flag,errmsg] = assert_checkfalse ( %t );
+checkassert ( flag , errmsg , "failure" );
+//
+[flag,errmsg] = assert_checkfalse ( [%t %f] );
+checkassert ( flag , errmsg , "failure" );
+
--- /dev/null
+// Copyright (C) 2008 - INRIA - Michael Baudin
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+function flag = MY_assert_equal ( computed , expected )
+ if computed==expected then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then bugmes();quit;end
+endfunction
+function checkassert ( flag , errmsg , ctype )
+ if ( ctype == "success" ) then
+ MY_assert_equal ( (flag==%t) & (errmsg==""), %t )
+ else
+ MY_assert_equal ( (flag==%f) & (errmsg<>""), %t )
+ end
+endfunction
+format("v",10);
+// Check error message when number of arguments is false
+instr = "assert_checkfilesequal ( )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkfilesequal ( ""foo.txt"" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "[o1,o2,o3]=assert_checkfilesequal ( ""foo.txt"" , ""foo.txt"" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 59 );
+//
+//////////////////////////////////////////
+//
+// Check error message when type of arguments is false
+instr = "assert_checkfilesequal ( ""foo.txt"" , %t )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkfilesequal ( %t , ""foo.txt"" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkfilesequal ( %t , %t )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+//////////////////////////////////////////
+//
+// Check error message when size of arguments is false
+instr = "assert_checkfilesequal ( [ ""foo.txt"" ""foo.txt"" ] , ""foo.txt"" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkfilesequal ( ""foo.txt"" , [ ""foo.txt"" ""foo.txt"" ] )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+//////////////////////////////////////////
+//
+// Prepare data for the tests
+// fileref1 : three lines of text.
+// filecomp1 : == fileref1
+// filecomp2 : <> fileref1
+//
+// fileref1
+fileref1 = fullfile(TMPDIR,"fileref.txt");
+txt1 = [
+ "Line #1"
+ "Line #2"
+ "Line #3"
+];
+fd = mopen(fileref1,"w");
+mputl(txt1,fd);
+mclose(fd);
+//
+// filecomp1
+filecomp1 = fullfile(TMPDIR,"filecomp1.txt");
+fd = mopen(filecomp1,"w");
+mputl(txt1,fd);
+mclose(fd);
+//
+filecomp2 = fullfile(TMPDIR,"filecomp2.txt");
+txt2 = [
+ "Line #1"
+ "Line #4"
+ "Line #3"
+];
+fd = mopen(filecomp2,"w");
+mputl(txt2,fd);
+mclose(fd);
+//
+//////////////////////////////////////////
+//
+// A test which pass
+[flag,errmsg] = assert_checkfilesequal ( filecomp1 , fileref1 );
+checkassert ( flag , errmsg , "success" );
+//
+// A test which pass.
+// Replay it, to make sure that the files are correctly closed.
+[flag,errmsg] = assert_checkfilesequal ( filecomp1 , fileref1 );
+checkassert ( flag , errmsg , "success" );
+//
+// Failure: filecomp2 <> fileref1
+[flag,errmsg] = assert_checkfilesequal ( filecomp2 , fileref1 );
+checkassert ( flag , errmsg , "failure" );
+//
+// Failure: filecomp2 <> fileref1
+// Replay it, to make sure that the files are correctly closed.
+[flag,errmsg] = assert_checkfilesequal ( filecomp2 , fileref1 );
+checkassert ( flag , errmsg , "failure" );
+//
+// Failure: fileref does not exist.
+[flag,errmsg] = assert_checkfilesequal ( filecomp2 , "foo.txt" );
+checkassert ( flag , errmsg , "failure" );
+//
+// Failure: filecomp does not exist.
+[flag,errmsg] = assert_checkfilesequal ( "foo.txt" , fileref1 );
+checkassert ( flag , errmsg , "failure" );
+//
+//////////////////////////////////////////
+//
+// A test with a comparison function which ignores comment lines.
+//
+// Define the filter
+function otxt = myfilter ( itxt )
+ nr = size(itxt,"r")
+ // This is the pattern for a comment line of the form "// blabla"
+ pattern = "/\/\/.*/"
+ k = 1
+ for i = 1 : nr
+ start = regexp(itxt(i),pattern)
+ if ( start == [] ) then
+ otxt(k) = itxt(i)
+ k = k + 1
+ end
+ end
+endfunction
+//
+// Check that the filter works as expected.
+itxt = [
+ "bla 1"
+ "// bla 2"
+ "bla 3"
+ "// bla 4"
+ "bla 5"
+ ];
+otxt = myfilter ( itxt );
+etxt = [
+ "bla 1"
+ "bla 3"
+ "bla 5"
+ ];
+MY_assert_equal ( otxt , etxt );
+//
+// Define the comparison function
+function areequal = mycompfun ( ctxt , etxt )
+ ctxt = myfilter ( ctxt )
+ etxt = myfilter ( etxt )
+ areequal = ( ctxt == etxt )
+endfunction
+//
+// Use the comparison function.
+// fileref2 == filecomp3, given that comment lines are ignored.
+// fileref2 <> filecomp4, given that comment lines are ignored.
+// Notice that the comments are inserted at different positions in the files:
+// sometimes at the begining, sometimes in the middle.
+//
+// Prepare data files
+//
+// fileref2
+fileref2 = fullfile(TMPDIR,"fileref2.txt");
+txt = [
+ "// bla 2"
+ "Line #1"
+ "// bla 2"
+ "Line #2"
+ "Line #3"
+];
+fd = mopen(fileref2,"w");
+mputl(txt,fd);
+mclose(fd);
+//
+// filecomp3
+filecomp3 = fullfile(TMPDIR,"filecomp3.txt");
+txt = [
+ "Line #1"
+ "// bla 5168"
+ "Line #2"
+ "Line #3"
+ "// bla oups"
+];
+fd = mopen(filecomp3,"w");
+mputl(txt,fd);
+mclose(fd);
+//
+// filecomp4
+filecomp4 = fullfile(TMPDIR,"filecomp4.txt");
+txt = [
+ "// bla 3"
+ "Line #1"
+ "Line #4"
+ "// bla 5168"
+ "Line #3"
+ "// bla oups"
+];
+fd = mopen(filecomp4,"w");
+mputl(txt,fd);
+mclose(fd);
+//
+// A test which pass
+[flag,errmsg] = assert_checkfilesequal ( filecomp3 , fileref2 , mycompfun );
+checkassert ( flag , errmsg , "success" );
+//
+// A test which fails
+[flag,errmsg] = assert_checkfilesequal ( filecomp4 , fileref2 , mycompfun );
+checkassert ( flag , errmsg , "failure" );
+//
+///////////////////////////////////////////////////////////////////
+//
+// A comparison function with an additionnal argument
+//
+// A test with a comparison function which ignores comment lines.
+//
+// Define the filter
+function otxt = myfilter2 ( itxt , pattern )
+ nr = size(itxt,"r")
+ k = 1
+ for i = 1 : nr
+ start = regexp(itxt(i),pattern)
+ if ( start == [] ) then
+ otxt(k) = itxt(i)
+ k = k + 1
+ end
+ end
+endfunction
+//
+// Check that the filter works as expected.
+// This is the pattern for a comment line of the form "// blabla"
+pattern = "/\/\/.*/"
+ pattern =
+
+ /\/\/.*/
+itxt = [
+ "bla 1"
+ "// bla 2"
+ "bla 3"
+ "// bla 4"
+ "bla 5"
+ ];
+otxt = myfilter2 ( itxt , pattern );
+etxt = [
+ "bla 1"
+ "bla 3"
+ "bla 5"
+ ];
+MY_assert_equal ( otxt , etxt );
+//
+// Define the comparison function
+function areequal = mycompfun2 ( ctxt , etxt , pattern )
+ ctxt = myfilter2 ( ctxt , pattern )
+ etxt = myfilter2 ( etxt , pattern )
+ areequal = ( ctxt == etxt )
+endfunction
+//
+// A test which pass
+mycompfun2 = list ( mycompfun2 , pattern );
+Warning : redefining function: mycompfun2 . Use funcprot(0) to avoid this message
+
+[flag,errmsg] = assert_checkfilesequal ( filecomp3 , fileref2 , mycompfun2 );
+checkassert ( flag , errmsg , "success" );
+//
+// A test which fails
+[flag,errmsg] = assert_checkfilesequal ( filecomp4 , fileref2 , mycompfun2 );
+checkassert ( flag , errmsg , "failure" );
--- /dev/null
+// Copyright (C) 2008 - INRIA - Michael Baudin
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+function flag = MY_assert_equal ( computed , expected )
+ if computed==expected then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then pause,end
+endfunction
+
+function checkassert ( flag , errmsg , ctype )
+ if ( ctype == "success" ) then
+ MY_assert_equal ( (flag==%t) & (errmsg==""), %t )
+ else
+ MY_assert_equal ( (flag==%f) & (errmsg<>""), %t )
+ end
+endfunction
+
+format("v",10);
+
+// Check error message when number of arguments is false
+instr = "assert_checkfilesequal ( )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkfilesequal ( ""foo.txt"" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "[o1,o2,o3]=assert_checkfilesequal ( ""foo.txt"" , ""foo.txt"" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 59 );
+//
+//////////////////////////////////////////
+//
+// Check error message when type of arguments is false
+instr = "assert_checkfilesequal ( ""foo.txt"" , %t )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkfilesequal ( %t , ""foo.txt"" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkfilesequal ( %t , %t )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+//////////////////////////////////////////
+//
+// Check error message when size of arguments is false
+instr = "assert_checkfilesequal ( [ ""foo.txt"" ""foo.txt"" ] , ""foo.txt"" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "assert_checkfilesequal ( ""foo.txt"" , [ ""foo.txt"" ""foo.txt"" ] )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+//////////////////////////////////////////
+//
+// Prepare data for the tests
+// fileref1 : three lines of text.
+// filecomp1 : == fileref1
+// filecomp2 : <> fileref1
+//
+// fileref1
+fileref1 = fullfile(TMPDIR,"fileref.txt");
+txt1 = [
+ "Line #1"
+ "Line #2"
+ "Line #3"
+];
+fd = mopen(fileref1,"w");
+mputl(txt1,fd);
+mclose(fd);
+//
+// filecomp1
+filecomp1 = fullfile(TMPDIR,"filecomp1.txt");
+fd = mopen(filecomp1,"w");
+mputl(txt1,fd);
+mclose(fd);
+//
+filecomp2 = fullfile(TMPDIR,"filecomp2.txt");
+txt2 = [
+ "Line #1"
+ "Line #4"
+ "Line #3"
+];
+fd = mopen(filecomp2,"w");
+mputl(txt2,fd);
+mclose(fd);
+//
+//////////////////////////////////////////
+//
+// A test which pass
+[flag,errmsg] = assert_checkfilesequal ( filecomp1 , fileref1 );
+checkassert ( flag , errmsg , "success" );
+//
+// A test which pass.
+// Replay it, to make sure that the files are correctly closed.
+[flag,errmsg] = assert_checkfilesequal ( filecomp1 , fileref1 );
+checkassert ( flag , errmsg , "success" );
+//
+// Failure: filecomp2 <> fileref1
+[flag,errmsg] = assert_checkfilesequal ( filecomp2 , fileref1 );
+checkassert ( flag , errmsg , "failure" );
+//
+// Failure: filecomp2 <> fileref1
+// Replay it, to make sure that the files are correctly closed.
+[flag,errmsg] = assert_checkfilesequal ( filecomp2 , fileref1 );
+checkassert ( flag , errmsg , "failure" );
+//
+// Failure: fileref does not exist.
+[flag,errmsg] = assert_checkfilesequal ( filecomp2 , "foo.txt" );
+checkassert ( flag , errmsg , "failure" );
+//
+// Failure: filecomp does not exist.
+[flag,errmsg] = assert_checkfilesequal ( "foo.txt" , fileref1 );
+checkassert ( flag , errmsg , "failure" );
+//
+//////////////////////////////////////////
+//
+// A test with a comparison function which ignores comment lines.
+//
+// Define the filter
+function otxt = myfilter ( itxt )
+ nr = size(itxt,"r")
+ // This is the pattern for a comment line of the form "// blabla"
+ pattern = "/\/\/.*/"
+ k = 1
+ for i = 1 : nr
+ start = regexp(itxt(i),pattern)
+ if ( start == [] ) then
+ otxt(k) = itxt(i)
+ k = k + 1
+ end
+ end
+endfunction
+//
+// Check that the filter works as expected.
+itxt = [
+ "bla 1"
+ "// bla 2"
+ "bla 3"
+ "// bla 4"
+ "bla 5"
+ ];
+otxt = myfilter ( itxt );
+etxt = [
+ "bla 1"
+ "bla 3"
+ "bla 5"
+ ];
+MY_assert_equal ( otxt , etxt );
+//
+// Define the comparison function
+function areequal = mycompfun ( ctxt , etxt )
+ ctxt = myfilter ( ctxt )
+ etxt = myfilter ( etxt )
+ areequal = ( ctxt == etxt )
+endfunction
+
+//
+// Use the comparison function.
+// fileref2 == filecomp3, given that comment lines are ignored.
+// fileref2 <> filecomp4, given that comment lines are ignored.
+// Notice that the comments are inserted at different positions in the files:
+// sometimes at the begining, sometimes in the middle.
+//
+// Prepare data files
+//
+// fileref2
+fileref2 = fullfile(TMPDIR,"fileref2.txt");
+txt = [
+ "// bla 2"
+ "Line #1"
+ "// bla 2"
+ "Line #2"
+ "Line #3"
+];
+fd = mopen(fileref2,"w");
+mputl(txt,fd);
+mclose(fd);
+//
+// filecomp3
+filecomp3 = fullfile(TMPDIR,"filecomp3.txt");
+txt = [
+ "Line #1"
+ "// bla 5168"
+ "Line #2"
+ "Line #3"
+ "// bla oups"
+];
+fd = mopen(filecomp3,"w");
+mputl(txt,fd);
+mclose(fd);
+//
+// filecomp4
+filecomp4 = fullfile(TMPDIR,"filecomp4.txt");
+txt = [
+ "// bla 3"
+ "Line #1"
+ "Line #4"
+ "// bla 5168"
+ "Line #3"
+ "// bla oups"
+];
+fd = mopen(filecomp4,"w");
+mputl(txt,fd);
+mclose(fd);
+//
+// A test which pass
+[flag,errmsg] = assert_checkfilesequal ( filecomp3 , fileref2 , mycompfun );
+checkassert ( flag , errmsg , "success" );
+//
+// A test which fails
+[flag,errmsg] = assert_checkfilesequal ( filecomp4 , fileref2 , mycompfun );
+checkassert ( flag , errmsg , "failure" );
+//
+///////////////////////////////////////////////////////////////////
+//
+// A comparison function with an additionnal argument
+//
+// A test with a comparison function which ignores comment lines.
+//
+// Define the filter
+function otxt = myfilter2 ( itxt , pattern )
+ nr = size(itxt,"r")
+ k = 1
+ for i = 1 : nr
+ start = regexp(itxt(i),pattern)
+ if ( start == [] ) then
+ otxt(k) = itxt(i)
+ k = k + 1
+ end
+ end
+endfunction
+//
+// Check that the filter works as expected.
+// This is the pattern for a comment line of the form "// blabla"
+pattern = "/\/\/.*/"
+itxt = [
+ "bla 1"
+ "// bla 2"
+ "bla 3"
+ "// bla 4"
+ "bla 5"
+ ];
+otxt = myfilter2 ( itxt , pattern );
+etxt = [
+ "bla 1"
+ "bla 3"
+ "bla 5"
+ ];
+MY_assert_equal ( otxt , etxt );
+//
+// Define the comparison function
+function areequal = mycompfun2 ( ctxt , etxt , pattern )
+ ctxt = myfilter2 ( ctxt , pattern )
+ etxt = myfilter2 ( etxt , pattern )
+ areequal = ( ctxt == etxt )
+endfunction
+//
+// A test which pass
+mycompfun2 = list ( mycompfun2 , pattern );
+[flag,errmsg] = assert_checkfilesequal ( filecomp3 , fileref2 , mycompfun2 );
+checkassert ( flag , errmsg , "success" );
+//
+// A test which fails
+[flag,errmsg] = assert_checkfilesequal ( filecomp4 , fileref2 , mycompfun2 );
+checkassert ( flag , errmsg , "failure" );
+
--- /dev/null
+// Copyright (C) 2008 - INRIA - Michael Baudin
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+function flag = MY_assert_equal ( computed , expected )
+ if computed==expected then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then bugmes();quit;end
+endfunction
+function checkassert ( flag , errmsg , ctype )
+ if ( ctype == "success" ) then
+ MY_assert_equal ( (flag==%t) & (errmsg==""), %t )
+ else
+ MY_assert_equal ( (flag==%f) & (errmsg<>""), %t )
+ end
+endfunction
+format("v",10);
+// Check error message when number of arguments is false
+instr = "assert_checktrue ( )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "[o1,o2,o3]=assert_checktrue ( %t )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 59 );
+//////////////////////////////////////////
+// Check error message when type of arguments is false
+instr = "assert_checktrue ( ""a"" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+//
+// Check that the error message is correctly handled.
+instr = "assert_checktrue ( [%f %t] )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+errmsg = lasterror();
+MY_assert_equal ( errmsg , "assert_checktrue: Assertion failed: found false entry in condition = [F ...]" );
+//
+[flag,errmsg] = assert_checktrue ( %t );
+checkassert ( flag , errmsg , "success" );
+//
+[flag,errmsg] = assert_checktrue ( [%t %t] );
+checkassert ( flag , errmsg , "success" );
+//
+[flag,errmsg] = assert_checktrue ( %f );
+checkassert ( flag , errmsg , "failure" );
+//
+[flag,errmsg] = assert_checktrue ( [%t %f] );
+checkassert ( flag , errmsg , "failure" );
--- /dev/null
+// Copyright (C) 2008 - INRIA - Michael Baudin
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+function flag = MY_assert_equal ( computed , expected )
+ if computed==expected then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then pause,end
+endfunction
+
+function checkassert ( flag , errmsg , ctype )
+ if ( ctype == "success" ) then
+ MY_assert_equal ( (flag==%t) & (errmsg==""), %t )
+ else
+ MY_assert_equal ( (flag==%f) & (errmsg<>""), %t )
+ end
+endfunction
+
+format("v",10);
+
+// Check error message when number of arguments is false
+instr = "assert_checktrue ( )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+instr = "[o1,o2,o3]=assert_checktrue ( %t )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 59 );
+//////////////////////////////////////////
+// Check error message when type of arguments is false
+instr = "assert_checktrue ( ""a"" )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+//
+//
+// Check that the error message is correctly handled.
+instr = "assert_checktrue ( [%f %t] )";
+ierr=execstr(instr,"errcatch");
+MY_assert_equal ( ierr , 10000 );
+errmsg = lasterror();
+MY_assert_equal ( errmsg , "assert_checktrue: Assertion failed: found false entry in condition = [F ...]" );
+//
+[flag,errmsg] = assert_checktrue ( %t );
+checkassert ( flag , errmsg , "success" );
+//
+[flag,errmsg] = assert_checktrue ( [%t %t] );
+checkassert ( flag , errmsg , "success" );
+//
+[flag,errmsg] = assert_checktrue ( %f );
+checkassert ( flag , errmsg , "failure" );
+//
+[flag,errmsg] = assert_checktrue ( [%t %f] );
+checkassert ( flag , errmsg , "failure" );
+
--- /dev/null
+// Copyright (C) 2008 - INRIA - Michael Baudin
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+function flag = MY_assert_equal ( computed , expected )
+ if computed==expected then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then bugmes();quit;end
+endfunction
+// Compare real values
+order = assert_comparecomplex ( 1 , -1 );
+MY_assert_equal ( order , 1 );
+//
+order = assert_comparecomplex ( -1 , 1 );
+MY_assert_equal ( order , -1 );
+//
+order = assert_comparecomplex ( 1 , 1 );
+MY_assert_equal ( order , 0 );
+//
+order = assert_comparecomplex ( 1 , -1 , %eps , 0 );
+MY_assert_equal ( order , 1 );
+//
+order = assert_comparecomplex ( -1 , 1 , %eps , 0 );
+MY_assert_equal ( order , -1 );
+//
+order = assert_comparecomplex ( 1 , 1 , %eps , 0 );
+MY_assert_equal ( order , 0 );
+//
+// Compare complex values #1
+order = assert_comparecomplex ( 1+2*%i , 1+3*%i , %eps , 0 );
+MY_assert_equal ( order , -1 );
+//
+order = assert_comparecomplex ( 1+3*%i , 1+2*%i , %eps , 0 );
+MY_assert_equal ( order , 1 );
+//
+order = assert_comparecomplex ( 1+2*%i , 1+2*%i , %eps , 0 );
+MY_assert_equal ( order , 0 );
+//
+order = assert_comparecomplex ( 1+2*%i , 1+3*%i );
+MY_assert_equal ( order , -1 );
+//
+order = assert_comparecomplex ( 1+3*%i , 1+2*%i );
+MY_assert_equal ( order , 1 );
+//
+order = assert_comparecomplex ( 1+2*%i , 1+2*%i );
+MY_assert_equal ( order , 0 );
+//
+// Compare complex values #2
+order = assert_comparecomplex ( 1+%i , -1+%i );
+MY_assert_equal ( order , 1 );
+//
+order = assert_comparecomplex ( -1+%i , 1+%i );
+MY_assert_equal ( order , -1 );
+//
+order = assert_comparecomplex ( 1+%i , 1+%i );
+MY_assert_equal ( order , 0 );
+//
+order = assert_comparecomplex ( 1+%i , -1+%i , %eps , 0 );
+MY_assert_equal ( order , 1 );
+//
+order = assert_comparecomplex ( -1+%i , 1+%i , %eps , 0 );
+MY_assert_equal ( order , -1 );
+//
+order = assert_comparecomplex ( 1+%i , 1+%i , %eps , 0 );
+MY_assert_equal ( order , 0 );
+//
+// Compare with tolerances : equality cases
+order = assert_comparecomplex ( 1.2345+%i , 1.2346+%i , %eps , 1.e-3 );
+MY_assert_equal ( order , 0 );
+//
+order = assert_comparecomplex ( 1.2345+%i , 1.2346+%i , 1.e12*%eps , 0 );
+MY_assert_equal ( order , 0 );
+//
+order = assert_comparecomplex ( 1+1.2345*%i , 1+1.2347*%i , %eps , 1.e-3 );
+MY_assert_equal ( order , 0 );
+//
+order = assert_comparecomplex ( 1+1.2345*%i , 1+1.2347*%i , 1.e12*%eps , 0 );
+MY_assert_equal ( order , 0 );
+//
+// Compare more realistic data
+x = [
+-0.123452 - 0.123454 * %i
+-0.123451 + 0.123453 * %i
+0.123458 - 0.123459 * %i
+0.123456 + 0.123457 * %i
+];
+// Consider less than 4 significant digits
+for i = 1 : size(x,"*")-1
+ order(i) = assert_comparecomplex ( x(i) , x(i+1) , 1.e-4 );
+end
+MY_assert_equal ( order , -ones(3,1) );
+clear order;
+// Compare data from bug #415
+x = [
+-1.9914145
+-1.895889
+-1.6923826
+-1.4815461
+-1.1302576
+-0.5652256 - 0.0655080 * %i
+-0.5652256 + 0.0655080 * %i
+0.3354023 - 0.1602902 * %i
+0.3354023 + 0.1602902 * %i
+1.3468911
+1.5040136
+1.846668
+1.9736772
+1.9798866
+];
+// Consider less than 4 significant digits
+for i = 1 : size(x,"*")-1
+ order(i) = assert_comparecomplex ( x(i) , x(i+1) , 1.e-5 );
+end
+MY_assert_equal ( order , -ones(13,1) );
+clear order;
+//
+order = assert_comparecomplex ( 1 , 1 );
+MY_assert_equal ( order , 0 );
+//
+order = assert_comparecomplex ( 1+%eps , 1 );
+MY_assert_equal ( order , 0 );
+//
+order = assert_comparecomplex ( 0 , 0 , 0 , 1.e-5 );
+MY_assert_equal ( order , 0 );
+//
+order = assert_comparecomplex ( 1 , 2 );
+MY_assert_equal ( order , -1 );
+//
+order = assert_comparecomplex ( 1.e-4 , 0 , 0 , 1.e-5 );
+MY_assert_equal ( order , 1 );
+//
+// Success: not obvious!
+// The two values are equal, very small, but nonzero.
+// The relative tolerance must be used here.
+// If, instead, a bug in the assert function is so that the
+// absolute tolerance is used as 10^-16, then the output
+// of this comparison is wrong.
+order = assert_comparecomplex ( 1.23456789123456789e-30 , 1.23456789123456789e-30 );
+MY_assert_equal ( order , 0 );
+//
+// Failure : not obvious!
+// There is only one significant digit here and we require the
+// maximum precision.
+// The test must fail because the relative tolerance must be used here.
+// If, instead, there is a bug in the comparison and
+// the absolute tolerance is used and set to
+// 10^-16, the output of this test is wrong.
+order = assert_comparecomplex ( 1.23456789123456789e-30 , 1.3e-30 );
+MY_assert_equal ( order , -1 );
+//
+// Success : not obvious!
+// The expected result is zero, so that the absolute tolerance is used.
+order = assert_comparecomplex ( 1.23456789123456789e-30 , 0 , 0 , 1.e-10 );
+MY_assert_equal ( order , 0 );
+//
+// Check that slightly different values cannot pass basic test
+// Simple sequence with default settings
+order = assert_comparecomplex ( 1 + 5 * %eps , 1 , %eps );
+MY_assert_equal ( order , 1 );
+//
+// Customize the relative precision so that a test can pass
+// Simple sequence with default settings
+order = assert_comparecomplex ( 1 + 5 * %eps , 1 , 10*%eps , 0 );
+MY_assert_equal ( order , 0 );
+//
+// Customize the absolute precision so that a test can pass
+// Simple sequence with default settings
+order = assert_comparecomplex ( 5 * %eps , 0 , 0 , 10*%eps );
+MY_assert_equal ( order , 0 );
+//
+// An example where the relative error is used,
+// with a customized tolerance.
+order = assert_comparecomplex ( 1.23456 , 1.23457 , 1.e11*%eps , 0 );
+MY_assert_equal ( order , 0 );
+//
+// Test all IEEE values
+// We choose -%inf < 0 < %inf < %nan.
+table = [
+ %inf 0 1
+ %inf %inf 0
+ %inf -%inf 1
+ %inf %nan -1
+ -%inf 0 -1
+ -%inf %inf -1
+ -%inf -%inf 0
+ -%inf %nan -1
+ %nan 0 1
+ %nan %inf 1
+ %nan -%inf 1
+ %nan %nan 0
+ 0 0 0
+ 0 %inf -1
+ 0 -%inf 1
+ 0 %nan -1
+];
+ntests = size(table,"r");
+for i = 1 : ntests
+ a = table(i,1);
+ b = table(i,2);
+ expected = table(i,3);
+ order = assert_comparecomplex ( a , b );
+ MY_assert_equal ( order , expected );
+ order = assert_comparecomplex ( b , a );
+ MY_assert_equal ( order , -expected );
+end
--- /dev/null
+// Copyright (C) 2008 - INRIA - Michael Baudin
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+function flag = MY_assert_equal ( computed , expected )
+ if computed==expected then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then pause,end
+endfunction
+
+// Compare real values
+order = assert_comparecomplex ( 1 , -1 );
+MY_assert_equal ( order , 1 );
+//
+order = assert_comparecomplex ( -1 , 1 );
+MY_assert_equal ( order , -1 );
+//
+order = assert_comparecomplex ( 1 , 1 );
+MY_assert_equal ( order , 0 );
+//
+order = assert_comparecomplex ( 1 , -1 , %eps , 0 );
+MY_assert_equal ( order , 1 );
+//
+order = assert_comparecomplex ( -1 , 1 , %eps , 0 );
+MY_assert_equal ( order , -1 );
+//
+order = assert_comparecomplex ( 1 , 1 , %eps , 0 );
+MY_assert_equal ( order , 0 );
+//
+
+// Compare complex values #1
+order = assert_comparecomplex ( 1+2*%i , 1+3*%i , %eps , 0 );
+MY_assert_equal ( order , -1 );
+//
+order = assert_comparecomplex ( 1+3*%i , 1+2*%i , %eps , 0 );
+MY_assert_equal ( order , 1 );
+//
+order = assert_comparecomplex ( 1+2*%i , 1+2*%i , %eps , 0 );
+MY_assert_equal ( order , 0 );
+//
+order = assert_comparecomplex ( 1+2*%i , 1+3*%i );
+MY_assert_equal ( order , -1 );
+//
+order = assert_comparecomplex ( 1+3*%i , 1+2*%i );
+MY_assert_equal ( order , 1 );
+//
+order = assert_comparecomplex ( 1+2*%i , 1+2*%i );
+MY_assert_equal ( order , 0 );
+//
+
+// Compare complex values #2
+order = assert_comparecomplex ( 1+%i , -1+%i );
+MY_assert_equal ( order , 1 );
+//
+order = assert_comparecomplex ( -1+%i , 1+%i );
+MY_assert_equal ( order , -1 );
+//
+order = assert_comparecomplex ( 1+%i , 1+%i );
+MY_assert_equal ( order , 0 );
+//
+order = assert_comparecomplex ( 1+%i , -1+%i , %eps , 0 );
+MY_assert_equal ( order , 1 );
+//
+order = assert_comparecomplex ( -1+%i , 1+%i , %eps , 0 );
+MY_assert_equal ( order , -1 );
+//
+order = assert_comparecomplex ( 1+%i , 1+%i , %eps , 0 );
+MY_assert_equal ( order , 0 );
+//
+
+// Compare with tolerances : equality cases
+order = assert_comparecomplex ( 1.2345+%i , 1.2346+%i , %eps , 1.e-3 );
+MY_assert_equal ( order , 0 );
+//
+order = assert_comparecomplex ( 1.2345+%i , 1.2346+%i , 1.e12*%eps , 0 );
+MY_assert_equal ( order , 0 );
+//
+order = assert_comparecomplex ( 1+1.2345*%i , 1+1.2347*%i , %eps , 1.e-3 );
+MY_assert_equal ( order , 0 );
+//
+order = assert_comparecomplex ( 1+1.2345*%i , 1+1.2347*%i , 1.e12*%eps , 0 );
+MY_assert_equal ( order , 0 );
+//
+
+// Compare more realistic data
+x = [
+-0.123452 - 0.123454 * %i
+-0.123451 + 0.123453 * %i
+0.123458 - 0.123459 * %i
+0.123456 + 0.123457 * %i
+];
+// Consider less than 4 significant digits
+for i = 1 : size(x,"*")-1
+ order(i) = assert_comparecomplex ( x(i) , x(i+1) , 1.e-4 );
+end
+MY_assert_equal ( order , -ones(3,1) );
+clear order;
+
+// Compare data from bug #415
+x = [
+-1.9914145
+-1.895889
+-1.6923826
+-1.4815461
+-1.1302576
+-0.5652256 - 0.0655080 * %i
+-0.5652256 + 0.0655080 * %i
+0.3354023 - 0.1602902 * %i
+0.3354023 + 0.1602902 * %i
+1.3468911
+1.5040136
+1.846668
+1.9736772
+1.9798866
+];
+// Consider less than 4 significant digits
+for i = 1 : size(x,"*")-1
+ order(i) = assert_comparecomplex ( x(i) , x(i+1) , 1.e-5 );
+end
+MY_assert_equal ( order , -ones(13,1) );
+clear order;
+//
+order = assert_comparecomplex ( 1 , 1 );
+MY_assert_equal ( order , 0 );
+//
+order = assert_comparecomplex ( 1+%eps , 1 );
+MY_assert_equal ( order , 0 );
+//
+order = assert_comparecomplex ( 0 , 0 , 0 , 1.e-5 );
+MY_assert_equal ( order , 0 );
+//
+order = assert_comparecomplex ( 1 , 2 );
+MY_assert_equal ( order , -1 );
+//
+order = assert_comparecomplex ( 1.e-4 , 0 , 0 , 1.e-5 );
+MY_assert_equal ( order , 1 );
+//
+// Success: not obvious!
+// The two values are equal, very small, but nonzero.
+// The relative tolerance must be used here.
+// If, instead, a bug in the assert function is so that the
+// absolute tolerance is used as 10^-16, then the output
+// of this comparison is wrong.
+order = assert_comparecomplex ( 1.23456789123456789e-30 , 1.23456789123456789e-30 );
+MY_assert_equal ( order , 0 );
+//
+// Failure : not obvious!
+// There is only one significant digit here and we require the
+// maximum precision.
+// The test must fail because the relative tolerance must be used here.
+// If, instead, there is a bug in the comparison and
+// the absolute tolerance is used and set to
+// 10^-16, the output of this test is wrong.
+order = assert_comparecomplex ( 1.23456789123456789e-30 , 1.3e-30 );
+MY_assert_equal ( order , -1 );
+//
+// Success : not obvious!
+// The expected result is zero, so that the absolute tolerance is used.
+order = assert_comparecomplex ( 1.23456789123456789e-30 , 0 , 0 , 1.e-10 );
+MY_assert_equal ( order , 0 );
+//
+// Check that slightly different values cannot pass basic test
+// Simple sequence with default settings
+order = assert_comparecomplex ( 1 + 5 * %eps , 1 , %eps );
+MY_assert_equal ( order , 1 );
+//
+// Customize the relative precision so that a test can pass
+// Simple sequence with default settings
+order = assert_comparecomplex ( 1 + 5 * %eps , 1 , 10*%eps , 0 );
+MY_assert_equal ( order , 0 );
+//
+// Customize the absolute precision so that a test can pass
+// Simple sequence with default settings
+order = assert_comparecomplex ( 5 * %eps , 0 , 0 , 10*%eps );
+MY_assert_equal ( order , 0 );
+//
+// An example where the relative error is used,
+// with a customized tolerance.
+order = assert_comparecomplex ( 1.23456 , 1.23457 , 1.e11*%eps , 0 );
+MY_assert_equal ( order , 0 );
+//
+// Test all IEEE values
+// We choose -%inf < 0 < %inf < %nan.
+table = [
+ %inf 0 1
+ %inf %inf 0
+ %inf -%inf 1
+ %inf %nan -1
+ -%inf 0 -1
+ -%inf %inf -1
+ -%inf -%inf 0
+ -%inf %nan -1
+ %nan 0 1
+ %nan %inf 1
+ %nan -%inf 1
+ %nan %nan 0
+ 0 0 0
+ 0 %inf -1
+ 0 -%inf 1
+ 0 %nan -1
+];
+ntests = size(table,"r");
+for i = 1 : ntests
+ a = table(i,1);
+ b = table(i,2);
+ expected = table(i,3);
+ order = assert_comparecomplex ( a , b );
+ MY_assert_equal ( order , expected );
+ order = assert_comparecomplex ( b , a );
+ MY_assert_equal ( order , -expected );
+end
+
--- /dev/null
+// Copyright (C) 2008 - INRIA - Michael Baudin
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+function flag = MY_assert_equal ( computed , expected )
+ if computed==expected then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then bugmes();quit;end
+endfunction
+format("v",10);
+//
+dmax = -log10(2^(-53));
+//
+computed = assert_computedigits ( 1 , 1 );
+MY_assert_equal ( computed , dmax );
+//
+computed = assert_computedigits ( 0 , 0 );
+MY_assert_equal ( computed , dmax );
+//
+computed = assert_computedigits ( 1 , 0 );
+MY_assert_equal ( computed , 0 );
+//
+computed = assert_computedigits ( 0 , 1 );
+MY_assert_equal ( computed , 0 );
+//
+computed = assert_computedigits ( 3.1415926 , %pi );
+MY_assert_equal ( computed , 7.76806779280040160 );
+//
+computed = assert_computedigits ( 3.1415926 , %pi , 2 );
+MY_assert_equal ( computed , 25.80496264389331884 );
+//
+computed = assert_computedigits ( [0 0 1 1] , [0 1 0 1] );
+MY_assert_equal ( computed , [dmax 0 0 dmax] );
+//
+computed = assert_computedigits(ones(3,2),ones(3,2));
+MY_assert_equal ( computed , dmax * ones(3,2) );
+//
+computed = assert_computedigits([%nan %nan %nan %nan],[%nan %inf -%inf 0]);
+MY_assert_equal ( computed , [dmax 0 0 0] );
+//
+computed = assert_computedigits([%inf %inf %inf %inf],[%nan %inf -%inf 0]);
+MY_assert_equal ( computed , [0 dmax 0 0] );
+//
+computed = assert_computedigits([-%inf -%inf -%inf -%inf],[%nan %inf -%inf 0]);
+MY_assert_equal ( computed , [0 0 dmax 0] );
+//
+computed = assert_computedigits([0 0 0 0],[%nan %inf -%inf 0]);
+MY_assert_equal ( computed , [0 0 0 dmax] );
+//
+computed = assert_computedigits(1.224646799D-16,8.462643383D-18);
+MY_assert_equal ( computed , 0 );
+//
+computed = assert_computedigits ( 1.2345 + %i*6.7891 , 1.23456789 + %i*6.789123456 );
+MY_assert_equal ( computed , 4.259709168495138698 );
+//
+// The sign bit of the number of digits may be wrong because
+// ieee(2); z=max(-0,0); 1/z is -%inf
+back = ieee();
+ieee(2);
+computed = assert_computedigits ( 1.e-305 , 0 );
+MY_assert_equal ( 1/computed , %inf );
+//
+computed = assert_computedigits ( 0 , 1.e-305 );
+MY_assert_equal ( 1/computed , %inf );
+ieee(back);
--- /dev/null
+// Copyright (C) 2008 - INRIA - Michael Baudin
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+function flag = MY_assert_equal ( computed , expected )
+ if computed==expected then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then pause,end
+endfunction
+
+format("v",10);
+
+//
+dmax = -log10(2^(-53));
+//
+computed = assert_computedigits ( 1 , 1 );
+MY_assert_equal ( computed , dmax );
+//
+computed = assert_computedigits ( 0 , 0 );
+MY_assert_equal ( computed , dmax );
+//
+computed = assert_computedigits ( 1 , 0 );
+MY_assert_equal ( computed , 0 );
+//
+computed = assert_computedigits ( 0 , 1 );
+MY_assert_equal ( computed , 0 );
+//
+computed = assert_computedigits ( 3.1415926 , %pi );
+MY_assert_equal ( computed , 7.76806779280040160 );
+//
+computed = assert_computedigits ( 3.1415926 , %pi , 2 );
+MY_assert_equal ( computed , 25.80496264389331884 );
+//
+computed = assert_computedigits ( [0 0 1 1] , [0 1 0 1] );
+MY_assert_equal ( computed , [dmax 0 0 dmax] );
+//
+computed = assert_computedigits(ones(3,2),ones(3,2));
+MY_assert_equal ( computed , dmax * ones(3,2) );
+//
+computed = assert_computedigits([%nan %nan %nan %nan],[%nan %inf -%inf 0]);
+MY_assert_equal ( computed , [dmax 0 0 0] );
+//
+computed = assert_computedigits([%inf %inf %inf %inf],[%nan %inf -%inf 0]);
+MY_assert_equal ( computed , [0 dmax 0 0] );
+//
+computed = assert_computedigits([-%inf -%inf -%inf -%inf],[%nan %inf -%inf 0]);
+MY_assert_equal ( computed , [0 0 dmax 0] );
+//
+computed = assert_computedigits([0 0 0 0],[%nan %inf -%inf 0]);
+MY_assert_equal ( computed , [0 0 0 dmax] );
+//
+computed = assert_computedigits(1.224646799D-16,8.462643383D-18);
+MY_assert_equal ( computed , 0 );
+//
+computed = assert_computedigits ( 1.2345 + %i*6.7891 , 1.23456789 + %i*6.789123456 );
+MY_assert_equal ( computed , 4.259709168495138698 );
+//
+// The sign bit of the number of digits may be wrong because
+// ieee(2); z=max(-0,0); 1/z is -%inf
+back = ieee();
+ieee(2);
+computed = assert_computedigits ( 1.e-305 , 0 );
+MY_assert_equal ( 1/computed , %inf );
+//
+computed = assert_computedigits ( 0 , 1.e-305 );
+MY_assert_equal ( 1/computed , %inf );
+ieee(back);
+
--- /dev/null
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+function flag = MY_assert_equal ( computed , expected )
+ if computed==expected then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then bugmes();quit;end
+endfunction
+//
+condition = [
+ 0
+ 1
+ 1.e1
+ 1.e2
+ 1.e3
+ 1.e13
+ 1.e14
+ 1.e15
+ 1.e16
+ 1.e17
+ 1.e18
+];
+computed = assert_cond2reltol ( condition );
+expected = [
+ 1.110223024625162210D-16
+ 1.110223024625162210D-16
+ 1.110223024625162260D-15
+ 1.110223024625162220D-14
+ 1.110223024625162220D-13
+ 1.110223024625157625D-03
+ 1.110223024625162265D-02
+ 1.110223024625157789D-01
+ 1.000000000000000000D+00
+ 1.000000000000000000D+00
+ 1.000000000000000000D+00
+];
+MY_assert_equal ( computed , expected );
+//
+// With offset
+computed = assert_cond2reltol ( 1.e2 , [5 4 3 2 1 0 -1 -2 -3 -4 -5]' );
+expected = [
+ 1.110223024625162210D-16
+ 1.110223024625162210D-16
+ 1.110223024625162210D-16
+ 1.110223024625162210D-16
+ 1.110223024625162260D-15
+ 1.110223024625162220D-14
+ 1.110223024625162220D-13
+ 1.110223024625162195D-12
+ 1.110223024625162195D-11
+ 1.110223024625162227D-10
+ 1.110223024625162331D-09
+];
+MY_assert_equal ( computed , expected );
+//
+computed = assert_cond2reltol ( 1.e14 , [0 -1 -2 -3] );
+expected = [1.110223024625162265D-02 1.110223024625162230D-01 1.000000000000000000D+00 1.000000000000000000D+00];
+MY_assert_equal ( computed , expected );
+//
+computed = assert_cond2reltol ( 1.e2 , [0 1 2 3] ) ;
+expected = [1.110223024625162220D-14 1.110223024625162260D-15 1.110223024625162210D-16 1.110223024625162210D-16];
+MY_assert_equal ( computed , expected );
--- /dev/null
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+function flag = MY_assert_equal ( computed , expected )
+ if computed==expected then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then pause,end
+endfunction
+
+//
+condition = [
+ 0
+ 1
+ 1.e1
+ 1.e2
+ 1.e3
+ 1.e13
+ 1.e14
+ 1.e15
+ 1.e16
+ 1.e17
+ 1.e18
+];
+computed = assert_cond2reltol ( condition );
+expected = [
+ 1.110223024625162210D-16
+ 1.110223024625162210D-16
+ 1.110223024625162260D-15
+ 1.110223024625162220D-14
+ 1.110223024625162220D-13
+ 1.110223024625157625D-03
+ 1.110223024625162265D-02
+ 1.110223024625157789D-01
+ 1.000000000000000000D+00
+ 1.000000000000000000D+00
+ 1.000000000000000000D+00
+];
+MY_assert_equal ( computed , expected );
+//
+// With offset
+computed = assert_cond2reltol ( 1.e2 , [5 4 3 2 1 0 -1 -2 -3 -4 -5]' );
+expected = [
+ 1.110223024625162210D-16
+ 1.110223024625162210D-16
+ 1.110223024625162210D-16
+ 1.110223024625162210D-16
+ 1.110223024625162260D-15
+ 1.110223024625162220D-14
+ 1.110223024625162220D-13
+ 1.110223024625162195D-12
+ 1.110223024625162195D-11
+ 1.110223024625162227D-10
+ 1.110223024625162331D-09
+];
+MY_assert_equal ( computed , expected );
+//
+computed = assert_cond2reltol ( 1.e14 , [0 -1 -2 -3] );
+expected = [1.110223024625162265D-02 1.110223024625162230D-01 1.000000000000000000D+00 1.000000000000000000D+00];
+MY_assert_equal ( computed , expected );
+//
+computed = assert_cond2reltol ( 1.e2 , [0 1 2 3] ) ;
+expected = [1.110223024625162220D-14 1.110223024625162260D-15 1.110223024625162210D-16 1.110223024625162210D-16];
+MY_assert_equal ( computed , expected );
+
--- /dev/null
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+function flag = MY_assert_equal ( computed , expected )
+ if computed==expected then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then bugmes();quit;end
+endfunction
+//
+condition = [
+ 0
+ 1
+ 1.e1
+ 1.e2
+ 1.e3
+ 1.e13
+ 1.e14
+ 1.e15
+ 1.e16
+ 1.e17
+ 1.e18
+];
+computed = assert_cond2reqdigits ( condition );
+expected = [
+ 15.954589770191001107946
+ 15.954589770191001107946
+ 14.954589770191001107946
+ 13.954589770191001107946
+ 12.954589770191001107946
+ 2.954589770191002884303
+ 1.9545897701910011079462
+ 0.954589770191002884303
+ 0.
+ 0.
+ 0.
+];
+MY_assert_equal ( computed , expected );
+//
+// With offset
+computed = assert_cond2reqdigits ( 1.e2 , [5 4 3 2 1 0 -1 -2 -3 -4 -5]' );
+expected = [
+ 15.954589770191001107946
+ 15.954589770191001107946
+ 15.954589770191001107946
+ 15.954589770191001107946
+ 14.954589770191001107946
+ 13.954589770191001107946
+ 12.954589770191001107946
+ 11.954589770191001107946
+ 10.954589770191001107946
+ 9.9545897701910011079462
+ 8.9545897701910011079462
+];
+MY_assert_equal ( computed , expected );
+//
+computed = assert_cond2reqdigits ( 1.e14 , [0 -1 -2 -3] );
+expected = [1.9545897701910011079462 0.9545897701910011079462 0. 0.];
+MY_assert_equal ( computed , expected );
+//
+computed = assert_cond2reqdigits ( 1.e2 , [0 1 2 3] ) ;
+expected = [13.954589770191001107946 14.954589770191001107946 15.954589770191001107946 15.954589770191001107946];
+MY_assert_equal ( computed , expected );
+//
+// Use base-2
+condition = [
+ 0
+ 1
+ 1.e1
+ 1.e2
+ 1.e3
+ 1.e13
+ 1.e14
+ 1.e15
+ 1.e16
+ 1.e17
+ 1.e18
+];
+computed = assert_cond2reqdigits ( condition , [] , 2 );
+expected = [
+ 53.
+ 53.
+ 49.678071905112638262381
+ 46.3561438102252765248
+ 43.034215715337914787142
+ 9.814934766464290305521
+ 6.4930066715769214624743
+ 3.1710785766895668302823
+ 0.
+ 0.
+ 0.
+];
+MY_assert_equal ( computed , expected );
+//
+// With offset
+computed = assert_cond2reqdigits ( 1.e2 , [5 4 3 2 1 0 -1 -2 -3 -4 -5]' , 2 );
+expected = [
+ 51.3561438102252765248
+ 50.3561438102252765248
+ 49.3561438102252765248
+ 48.3561438102252765248
+ 47.3561438102252765248
+ 46.3561438102252765248
+ 45.3561438102252765248
+ 44.3561438102252765248
+ 43.3561438102252765248
+ 42.3561438102252765248
+ 41.3561438102252765248
+];
+MY_assert_equal ( computed , expected );
--- /dev/null
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+function flag = MY_assert_equal ( computed , expected )
+ if computed==expected then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then pause,end
+endfunction
+
+//
+condition = [
+ 0
+ 1
+ 1.e1
+ 1.e2
+ 1.e3
+ 1.e13
+ 1.e14
+ 1.e15
+ 1.e16
+ 1.e17
+ 1.e18
+];
+computed = assert_cond2reqdigits ( condition );
+expected = [
+ 15.954589770191001107946
+ 15.954589770191001107946
+ 14.954589770191001107946
+ 13.954589770191001107946
+ 12.954589770191001107946
+ 2.954589770191002884303
+ 1.9545897701910011079462
+ 0.954589770191002884303
+ 0.
+ 0.
+ 0.
+];
+MY_assert_equal ( computed , expected );
+//
+// With offset
+computed = assert_cond2reqdigits ( 1.e2 , [5 4 3 2 1 0 -1 -2 -3 -4 -5]' );
+expected = [
+ 15.954589770191001107946
+ 15.954589770191001107946
+ 15.954589770191001107946
+ 15.954589770191001107946
+ 14.954589770191001107946
+ 13.954589770191001107946
+ 12.954589770191001107946
+ 11.954589770191001107946
+ 10.954589770191001107946
+ 9.9545897701910011079462
+ 8.9545897701910011079462
+];
+MY_assert_equal ( computed , expected );
+//
+computed = assert_cond2reqdigits ( 1.e14 , [0 -1 -2 -3] );
+expected = [1.9545897701910011079462 0.9545897701910011079462 0. 0.];
+MY_assert_equal ( computed , expected );
+//
+computed = assert_cond2reqdigits ( 1.e2 , [0 1 2 3] ) ;
+expected = [13.954589770191001107946 14.954589770191001107946 15.954589770191001107946 15.954589770191001107946];
+MY_assert_equal ( computed , expected );
+//
+// Use base-2
+condition = [
+ 0
+ 1
+ 1.e1
+ 1.e2
+ 1.e3
+ 1.e13
+ 1.e14
+ 1.e15
+ 1.e16
+ 1.e17
+ 1.e18
+];
+computed = assert_cond2reqdigits ( condition , [] , 2 );
+expected = [
+ 53.
+ 53.
+ 49.678071905112638262381
+ 46.3561438102252765248
+ 43.034215715337914787142
+ 9.814934766464290305521
+ 6.4930066715769214624743
+ 3.1710785766895668302823
+ 0.
+ 0.
+ 0.
+];
+MY_assert_equal ( computed , expected );
+//
+// With offset
+computed = assert_cond2reqdigits ( 1.e2 , [5 4 3 2 1 0 -1 -2 -3 -4 -5]' , 2 );
+expected = [
+ 51.3561438102252765248
+ 50.3561438102252765248
+ 49.3561438102252765248
+ 48.3561438102252765248
+ 47.3561438102252765248
+ 46.3561438102252765248
+ 45.3561438102252765248
+ 44.3561438102252765248
+ 43.3561438102252765248
+ 42.3561438102252765248
+ 41.3561438102252765248
+];
+MY_assert_equal ( computed , expected );
+
--- /dev/null
+// Copyright (C) 2009 - 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+function flag = MY_assert_equal ( computed , expected )
+ if computed==expected then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then bugmes();quit;end
+endfunction
+instr = "assert_generror ( ""oups"" )";
+ierr=execstr(instr,"errcatch");
+lerr = lasterror();
+MY_assert_equal ( ierr , 10000 );
+MY_assert_equal ( lerr , "oups" );
+//
+instr = "assert_generror ( ""oups"" , 123456789 )";
+ierr=execstr(instr,"errcatch");
+lerr = lasterror();
+MY_assert_equal ( ierr , 123456789 );
+MY_assert_equal ( lerr , "oups" );
+//
+instr = "assert_generror ( 12 )";
+ierr=execstr(instr,"errcatch");
+lerr = lasterror();
+MY_assert_equal ( ierr , 10000 );
+MY_assert_equal ( lerr , "assert_generror: Wrong type for argument 1: Matrix of strings expected." );
+//
+instr = "assert_generror ( )";
+ierr=execstr(instr,"errcatch");
+lerr = lasterror();
+MY_assert_equal ( ierr , 10000 );
+MY_assert_equal ( lerr , "assert_generror: Wrong number of input arguments: 1 to 2 expected." );
--- /dev/null
+// Copyright (C) 2009 - 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+function flag = MY_assert_equal ( computed , expected )
+ if computed==expected then
+ flag = 1;
+ else
+ flag = 0;
+ end
+ if flag <> 1 then pause,end
+endfunction
+
+instr = "assert_generror ( ""oups"" )";
+ierr=execstr(instr,"errcatch");
+lerr = lasterror();
+MY_assert_equal ( ierr , 10000 );
+MY_assert_equal ( lerr , "oups" );
+//
+instr = "assert_generror ( ""oups"" , 123456789 )";
+ierr=execstr(instr,"errcatch");
+lerr = lasterror();
+MY_assert_equal ( ierr , 123456789 );
+MY_assert_equal ( lerr , "oups" );
+//
+instr = "assert_generror ( 12 )";
+ierr=execstr(instr,"errcatch");
+lerr = lasterror();
+MY_assert_equal ( ierr , 10000 );
+MY_assert_equal ( lerr , "assert_generror: Wrong type for argument 1: Matrix of strings expected." );
+//
+instr = "assert_generror ( )";
+ierr=execstr(instr,"errcatch");
+lerr = lasterror();
+MY_assert_equal ( ierr , 10000 );
+MY_assert_equal ( lerr , "assert_generror: Wrong number of input arguments: 1 to 2 expected." );
+