Mercurial > octave-nkf
annotate test/test_switch.m @ 13741:b0e70a71647b stable release-3-4-3
Version 3.4.3 released.
* configure.ac (AC_INIT): Version number is now 3.4.3.
(OCTAVE_RELEASE_DATE): Update to 2011-10-10.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 10 Oct 2011 10:23:45 -0400 |
parents | fd0a3ac60b0e |
children | c3309e1ec50d |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2006-2011 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/switch/switch-1.m |
20 %!test | |
21 %! a = 1; | |
22 %! b = 2; | |
23 %! c = 3; | |
24 %! | |
25 %! switch 0 case 1 x = a; case 2 x = b; otherwise x = c; endswitch | |
26 %! switch 1 case 1 y = a; case 2 y = b; otherwise y = c; endswitch | |
27 %! switch 2 case 1 z = a; case 2 z = b; otherwise z = c; endswitch | |
28 %! switch 3 case 1 p = a; case 2 p = b; otherwise p = c; endswitch | |
29 %! | |
30 %! assert(x == c && y == a && z == b && p == c); | |
31 | |
32 %% test/octave.test/switch/switch-2.m | |
33 %!test | |
34 %! a = 1; | |
35 %! b = 2; | |
36 %! c = 3; | |
37 %! | |
38 %! x = zeros (1, 4); | |
39 %! | |
40 %! k = 1; | |
41 %! | |
42 %! for i = 0:3 | |
43 %! switch (i) | |
44 %! case a | |
45 %! x(k) = a; | |
46 %! case b | |
47 %! x(k) = b; | |
48 %! otherwise | |
49 %! x(k) = c; | |
50 %! endswitch | |
51 %! k++; | |
52 %! endfor | |
53 %! | |
54 %! assert(all (x == [3, 1, 2, 3])); | |
55 | |
56 %% test/octave.test/switch/switch-3.m | |
57 %!test | |
58 %! a = 1; | |
59 %! b = 2; | |
60 %! c = 3; | |
61 %! | |
62 %! x = zeros (1, 4); | |
63 %! | |
64 %! k = 1; | |
65 %! | |
66 %! for i = 0:3 | |
67 %! switch (i) | |
68 %! case a | |
69 %! x(k) = a; | |
70 %! endswitch | |
71 %! k++; | |
72 %! endfor | |
73 %! | |
74 %! assert(all (x == [0, 1, 0, 0])); | |
75 | |
11353
cbf58e4b5f4e
Add test for switch statement with otherwise clause, but no cases.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
76 %!test |
cbf58e4b5f4e
Add test for switch statement with otherwise clause, but no cases.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
77 %! a = 1; |
cbf58e4b5f4e
Add test for switch statement with otherwise clause, but no cases.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
78 %! |
cbf58e4b5f4e
Add test for switch statement with otherwise clause, but no cases.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
79 %! switch 1 |
cbf58e4b5f4e
Add test for switch statement with otherwise clause, but no cases.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
80 %! otherwise |
cbf58e4b5f4e
Add test for switch statement with otherwise clause, but no cases.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
81 %! a = 2; |
cbf58e4b5f4e
Add test for switch statement with otherwise clause, but no cases.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
82 %! endswitch |
cbf58e4b5f4e
Add test for switch statement with otherwise clause, but no cases.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
83 %! |
cbf58e4b5f4e
Add test for switch statement with otherwise clause, but no cases.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
84 %! assert(a == 2); |
cbf58e4b5f4e
Add test for switch statement with otherwise clause, but no cases.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
85 |
cbf58e4b5f4e
Add test for switch statement with otherwise clause, but no cases.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
86 |
5590 | 87 %% test/octave.test/switch/switch-4.m |
88 %!error <syntax error> eval("switch endswitch"); | |
89 | |
90 %% test/octave.test/switch/switch-5.m | |
91 %!error <syntax error> eval("switch case endswitch"); | |
92 | |
93 %% test/octave.test/switch/switch-6.m | |
94 %!error <syntax error> eval("switch 1 default 1; endswitch"); | |
95 |