9245
|
1 ## Copyright (C) 2006, 2007, 2009 John W. Eaton |
7016
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
|
18 |
5590
|
19 %% test/octave.test/for/for-1.m |
|
20 %!test |
|
21 %! for i = 1 |
|
22 %! printf_assert ("%d", i); |
|
23 %! end |
|
24 %! printf_assert ("\n"); |
|
25 %! assert(prog_output_assert("1")); |
|
26 |
|
27 %% test/octave.test/for/for-2.m |
|
28 %!test |
|
29 %! for i = 1:4 |
|
30 %! printf_assert ("%d", i); |
|
31 %! endfor |
|
32 %! printf_assert ("\n"); |
|
33 %! assert(prog_output_assert("1234")); |
|
34 |
|
35 %% test/octave.test/for/for-3.m |
|
36 %!test |
|
37 %! for i = [1,2,3,4] |
|
38 %! printf_assert ("%d", i); |
|
39 %! endfor |
|
40 %! printf_assert ("\n"); |
|
41 %! assert(prog_output_assert("1234")); |
|
42 |
|
43 %% test/octave.test/for/for-4.m |
|
44 %!test |
|
45 %! for i = [1,2;3,4] |
|
46 %! printf_assert ("%d", i(1,1)); |
|
47 %! printf_assert ("%d", i(2,1)); |
|
48 %! endfor |
|
49 %! printf_assert ("\n"); |
|
50 %! assert(prog_output_assert("1324")); |
|
51 |
|
52 %% test/octave.test/for/for-5.m |
|
53 %!test |
|
54 %! for i = I |
|
55 %! printf_assert ("%d", imag (i)); |
|
56 %! endfor |
|
57 %! printf_assert ("\n"); |
|
58 %! assert(prog_output_assert("1")); |
|
59 |
|
60 %% test/octave.test/for/for-6.m |
|
61 %!test |
|
62 %! for i = [1,2,3,4]*I |
|
63 %! printf_assert ("%d", imag (i)); |
|
64 %! endfor |
|
65 %! printf_assert ("\n"); |
|
66 %! assert(prog_output_assert("1234")); |
|
67 |
|
68 %% test/octave.test/for/for-7.m |
|
69 %!test |
|
70 %! for i = [1,2;3,4]*I |
|
71 %! printf_assert ("%d", imag (i(1,1))); |
|
72 %! printf_assert ("%d", imag (i(2,1))); |
|
73 %! endfor |
|
74 %! printf_assert ("\n"); |
|
75 %! assert(prog_output_assert("1324")); |
|
76 |
|
77 %% test/octave.test/for/for-8.m |
|
78 %!test |
|
79 %! for i = [1,2,3,4] |
|
80 %! if (i > 2) |
|
81 %! break; |
|
82 %! endif |
|
83 %! printf_assert ("%d", i); |
|
84 %! endfor |
|
85 %! printf_assert ("\n"); |
|
86 %! assert(prog_output_assert("12")); |
|
87 |
|
88 %% test/octave.test/for/for-9.m |
|
89 %!test |
|
90 %! for i = [1,2,3,4] |
|
91 %! if (i < 3) |
|
92 %! continue; |
|
93 %! endif |
|
94 %! printf_assert ("%d", i); |
|
95 %! endfor |
|
96 %! printf_assert ("\n"); |
|
97 %! assert(prog_output_assert("34")); |
|
98 |
6587
|
99 %!test |
|
100 %! a = [1,3;2,4]; |
|
101 %! j = 0; |
|
102 %! for i = cat (3, a, 4 + a) |
|
103 %! assert (i, [1;2] + 2*j++) |
|
104 %! endfor |
|
105 |
|
106 %!test |
|
107 %! a = {1,3;2,4}; |
6602
|
108 %! j = 0; |
6587
|
109 %! for i = cat (3, a, cellfun(@(x) 4 + x, a, 'UniformOutput', 0)) |
|
110 %! assert (i, {1 + 2*j; 2 + 2*j++}) |
|
111 %! endfor |