b724c91d01cd9a71fc8165bcadbf472191989009
[scilab.git] / scilab / modules / functions / tests / unit_tests / deff.tst
1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2009 - DIGITEO - Allan CORNET
4 //
5 //  This file is distributed under the same license as the Scilab package.
6 // =============================================================================
7
8 // <-- CLI SHELL MODE -->
9
10 deff("[x] = myplus(y,z)","x=y+z");
11 assert_checktrue(isdef("myplus"));
12 assert_checkequal(myplus(3,2), 5);
13 clear myplus;
14 assert_checkfalse(isdef("myplus"));
15
16 deff("[x] = mymacro(y,z)",["a=3*y+1"; "x=a*z+y"]);
17 assert_checktrue(isdef("mymacro"));
18 assert_checkequal(mymacro(5,2), 37);
19 clear mymacro;
20 assert_checkfalse(isdef("mymacro"));
21
22 deff("[a,b,c] = mymacro(varargin)",["a = varargin(1); b = varargin(2) * a; c = varargin(3) * b"]);
23 assert_checktrue(isdef("mymacro"));
24 [a,b,c] = mymacro(3,4,5);
25 assert_checkequal(a, 3);
26 assert_checkequal(b, 12);
27 assert_checkequal(c, 60);
28 clear mymacro;
29 assert_checkfalse(isdef("mymacro"));
30
31 deff("[varargout] = mymacro(varargin)",["for i = 1 : size(varargin)"; "    varargout(i) = varargin(i) * 2;";"end"]);
32 assert_checktrue(isdef("mymacro"));
33 [a,b,c] = mymacro(3,4,5);
34 assert_checkequal(a, 6);
35 assert_checkequal(b, 8);
36 assert_checkequal(c, 10);
37 clear mymacro;
38 assert_checkfalse(isdef("mymacro"));
39
40 deff("[varargout] = mymacro(varargin)", ["deff(""varargout = mymacro2(varargin)"", [""for i = 1 : size(varargin)""; ""    varargout(i) = varargin(i) * 2;"";""end""]);";"[a,b,c] = mymacro2(varargin(:));";"varargout(1) = a*2;";"varargout(2) = b*2;";"varargout(3) = c*2;"]);
41 assert_checktrue(isdef("mymacro"));
42 assert_checkfalse(isdef("mymacro2"));
43 [a,b,c] = mymacro(3,4,5);
44 assert_checkequal(a, 12);
45 assert_checkequal(b, 16);
46 assert_checkequal(c, 20);
47 assert_checkfalse(isdef("mymacro2"));
48 clear mymacro;
49 assert_checkfalse(isdef("mymacro"));
50