b760f5d5dd8e81cc74b72a4ce5f965adeb93f29a
[scilab.git] / scilab / modules / functions / tests / unit_tests / deff.dia.ref
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 // <-- CLI SHELL MODE -->
8 deff("[x] = myplus(y,z)","x=y+z");
9 assert_checktrue(isdef("myplus"));
10 assert_checkequal(myplus(3,2), 5);
11 clear myplus;
12 assert_checkfalse(isdef("myplus"));
13 deff("[x] = mymacro(y,z)",["a=3*y+1"; "x=a*z+y"]);
14 assert_checktrue(isdef("mymacro"));
15 assert_checkequal(mymacro(5,2), 37);
16 clear mymacro;
17 assert_checkfalse(isdef("mymacro"));
18 deff("[a,b,c] = mymacro(varargin)",["a = varargin(1); b = varargin(2) * a; c = varargin(3) * b"]);
19 assert_checktrue(isdef("mymacro"));
20 [a,b,c] = mymacro(3,4,5);
21 assert_checkequal(a, 3);
22 assert_checkequal(b, 12);
23 assert_checkequal(c, 60);
24 clear mymacro;
25 assert_checkfalse(isdef("mymacro"));
26 deff("[varargout] = mymacro(varargin)",["for i = 1 : size(varargin)"; "    varargout(i) = varargin(i) * 2;";"end"]);
27 assert_checktrue(isdef("mymacro"));
28 [a,b,c] = mymacro(3,4,5);
29 assert_checkequal(a, 6);
30 assert_checkequal(b, 8);
31 assert_checkequal(c, 10);
32 clear mymacro;
33 assert_checkfalse(isdef("mymacro"));
34 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;"]);
35 assert_checktrue(isdef("mymacro"));
36 assert_checkfalse(isdef("mymacro2"));
37 [a,b,c] = mymacro(3,4,5);
38 assert_checkequal(a, 12);
39 assert_checkequal(b, 16);
40 assert_checkequal(c, 20);
41 assert_checkfalse(isdef("mymacro2"));
42 clear mymacro;
43 assert_checkfalse(isdef("mymacro"));