Mercurial > octave
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 |
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 | 7 ## |
8 ## This file is part of Octave. | |
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 | 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 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
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 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
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 | 25 |
7775 | 26 ######################################## |
27 ## No inputs or no outputs | |
5590 | 28 |
7775 | 29 ## no input or output arguments |
5590 | 30 %!function f () |
7775 | 31 %! assert (nargin, 0); |
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 | 34 %!test |
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 | 38 |
7775 | 39 ## one input with two possible inputs |
5590 | 40 %!function f (x, y) |
7775 | 41 %! assert (nargin, 1); |
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 | 44 %!test |
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 | 48 |
7775 | 49 ## no inputs, one of multiple outputs |
5590 | 50 %!function [x, y] = f () |
7775 | 51 %! assert (nargin, 0); |
52 %! assert (nargout, 1); | |
5590 | 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 | 55 %!test |
7775 | 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 | 59 |
7775 | 60 ## one of multiple inputs, one of multiple outputs |
5590 | 61 %!function [x, y] = f (a, b) |
7775 | 62 %! assert (nargin, 1); |
63 %! assert (nargout, 1); | |
5590 | 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 | 66 %!test |
7775 | 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 | 70 |
71 ######################################## | |
72 ## Varargin, varargout | |
5590 | 73 |
7775 | 74 ## varargin and varargout with no inputs or outputs |
5590 | 75 %!function [varargout] = f (varargin) |
7775 | 76 %! assert (nargin, 0); |
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 | 79 %!test |
80 %! f; | |
81 | |
7775 | 82 ## varargin and varargout with one input |
5590 | 83 %!function [varargout] = f (x, varargin) |
7775 | 84 %! assert (nargin, 1); |
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 | 87 %!test |
88 %! f (1); | |
89 | |
7775 | 90 ## varargin and varargout with one output |
5590 | 91 %!function [x, varargout] = f (varargin) |
7775 | 92 %! assert (nargin, 0); |
93 %! assert (nargout, 1); | |
5590 | 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 | 96 %!test |
7775 | 97 %! assert (f (), 2); |
5590 | 98 |
7775 | 99 ## varargin and varargout with one input and output |
5590 | 100 %!function [varargout] = f (varargin) |
7775 | 101 %! assert (nargin, 1); |
102 %! assert (nargout, 1); | |
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 | 105 %!test |
7775 | 106 %! assert (f (1), 1); |
5590 | 107 |
7775 | 108 ## multiple inputs, multiple outputs, but not all of either |
109 ## WARNING: The original test did not assign the outputs, it just | |
110 ## requested them, and I think that is supposed to be an error. It also | |
111 ## still has a non-assigned output argument. | |
5590 | 112 %!function [x, y, z] = f (a, b, c, d, e) |
7775 | 113 %! assert (nargin, 4); |
114 %! assert (nargout, 2); | |
115 %! x = a; | |
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 | 118 %!test |
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 | 121 |
7775 | 122 ## Fully used varargin and varargout |
5590 | 123 %!function [varargout] = f (varargin) |
7775 | 124 %! assert (nargin, 3); |
125 %! assert (nargout, 4); | |
126 %! varargout{1} = varargin{1}; | |
127 %! varargout{2} = varargin{2}; | |
128 %! varargout{3} = varargin{3}; | |
5590 | 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 | 131 %!test |
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 | 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 | 165 ## Test default arguments |
166 ## numeric | |
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 | 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 | 172 |
173 ## numeric vector (spaces) | |
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 | 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 | 179 |
180 ## numeric vector (range) | |
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 | 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 | 186 |
187 ## numeric vector (commas) | |
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 | 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 | 193 |
194 ## numeric vector (commas and spaces) | |
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 | 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 | 200 |
201 ## numeric matrix | |
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 | 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 | 207 |
208 ## empty cell | |
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 | 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 | 214 |
7775 | 215 ## full cell |
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 | 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 | 221 |
222 ## many cells | |
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 | 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 | 228 |
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 | 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 | 235 |
236 ## char (double quotes) | |
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 | 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 | 242 |
243 ## char (single quotes) | |
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 | 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 | 249 |
250 ## char (string, double quotes) | |
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 | 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 | 256 |
257 ## char (string, double quotes, punctuation) | |
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 | 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 | 263 |
264 ## Function handle (builtin) | |
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 | 272 |
273 ## Function handle (anonymous) | |
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() |