annotate test/args.tst @ 31214:19bd1953fc1d stable

GitHub-CI: Remove ubuntu-18.04 runners from build matrix. * .github/workflow/make.yaml (ubuntu): GitHub-hosted runners for ubuntu-18.04 are being deprecated. Remove them from build matrix. See also: https://github.com/actions/runner-images/issues/6002
author Markus Mützel <markus.muetzel@gmx.de>
date Tue, 30 Aug 2022 11:16:27 +0200
parents 796f54d4ddbf
children 597f3ee61a48
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 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
3 ## Copyright (C) 2006-2022 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;
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
36
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
37 ## one input with two possible inputs
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
38 %!function f (x, y)
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
39 %! assert (nargin, 1);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
40 %! 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
41 %!endfunction
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
42 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
43 %! f (1);
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
44
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
45 ## no inputs, one of multiple outputs
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
46 %!function [x, y] = f ()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
47 %! assert (nargin, 0);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
48 %! assert (nargout, 1);
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
49 %! x = 2;
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
50 %!endfunction
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
51 %!test
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
52 %! assert (f (), 2);
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
53
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
54 ## one of multiple inputs, one of multiple outputs
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
55 %!function [x, y] = f (a, b)
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
56 %! assert (nargin, 1);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
57 %! assert (nargout, 1);
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
58 %! x = a;
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
59 %!endfunction
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
60 %!test
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
61 %! assert (f (1), 1);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
62
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
63 ########################################
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
64 ## Varargin, varargout
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
65
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
66 ## varargin and varargout with no inputs or outputs
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
67 %!function [varargout] = f (varargin)
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
68 %! assert (nargin, 0);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
69 %! 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
70 %!endfunction
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
71 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
72 %! f;
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 one input
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
75 %!function [varargout] = f (x, varargin)
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
76 %! assert (nargin, 1);
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 (1);
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 output
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
83 %!function [x, varargout] = f (varargin)
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
84 %! assert (nargin, 0);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
85 %! assert (nargout, 1);
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
86 %! x = 2;
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
87 %!endfunction
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
88 %!test
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
89 %! assert (f (), 2);
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
90
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
91 ## varargin and varargout with one input and output
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
92 %!function [varargout] = f (varargin)
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
93 %! assert (nargin, 1);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
94 %! assert (nargout, 1);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
95 %! 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
96 %!endfunction
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
97 %!test
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
98 %! assert (f (1), 1);
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
99
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
100 ## multiple inputs, multiple outputs, but not all of either
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
101 ## 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
102 ## 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
103 ## still has a non-assigned output argument.
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
104 %!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
105 %! assert (nargin, 4);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
106 %! assert (nargout, 2);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
107 %! x = a;
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
108 %! y = b;
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
109 %!endfunction
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
110 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
111 %! [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
112 %! assert ([s t], [1 2]);
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
113
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
114 ## Fully used varargin and varargout
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
115 %!function [varargout] = f (varargin)
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
116 %! assert (nargin, 3);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
117 %! assert (nargout, 4);
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
118 %! varargout{1} = varargin{1};
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
119 %! varargout{2} = varargin{2};
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
120 %! varargout{3} = varargin{3};
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
121 %! 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
122 %!endfunction
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
123 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
124 %! [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
125 %! assert ([s t u v], [1 2 3 4]);
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
126
28193
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
127 ## Wrapper functions
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
128 %!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
129 %! assert (nargin, 0);
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
130 %! assert (nargout, 0);
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
131 %! x = 3;
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
132 %! y = 2;
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
133 %! z = 1;
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
134 %!endfunction
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
135 %!function varargout = wrapper_1 (varargin)
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
136 %! assert (nargout, 0);
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
137 %! [varargout{1:nargout}] = f ();
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
138 %!endfunction
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
139 %!function varargout = wrapper_2 (varargin)
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
140 %! assert (nargout, 0);
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
141 %! varargout = cell (1, nargout);
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
142 %! [varargout{1:nargout}] = f ();
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
143 %!endfunction
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
144 %!function varargout = wrapper_3 (varargin)
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
145 %! assert (nargout, 0);
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
146 %! varargout = cell (1, nargout);
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
147 %! [varargout{:}] = f ();
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
148 %!endfunction
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
149 %!test
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
150 %! wrapper_1 ();
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
151 %! assert (ans, 3);
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
152 %! wrapper_2 ();
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
153 %! assert (ans, 3);
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
154 %! wrapper_3 ();
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
155 %! assert (ans, 3);
56c209ff0a08 improve handling of ans assignment with wrapper functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
156
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
157 ## Test default arguments
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
158 ## numeric
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
159 %!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
160 %! assert (x, 0);
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
161 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
162 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
163 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
164
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
165 ## numeric vector (spaces)
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
166 %!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
167 %! 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
168 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
169 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
170 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
171
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
172 ## numeric vector (range)
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
173 %!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
174 %! 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
175 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
176 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
177 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
178
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
179 ## numeric vector (commas)
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
180 %!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
181 %! 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
182 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
183 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
184 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
185
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
186 ## numeric vector (commas and spaces)
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
187 %!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
188 %! 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
189 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
190 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
191 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
192
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
193 ## numeric matrix
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
194 %!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
195 %! 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
196 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
197 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
198 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
199
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
200 ## empty cell
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
201 %!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
202 %! assert (x, {});
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
203 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
204 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
205 %! f()
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
206
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
207 ## full cell
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
208 %!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
209 %! assert (x, {1});
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
210 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
211 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
212 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
213
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
214 ## many cells
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
215 %!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
216 %! 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
217 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
218 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
219 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
220
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
221 ## struct
28916
ec591c500fa4 maint: Use Octave convention of space after function name in test/.
Rik <rik@octave.org>
parents: 28193
diff changeset
222 %!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
223 %! 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
224 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
225 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
226 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
227
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
228 ## char (double quotes)
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
229 %!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
230 %! assert (x, "a");
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
231 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
232 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
233 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
234
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
235 ## char (single quotes)
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
236 %!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
237 %! assert (x, "a");
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
238 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
239 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
240 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
241
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
242 ## char (string, double quotes)
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
243 %!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
244 %! assert (x, "abc123");
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
245 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
246 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
247 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
248
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
249 ## char (string, double quotes, punctuation)
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
250 %!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
251 %! 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
252 %!endfunction
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
253 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
254 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
255
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
256 ## Function handle (builtin)
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
257 %!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
258 %! 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
259 %! fname = finfo.function;
25803
23483673ba43 Use is_function_handle instead of isa (x, "function_handle").
Rik <rik@octave.org>
parents: 25054
diff changeset
260 %! 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
261 %!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
262 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
263 %! f()
7775
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
264
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
265 ## Function handle (anonymous)
c10d77387d96 test_args: update function argument tests
bill@denney.ws
parents: 7017
diff changeset
266 %!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
267 %! 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
268 %! ftype = finfo.type;
25803
23483673ba43 Use is_function_handle instead of isa (x, "function_handle").
Rik <rik@octave.org>
parents: 25054
diff changeset
269 %! 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
270 %!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
271 %!test
17314
7f27a3cbdb41 Use Octave coding convention of 1 space after '%!' test prefix.
Rik <rik@octave.org>
parents: 16030
diff changeset
272 %! f()