annotate test/args.tst @ 32654:9f0a15acdaea

test: Add tests for interpreter of functions with too many inputs or outputs. * args.tst: Add %!error BIST tests to verify interpreter produces error when functions are called with too many inputs or outputs.
author Rik <rik@octave.org>
date Tue, 26 Dec 2023 13:19:34 -0800
parents 2e484f9f1f18
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
32632
2e484f9f1f18 maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
3 ## Copyright (C) 2006-2024 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5590
diff changeset
7 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5590
diff changeset
8 ## This file is part of Octave.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5590
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5590
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5590
diff changeset
14 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5590
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5590
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5590
diff changeset
19 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5590
diff changeset
20 ## You should have received a copy of the GNU General Public License
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5590
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5590
diff changeset
25
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
26 ########################################
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
27 ## No inputs or no outputs
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
28
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
29 ## no input or output arguments
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
30 %!function f ()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
31 %! assert (nargin, 0);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
32 %! assert (nargout, 0);
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
33 %!endfunction
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
34 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
35 %! f;
32654
9f0a15acdaea test: Add tests for interpreter of functions with too many inputs or outputs.
Rik <rik@octave.org>
parents: 32632
diff changeset
36 %!error <function called with too many inputs> f (1)
9f0a15acdaea test: Add tests for interpreter of functions with too many inputs or outputs.
Rik <rik@octave.org>
parents: 32632
diff changeset
37 %!error <function called with too many outputs> y = f ()
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
38
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
39 ## one input with two possible inputs
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
40 %!function f (x, y)
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
41 %! assert (nargin, 1);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
42 %! assert (nargout, 0);
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
43 %!endfunction
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
44 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
45 %! f (1);
32654
9f0a15acdaea test: Add tests for interpreter of functions with too many inputs or outputs.
Rik <rik@octave.org>
parents: 32632
diff changeset
46 %!error <function called with too many inputs> f (1, 2, 3)
9f0a15acdaea test: Add tests for interpreter of functions with too many inputs or outputs.
Rik <rik@octave.org>
parents: 32632
diff changeset
47 %!error <function called with too many outputs> y = f ()
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
48
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
49 ## no inputs, one of multiple outputs
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
50 %!function [x, y] = f ()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
51 %! assert (nargin, 0);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
52 %! assert (nargout, 1);
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
53 %! x = 2;
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
54 %!endfunction
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
55 %!test
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
56 %! assert (f (), 2);
32654
9f0a15acdaea test: Add tests for interpreter of functions with too many inputs or outputs.
Rik <rik@octave.org>
parents: 32632
diff changeset
57 %!error <function called with too many inputs> f (1)
9f0a15acdaea test: Add tests for interpreter of functions with too many inputs or outputs.
Rik <rik@octave.org>
parents: 32632
diff changeset
58 %!error <function called with too many outputs> [x, y, z] = f ()
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
59
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
60 ## one of multiple inputs, one of multiple outputs
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
61 %!function [x, y] = f (a, b)
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
62 %! assert (nargin, 1);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
63 %! assert (nargout, 1);
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
64 %! x = a;
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
65 %!endfunction
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
66 %!test
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
67 %! assert (f (1), 1);
32654
9f0a15acdaea test: Add tests for interpreter of functions with too many inputs or outputs.
Rik <rik@octave.org>
parents: 32632
diff changeset
68 %!error <function called with too many inputs> f (1, 2, 3)
9f0a15acdaea test: Add tests for interpreter of functions with too many inputs or outputs.
Rik <rik@octave.org>
parents: 32632
diff changeset
69 %!error <function called with too many outputs> [x, y, z] = f ()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
70
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
71 ########################################
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
72 ## Varargin, varargout
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
73
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
74 ## varargin and varargout with no inputs or outputs
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
75 %!function [varargout] = f (varargin)
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
76 %! assert (nargin, 0);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
77 %! assert (nargout, 0);
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
78 %!endfunction
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
79 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
80 %! f;
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
81
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
82 ## varargin and varargout with one input
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
83 %!function [varargout] = f (x, varargin)
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
84 %! assert (nargin, 1);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
85 %! assert (nargout, 0);
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
86 %!endfunction
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
87 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
88 %! f (1);
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
89
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
90 ## varargin and varargout with one output
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
91 %!function [x, varargout] = f (varargin)
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
92 %! assert (nargin, 0);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
93 %! assert (nargout, 1);
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
94 %! x = 2;
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
95 %!endfunction
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
96 %!test
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
97 %! assert (f (), 2);
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
98
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
99 ## varargin and varargout with one input and output
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
100 %!function [varargout] = f (varargin)
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
101 %! assert (nargin, 1);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
102 %! assert (nargout, 1);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
103 %! varargout{1} = varargin{1};
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
104 %!endfunction
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
105 %!test
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
106 %! assert (f (1), 1);
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
107
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
108 ## multiple inputs, multiple outputs, but not all of either
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
109 ## WARNING: The original test did not assign the outputs, it just
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
110 ## requested them, and I think that is supposed to be an error. It also
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
111 ## still has a non-assigned output argument.
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
112 %!function [x, y, z] = f (a, b, c, d, e)
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
113 %! assert (nargin, 4);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
114 %! assert (nargout, 2);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
115 %! x = a;
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
116 %! y = b;
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
117 %!endfunction
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
118 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
119 %! [s, t] = f (1, 2, 3, 4);
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
120 %! assert ([s t], [1 2]);
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
121
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
122 ## Fully used varargin and varargout
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
123 %!function [varargout] = f (varargin)
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
124 %! assert (nargin, 3);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
125 %! assert (nargout, 4);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
126 %! varargout{1} = varargin{1};
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
127 %! varargout{2} = varargin{2};
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
128 %! varargout{3} = varargin{3};
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
129 %! varargout{4} = 4;
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
130 %!endfunction
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
131 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
132 %! [s, t, u, v] = f (1, 2, 3);
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
133 %! assert ([s t u v], [1 2 3 4]);
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
134
28193
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
135 ## Wrapper functions
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
136 %!function [x, y, z] = f (varargin)
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
137 %! assert (nargin, 0);
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
138 %! assert (nargout, 0);
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
139 %! x = 3;
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
140 %! y = 2;
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
141 %! z = 1;
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
142 %!endfunction
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
143 %!function varargout = wrapper_1 (varargin)
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
144 %! assert (nargout, 0);
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
145 %! [varargout{1:nargout}] = f ();
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
146 %!endfunction
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
147 %!function varargout = wrapper_2 (varargin)
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
148 %! assert (nargout, 0);
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
149 %! varargout = cell (1, nargout);
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
150 %! [varargout{1:nargout}] = f ();
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
151 %!endfunction
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
152 %!function varargout = wrapper_3 (varargin)
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
153 %! assert (nargout, 0);
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
154 %! varargout = cell (1, nargout);
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
155 %! [varargout{:}] = f ();
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
156 %!endfunction
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
157 %!test
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
158 %! wrapper_1 ();
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
159 %! assert (ans, 3);
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
160 %! wrapper_2 ();
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
161 %! assert (ans, 3);
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
162 %! wrapper_3 ();
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
163 %! assert (ans, 3);
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
164
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
165 ## Test default arguments
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
166 ## numeric
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
167 %!function f (x = 0)
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
168 %! assert (x, 0);
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
169 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
170 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
171 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
172
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
173 ## numeric vector (spaces)
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
174 %!function f (x = [0 1 2])
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
175 %! assert (x, [0 1 2]);
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
176 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
177 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
178 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
179
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
180 ## numeric vector (range)
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
181 %!function f (x = 1:3)
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
182 %! assert (x, 1:3);
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
183 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
184 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
185 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
186
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
187 ## numeric vector (commas)
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
188 %!function f (x = [0,1,2])
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
189 %! assert (x, [0 1 2]);
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
190 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
191 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
192 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
193
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
194 ## numeric vector (commas and spaces)
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
195 %!function f (x = [0, 1, 2])
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
196 %! assert (x, [0 1 2]);
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
197 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
198 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
199 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
200
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
201 ## numeric matrix
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
202 %!function f (x = [0, 1, 2;3, 4, 5])
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
203 %! assert (x, [0 1 2;3 4 5]);
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
204 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
205 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
206 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
207
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
208 ## empty cell
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
209 %!function f (x = {})
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
210 %! assert (x, {});
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
211 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
212 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
213 %! f()
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
214
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
215 ## full cell
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
216 %!function f (x = {1})
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
217 %! assert (x, {1});
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
218 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
219 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
220 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
221
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
222 ## many cells
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
223 %!function f (x = {1 'a' "b" 2.0 struct("a", 3)})
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
224 %! assert (x, {1 'a' "b" 2.0 struct("a", 3)});
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
225 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
226 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
227 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
228
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
229 ## struct
28916
ec591c500fa4 maint: Use Octave convention of space after function name in test/.
Rik <rik@octave.org>
parents: 28193
diff changeset
230 %!function f (x = struct ("a", 3))
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
231 %! assert (x, struct ("a", 3));
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
232 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
233 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
234 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
235
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
236 ## char (double quotes)
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
237 %!function f (x = "a")
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
238 %! assert (x, "a");
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
239 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
240 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
241 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
242
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
243 ## char (single quotes)
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
244 %!function f (x = 'a')
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
245 %! assert (x, "a");
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
246 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
247 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
248 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
249
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
250 ## char (string, double quotes)
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
251 %!function f (x = "abc123")
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
252 %! assert (x, "abc123");
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
253 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
254 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
255 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
256
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
257 ## char (string, double quotes, punctuation)
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
258 %!function f (x = "abc123`1234567890-=~!@#$%^&*()_+[]{}|;':\",./<>?\\")
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
259 %! assert (x, "abc123`1234567890-=~!@#$%^&*()_+[]{}|;':\",./<>?\\");
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
260 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
261 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
262 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
263
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
264 ## Function handle (builtin)
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
265 %!function f (x = @sin)
8805
065a05eb148a test_args.m: don't use assert to test for function handles
John W. Eaton <jwe@octave.org>
parents: 7775
diff changeset
266 %! finfo = functions (x);
065a05eb148a test_args.m: don't use assert to test for function handles
John W. Eaton <jwe@octave.org>
parents: 7775
diff changeset
267 %! fname = finfo.function;
25803
23483673ba43 Use is_function_handle instead of isa (x, "function_handle").
Rik <rik@octave.org>
parents: 25054
diff changeset
268 %! assert (is_function_handle (x) && strcmp (fname, "sin"));
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
269 %!endfunction
8805
065a05eb148a test_args.m: don't use assert to test for function handles
John W. Eaton <jwe@octave.org>
parents: 7775
diff changeset
270 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
271 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
272
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
273 ## Function handle (anonymous)
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
274 %!function f (x = @(x) x.^2)
8805
065a05eb148a test_args.m: don't use assert to test for function handles
John W. Eaton <jwe@octave.org>
parents: 7775
diff changeset
275 %! finfo = functions (x);
065a05eb148a test_args.m: don't use assert to test for function handles
John W. Eaton <jwe@octave.org>
parents: 7775
diff changeset
276 %! ftype = finfo.type;
25803
23483673ba43 Use is_function_handle instead of isa (x, "function_handle").
Rik <rik@octave.org>
parents: 25054
diff changeset
277 %! assert (is_function_handle (x) && strcmp (ftype, "anonymous"));
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
278 %!endfunction
8805
065a05eb148a test_args.m: don't use assert to test for function handles
John W. Eaton <jwe@octave.org>
parents: 7775
diff changeset
279 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
280 %! f()