Mercurial > octave-nkf
annotate test/test_switch.m @ 16088:b29b10fbb744 stable release-3-6-4
Version 3.6.4 released.
* configure.ac (AC_INIT): Version is now 3.6.4.
(OCTAVE_RELEASE_DATE): Now 2013-02-21.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 21 Feb 2013 15:17:54 -0500 |
parents | 72c96de7a403 |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14131
diff
changeset
|
1 ## Copyright (C) 2006-2012 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 %! | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
30 %! assert (x == c && y == a && z == b && p == c); |
5590 | 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) | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
44 %! case a |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
45 %! x(k) = a; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
46 %! case b |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
47 %! x(k) = b; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
48 %! otherwise |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
49 %! x(k) = c; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
50 %! endswitch |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
51 %! k++; |
5590 | 52 %! endfor |
53 %! | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
54 %! assert (all (x == [3, 1, 2, 3])); |
5590 | 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 | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
67 %! switch (i) |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
68 %! case a |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
69 %! x(k) = a; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
70 %! endswitch |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
71 %! k++; |
5590 | 72 %! endfor |
73 %! | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
74 %! assert (all (x == [0, 1, 0, 0])); |
5590 | 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 %! |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
84 %! assert (a == 2); |
11353
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 |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
88 %!error <syntax error> eval ("switch endswitch") |
5590 | 89 |
90 %% test/octave.test/switch/switch-5.m | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
91 %!error <syntax error> eval ("switch case endswitch") |
5590 | 92 |
93 %% test/octave.test/switch/switch-6.m | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
94 %!error <syntax error> eval ("switch 1 default 1; endswitch") |
5590 | 95 |