1 // Copyright (C) 2008 - INRIA - Michael Baudin
2 // Copyright (C) 2010 - DIGITEO - Michael Baudin
4 // This file must be used under the terms of the CeCILL.
5 // This source file is licensed as described in the file COPYING, which
6 // you should have received as part of this distribution. The terms
7 // are also available at
8 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
9 // <-- JVM NOT MANDATORY -->
10 // <-- ENGLISH IMPOSED -->
11 function flag = MY_assert_equal ( computed , expected )
12 if computed==expected then
17 if flag <> 1 then bugmes();quit;end
21 dmax = -log10(2^(-53));
23 computed = assert_computedigits ( 1 , 1 );
24 MY_assert_equal ( computed , dmax );
26 computed = assert_computedigits ( 0 , 0 );
27 MY_assert_equal ( computed , dmax );
29 computed = assert_computedigits ( 1 , 0 );
30 MY_assert_equal ( computed , 0 );
32 computed = assert_computedigits ( 0 , 1 );
33 MY_assert_equal ( computed , 0 );
35 computed = assert_computedigits ( 3.1415926 , %pi );
36 MY_assert_equal ( computed , 7.467037797136421240 );
38 computed = assert_computedigits ( 3.1415926 , %pi , 2 );
39 MY_assert_equal ( computed , 24.804962643893318841037 );
41 computed = assert_computedigits ( [0 0 1 1] , [0 1 0 1] );
42 MY_assert_equal ( computed , [dmax 0 0 dmax] );
44 computed = assert_computedigits(ones(3,2),ones(3,2));
45 MY_assert_equal ( computed , dmax * ones(3,2) );
47 computed = assert_computedigits([%nan %nan %nan %nan],[%nan %inf -%inf 0]);
48 MY_assert_equal ( computed , [dmax 0 0 0] );
50 computed = assert_computedigits([%inf %inf %inf %inf],[%nan %inf -%inf 0]);
51 MY_assert_equal ( computed , [0 dmax 0 0] );
53 computed = assert_computedigits([-%inf -%inf -%inf -%inf],[%nan %inf -%inf 0]);
54 MY_assert_equal ( computed , [0 0 dmax 0] );
56 computed = assert_computedigits([0 0 0 0],[%nan %inf -%inf 0]);
57 MY_assert_equal ( computed , [0 0 0 dmax] );
59 computed = assert_computedigits(1.224646799D-16,8.462643383D-18);
60 MY_assert_equal ( computed , 0 );
62 computed = assert_computedigits ( 1.2345 + %i*6.7891 , 1.23456789 + %i*6.789123456 );
63 MY_assert_equal ( computed , 3.9586791728311578886235 );
65 // The sign bit of the number of digits may be wrong because
66 // ieee(2); z=max(-0,0); 1/z is -%inf
69 computed = assert_computedigits ( 1.e-305 , 0 );
70 MY_assert_equal ( 1/computed , %inf );
72 computed = assert_computedigits ( 0 , 1.e-305 );
73 MY_assert_equal ( 1/computed , %inf );
76 // An empirically found test case
78 3.982729777831130693D-59
79 2.584939414228211484D-26
80 4.391531370352049090D+43
81 1.725436586898508346D+68
84 3.982729777831130693D-59
85 2.584939414228211484D-26
86 4.391531370352048595D+43
87 1.725436586898508107D+68
89 c = assert_computedigits ( a , b , 2 );
96 assert_checkalmostequal ( c , e , 1.e-7 );
98 // Check that the vectorization was correct, i.e. no specific
99 // case in the processing of the data is forgotten.
101 function pI = permInverse(p)
102 // Given the permutation p, compute the
103 // inverse permutation pI.
136 mprintf("Test #%d\n",k);
137 p1 = grand(1,"prm",(1:N)');
138 p2 = grand(1,"prm",(1:N)');
141 d1 = assert_computedigits(computed,expected);
142 // Permute both computed and expected with the same permutation p3:
143 // d must not change.
144 p3 = grand(1,"prm",(1:N)');
145 computedP = computed(p3);
146 expectedP = expected(p3);
147 d2 = assert_computedigits(computedP,expectedP);
148 // Apply inverse permutation on d2.
149 pI = permInverse(p3);
151 assert_checkequal(d1,d2);