1
1
// =============================================================================
2
2
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3
3
// Copyright (C) 2008 - INRIA - Pierre MARECHAL <pierre.marechal@inria.fr>
4
// Copyright (C) 2012 - Scilab Enterprises - Cedric Delamarre
5
6
// This file is distributed under the same license as the Scilab package.
6
7
// =============================================================================
7
8
// <-- CLI SHELL MODE -->
8
9
// unit tests for abs() function (absolute value, magnitude)
9
10
// =============================================================================
10
if execstr("abs()" ,"errcatch") == 0 then bugmes();quit;end
11
if execstr("abs(1,2)","errcatch") == 0 then bugmes();quit;end
12
if abs(10) <> 10 then bugmes();quit;end
13
if abs(-4.3) <> 4.3 then bugmes();quit;end
14
if abs(6+8*%i) <> 10 then bugmes();quit;end
15
if abs(6-8*%i) <> 10 then bugmes();quit;end
16
if or(abs([ 7.6 , 8*%i ; 6+8*%i 6-8*%i ]) <> [7.6 , 8 ; 10 , 10 ]) then bugmes();quit;end
17
if or(abs([ 7.6 8*%i 6+8*%i 6-8*%i ]) <> [7.6 8 10 10 ]) then bugmes();quit;end
18
if or(abs([ 7.6 ; 8*%i ; 6+8*%i ; 6-8*%i ]) <> [7.6 ; 8 ; 10 ; 10 ]) then bugmes();quit;end
19
if ~isnan(abs(%nan)) then bugmes();quit;end
20
if ~isnan(abs(-%nan)) then bugmes();quit;end
21
if abs(%inf) <> %inf then bugmes();quit;end
22
if abs(-%inf) <> %inf then bugmes();quit;end
11
assert_checkfalse(execstr("abs()", "errcatch") == 0);
12
assert_checkfalse(execstr("abs(1,2)", "errcatch") == 0);
13
assert_checkequal(abs(10) ,10);
14
assert_checkequal(abs(-4.3) ,4.3);
15
assert_checkequal(abs(6+8*%i) ,10);
16
assert_checkequal(abs(6-8*%i) ,10);
17
assert_checkequal(abs([ 7.6 , 8*%i ; 6+8*%i 6-8*%i ]), [7.6 , 8 ; 10 , 10 ]);
18
assert_checkequal(abs([ 7.6 8*%i 6+8*%i 6-8*%i ]), [7.6 8 10 10 ]);
19
assert_checkequal(abs([ 7.6 ; 8*%i ; 6+8*%i ; 6-8*%i ]), [7.6 ; 8 ; 10 ; 10 ]);
20
assert_checktrue(isnan(abs(%nan)));
21
assert_checktrue(isnan(abs(-%nan)));
22
assert_checkequal(abs(%inf), %inf);
23
assert_checkequal(abs(-%inf), %inf);