Assert

Assert Commit Details

Date:2011-04-13 14:17:41 (7 years 2 months ago)
Author:Michael Baudin
Commit:124
Parents: 123
Message:archives are not necessary anymore.
Changes:
D/archive

File differences

archive/%ASSERT_string.sci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (C) 2008-2009 - INRIA - 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 str = %ASSERT_string ( this )
//
// Convert the current assert object into a string
//
str = []
k = 1
str(k) = sprintf("Assert Object:\n")
k = k + 1
str(k) = sprintf("======================")
k = k + 1
str(k) = sprintf("relativeprecision : %s\n",string(this.relativeprecision));
k = k + 1
str(k) = sprintf("absoluteprecision : %s\n",string(this.absoluteprecision));
k = k + 1
str(k) = sprintf("errorfunction : <function>\n");
k = k + 1
str(k) = sprintf("compnorm : %s\n",string(this.compnorm));
k = k + 1
str(k) = sprintf("verbose : %s\n",string(this.verbose));
k = k + 1
str(k) = sprintf("erroronfail : %s\n",string(this.erroronfail));
k = k + 1
str(k) = sprintf("======================")
k = k + 1
str(k) = sprintf("Current State:\n");
k = k + 1
str(k) = sprintf("failed : %s\n",string(this.failed));
k = k + 1
str(k) = sprintf("passed : %s\n",string(this.passed));
k = k + 1
str(k) = sprintf("total : %s\n",string(this.total));
endfunction
//
// _strvec --
// Returns a string for the given vector.
//
function str = _strvec ( x )
str = strcat(string(x)," ")
endfunction
function s = _tostring ( x )
if ( x==[] ) then
s = "[]"
else
n = size ( x , "*" )
if ( n == 1 ) then
s = string(x)
else
s = "["+strcat(string(x)," ")+"]"
end
end
endfunction
archive/assert_errorfunction.tst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2008 - INRIA - 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 = MY_assert_equal ( computed , expected )
if computed==expected then
flag = 1;
else
flag = 0;
end
if flag <> 1 then pause,end
endfunction
global mydata
mydata = 0;
function myerrorfunction ( msg )
global mydata
mydata = mydata + 1
mprintf ( "%s", msg )
endfunction
// Simple sequence
assert_startup ();
assert_configure ( "-errorfunction" , myerrorfunction );
assert_equal ( %T , %T );
assert_equal ( %F , %T );
assert_close ( 1.0 , 1.0 );
assert_close ( 1.0 , 2.0 );
MY_assert_equal ( mydata , 2 );
archive/assert_print.sci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright (C) 2008-2009 - INRIA - 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_print ( )
// Print the content of the assert structure.
//
// Calling Sequence
// assert_print ( )
//
// Parameters
//
// Description
//
// Authors
// Michael Baudin, 2010
global %assert
mprintf ( "ASSERT\n" )
mprintf ( "Verbose: %e\n", %assert.verbose)
mprintf ( "Relative precision: %e\n", %assert.relativeprecision)
mprintf ( "Absolute precision: %e\n", %assert.absoluteprecision)
mprintf ( "Total: %d\n", %assert.total)
mprintf ( "Failed: %d\n", %assert.failed)
mprintf ( "Passed: %d\n", %assert.passed)
endfunction
archive/assert_startup.dia.ref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2008 - INRIA - 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 = MY_assert_equal ( computed , expected )
if computed==expected then
flag = 1;
else
flag = 0;
end
if flag <> 1 then bugmes();quit;end
endfunction
// Simple sequence
assert_startup ();
assert_configure ( "-erroronfail" , %f );
MY_assert_equal ( assert_get ("-total") , 0 );
MY_assert_equal ( assert_get ("-passed") , 0 );
MY_assert_equal ( assert_get ("-failed") , 0 );
MY_assert_equal ( assert_get ("-all") , [0 0 0] );
archive/assert_startup.tst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2008 - INRIA - 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 = MY_assert_equal ( computed , expected )
if computed==expected then
flag = 1;
else
flag = 0;
end
if flag <> 1 then pause,end
endfunction
// Simple sequence
assert_startup ();
assert_configure ( "-erroronfail" , %f );
MY_assert_equal ( assert_get ("-total") , 0 );
MY_assert_equal ( assert_get ("-passed") , 0 );
MY_assert_equal ( assert_get ("-failed") , 0 );
archive/assert_get.sci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright (C) 2008-2009 - INRIA - 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 value = assert_get (key)
//
// Retrieve a field of the assert module.
//
// Calling sequence
// value = assert_get (key)
//
// Description
// Quiery a non-configurable field.
//
//
// Authors
// Michael Baudin, 2010
global %assert
select key
case "-total" then
value = %assert.total
case "-failed" then
value = %assert.failed
case "-passed" then
value = %assert.passed
else
errmsg = sprintf( gettext ( "%s: Unknown key %s" ) , "assert_cget" , key )
error(errmsg)
end
endfunction
archive/assert_configure.sci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (C) 2008-2009 - INRIA - 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_configure ( key , value )
// Configure the assert module.
//
// Calling Sequence
// assert_configure ( key , value )
//
// Parameters
// key: a string, the option to quiery.
// value: the value of the option.
//
// Description
//
//
// Authors
// Michael Baudin, 2010
global %assert
select key
case "-verbose" then
%assert.verbose = value
case "-relativeprecision" then
if ( value < 0. ) then
errmsg = sprintf( gettext ( "%s: Relative precision is negative: %e" ) ,"assert_configure" , value )
error(errmsg)
end
%assert.relativeprecision = value
case "-absoluteprecision" then
if ( value < 0. ) then
errmsg = sprintf( gettext ( "%s: Absolute precision is negative: %e") ,"assert_configure" , value )
error(errmsg)
end
%assert.absoluteprecision = value
case "-errorfunction" then
%assert.errorfunction = value
case "-compnorm" then
// TODO : check for comparison norm consistency
%assert.compnorm = value
case "-erroronfail" then
%assert.erroronfail = value
else
errmsg = sprintf( gettext ( "%s: Unknown key %s" ) , "assert_configure" , key )
error(errmsg)
end
endfunction
archive/assert_cget.sci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (C) 2008-2009 - INRIA - 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 value = assert_cget (key)
// Quiery the value of configurable options.
//
// Calling Sequence
// value = assert_cget (key)
//
// Parameters
// key: a string, the option to quiery.
// value: the value of the option.
//
// Description
// The list of available keys is key = "-verbose", "-relativeprecision", "-absoluteprecision",
// "-errorfunction", "-compnorm", "-erroronfail"
//
// Authors
// Michael Baudin, 2010
global %assert
select key
case "-verbose" then
value = %assert.verbose
case "-relativeprecision" then
value = %assert.relativeprecision
case "-absoluteprecision" then
value = %assert.absoluteprecision
case "-errorfunction" then
value = %assert.errorfunction
case "-compnorm" then
value = %assert.compnorm
case "-erroronfail" then
value = %assert.erroronfail
else
errmsg = sprintf( gettext ( "%s: Unknown key %s" ) , "assert_cget" , key )
error(errmsg)
end
endfunction
archive/assert_startup.sci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (C) 2008-2009 - INRIA - 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_startup ( )
// Startup the assert library.
//
// Calling Sequence
// assert_startup ( )
//
// Description
// Initialize the global variable %assert which is used in this module.
// TODO : avoid global parameter for parallel execution of unit tests
//
// Authors
// Michael Baudin, 2010
global %assert
%assert = tlist(["ASSERT"
"relativeprecision"
"absoluteprecision"
"errorfunction"
"compnorm"
"failed"
"passed"
"total"
"verbose"
"erroronfail"
])
%assert.relativeprecision = %eps
%assert.absoluteprecision = 0.
%assert.errorfunction = []
%assert.compnorm = 2
%assert.erroronfail = %t
%assert.verbose = 0
// Non-configurable fields
%assert.failed = 0
%assert.passed = 0
%assert.total = 0
endfunction
archive/%ASSERT_p.sci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Copyright (C) 2008-2009 - INRIA - 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_p ( this )
//
// Print the current assert object
//
str = string ( this )
srows = size(str,"r")
for i = 1 : srows
mprintf("%s\n",str(i))
end
endfunction
archive/assert_print.dia.ref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2008 - INRIA - 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 = MY_assert_equal ( computed , expected )
if computed==expected then
flag = 1;
else
flag = 0;
end
if flag <> 1 then bugmes();quit;end
endfunction
// Simple sequence
assert_startup ();
assert_configure ( "-erroronfail" , %f );
assert_print ( );
ASSERT
Verbose: 0.000000e+000
Relative precision: 2.220446e-016
Absolute precision: 0.000000e+000
Total: 0
Failed: 0
Passed: 0
assert_equal ( %T , %T );
assert_print ( );
ASSERT
Verbose: 0.000000e+000
Relative precision: 2.220446e-016
Absolute precision: 0.000000e+000
Total: 1
Failed: 0
Passed: 1
assert_equal ( %F , %T );
assert_print ( );
ASSERT
Verbose: 0.000000e+000
Relative precision: 2.220446e-016
Absolute precision: 0.000000e+000
Total: 2
Failed: 1
Passed: 1
archive/assert_print.tst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2008 - INRIA - 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 = MY_assert_equal ( computed , expected )
if computed==expected then
flag = 1;
else
flag = 0;
end
if flag <> 1 then pause,end
endfunction
// Simple sequence
assert_startup ();
assert_configure ( "-erroronfail" , %f );
assert_print ( );
assert_equal ( %T , %T );
assert_print ( );
assert_equal ( %F , %T );
assert_print ( );
archive/assert_error.sci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright (C) 2008-2009 - INRIA - 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_error ( msg )
// Generates an error with given message
//
// Calling Sequence
// assert_error ( msg )
//
// Parameters
// msg: the message
//
// Authors
// Michael Baudin, 2010
global %assert
if ( %assert.errorfunction == [] ) then
error ( sprintf ( gettext ( "%s: %s"), "assert_error" , msg ) )
else
%assert.errorfunction ( msg )
end
endfunction
archive/assert_errorfunction.dia.ref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2008 - INRIA - 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 = MY_assert_equal ( computed , expected )
if computed==expected then
flag = 1;
else
flag = 0;
end
if flag <> 1 then bugmes();quit;end
endfunction
global mydata
mydata = 0;
function myerrorfunction ( msg )
global mydata
mydata = mydata + 1
mprintf ( "%s", msg )
endfunction
// Simple sequence
assert_startup ();
assert_configure ( "-errorfunction" , myerrorfunction );
assert_equal ( %T , %T );
assert_equal ( %F , %T );
Failed assert equalassert_close ( 1.0 , 1.0 );
assert_close ( 1.0 , 2.0 );
Failed assert closeMY_assert_equal ( mydata , 2 );

Archive Download the corresponding diff file

Revision: 124