Mercurial > hg > octave-nkf
annotate test/struct.tst @ 16033:23a7661e529a ss-3-7-2
snapshot version 3.7.2
* configure.ac (AC_INIT): Set version to 3.7.2.
(OCTAVE_RELEASE_DATE): Set to 2013-02-09.
(OCTAVE_COPYRIGHT): Update year.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 10 Feb 2013 00:59:19 -0500 |
parents | 1af8d21608b7 |
children | b1283d4c06c2 |
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/struct/fieldnames-1.m |
20 %!test | |
21 %! s.a = 1; | |
22 %! c = fieldnames (s); | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
23 %! assert (iscell (c) && strcmp (c{1}, "a")); |
5590 | 24 |
25 %% test/octave.test/struct/fieldnames-2.m | |
26 %!test | |
27 %! s.a.b = 1; | |
28 %! c = fieldnames (s.a); | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
29 %! assert (iscell (c) && strcmp (c{1}, "b")); |
5590 | 30 |
31 %% test/octave.test/struct/fieldnames-3.m | |
13915
5fa482628bf6
Remove unnecessary regular expression '.*' from ends of %!error blocks
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
32 %!error <Invalid call to fieldnames> fieldnames (); |
5590 | 33 |
34 %% test/octave.test/struct/fieldnames-4.m | |
35 %!test | |
36 %! s.a = 1; | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
37 %! fail ("fieldnames (s, 1)", "Invalid call to fieldnames"); |
5590 | 38 |
39 %% test/octave.test/struct/fieldnames-5.m | |
40 %!error fieldnames (1); | |
41 | |
42 %% test/octave.test/struct/isfield-1.m | |
43 %!test | |
44 %! s.aaa = 1; | |
45 %! s.a = 2; | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
46 %! assert (isfield (s, "a")); |
5590 | 47 |
48 %% test/octave.test/struct/isfield-2.m | |
49 %!test | |
50 %! s.aaa = 1; | |
51 %! s.a = 2; | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
52 %! assert (!(isfield (s, "b"))); |
5590 | 53 |
54 %% test/octave.test/struct/isfield-3.m | |
13915
5fa482628bf6
Remove unnecessary regular expression '.*' from ends of %!error blocks
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
55 %!error <Invalid call to isfield> isfield (); |
5590 | 56 |
57 %% test/octave.test/struct/isfield-4.m | |
58 %!test | |
59 %! s.aaa = 1; | |
60 %! s.a = 2; | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
61 %! fail ("isfield (s, 'a', 3);", "Invalid call to isfield"); |
5590 | 62 |
63 %% test/octave.test/struct/isfield-5.m | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
64 %!assert (isfield (1, "m") == 0); |
5590 | 65 |
66 %% test/octave.test/struct/isfield-6.m | |
67 %!test | |
68 %! s.a = 2; | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
69 %! assert (isfield (s, 2) == 0); |
5590 | 70 |
71 %% test/octave.test/struct/isstruct-1.m | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
72 %!assert (!(isstruct (1))) |
5590 | 73 |
74 %% test/octave.test/struct/isstruct-2.m | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
75 %!assert (!(isstruct ([1, 2]))) |
5590 | 76 |
77 %% test/octave.test/struct/isstruct-3.m | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
78 %!assert (!(isstruct ([]))) |
5590 | 79 |
80 %% test/octave.test/struct/isstruct-4.m | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
81 %!assert (!(isstruct ([1, 2; 3, 4]))) |
5590 | 82 |
83 %% test/octave.test/struct/isstruct-5.m | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
84 %!assert (!(isstruct ("t"))) |
5590 | 85 |
86 %% test/octave.test/struct/isstruct-6.m | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
87 %!assert (!(isstruct ("test"))) |
5590 | 88 |
89 %% test/octave.test/struct/isstruct-7.m | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
90 %!assert (!(isstruct (["test"; "ing"]))) |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
91 |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
92 %!assert (!(isstruct ({1}))) |
5590 | 93 |
94 %% test/octave.test/struct/isstruct-8.m | |
95 %!test | |
96 %! s.a = 1; | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
97 %! assert (isstruct (s)); |
5590 | 98 |
99 %% test/octave.test/struct/isstruct-9.m | |
100 %!test | |
101 %! s.a.b = 1; | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
102 %! assert (isstruct (s.a)); |
5590 | 103 |
104 %% test/octave.test/struct/isstruct-10.m | |
13915
5fa482628bf6
Remove unnecessary regular expression '.*' from ends of %!error blocks
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
105 %!error <Invalid call to isstruct> isstruct (); |
5590 | 106 |
107 %% test/octave.test/struct/isstruct-11.m | |
108 %!test | |
109 %! s.a = 1; | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
110 %! fail ("isstruct (s, 1)", "Invalid call to isstruct"); |
5590 | 111 |
8603
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
112 ## increment element of matrix stored in struct array field |
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
113 %!test |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
114 %! a = struct ("c", {[1, 2, 3], [4, 5, 6], [7, 8, 9]}); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
115 %! a(2).c(3)++; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
116 %! assert (a(2).c, [4, 5, 7]); |
8603
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
117 |
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
118 ## create struct array by assignment to cs-list |
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
119 %!test |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
120 %! [a(1:2).x] = deal (1, 3); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
121 %! assert (a, struct ("x", {1, 3})); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
122 %! assert ({a(1:2).x}, {1, 3}); |
8603
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
123 |
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
124 ## assign to subrange of struct array field |
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
125 %!test |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
126 %! b = struct ("name", {"a", "b", "c"; "d", "e", "f"}, "value", 100); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
127 %! [b(1:2, [1,3]).name] = deal ("aaa", "ddd", "ccc", "fff"); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
128 %! assert ({b.name}, {"aaa", "ddd", "b", "e", "ccc", "fff"}); |
8603
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
129 |
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
130 ## index into nested struct arrays |
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
131 %!test |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
132 %! a = struct ("name", {"a", "b", "c"; "d", "e", "f"}, "value", 0); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
133 %! a(2).value = a; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
134 %! assert (a(2).value(2,3).name, "f"); |
8603
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
135 |
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
136 ## assign to subrange of field in nested struct array |
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
137 %!test |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
138 %! b = struct ("name", {"a", "b", "c"; "d", "e", "f"}, "value", 0); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
139 %! b(3, 1).value = b; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
140 %! [b(3, 1).value(1, [1, 3]).name] = deal ("aaa", "ccc"); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
141 %! assert (size (b), [3, 3]); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
142 %! assert (b(3,1).value(1, 3).name, "ccc"); |
8603
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
143 |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
144 ## test 4-dimensional struct array |
8603
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
145 %!test |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
146 %! c(4, 4, 4, 4).name = "a"; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
147 %! c(3, 3, 3, 3).value = 1; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
148 %! assert (c(2,2,2,2), struct ("name", [], "value", [])); |
8603
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
149 |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
150 ## assign to subrange of field in 4D struct array |
8603
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
151 %!test |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
152 %! c(4, 4, 4, 4).name = "a"; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
153 %! c(3, 3, 3, 3).value = 1; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
154 %! [c([1, 3], 2, :, [3, 4]).value] = deal (1); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
155 %! assert (length(find([c.value] == 1)), 17); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
156 %! assert (length(find([c.value])), 17); |
8603
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
157 |
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
158 ## swap elements of struct array |
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
159 %!test |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
160 %! b = struct ("name", {"a", "b", "c"; "d", "e", "f"}, "value", 0); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
161 %! [b([2, 1], [3, 1]).name] = deal (b([1, 2], [1, 2]).name); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
162 %! assert ({b.name}, {"e", "b", "b", "e", "d", "a"}); |
8603
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
163 |
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
164 ## test internal ordering of struct array fields |
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
165 %!test |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
166 %! c(4, 4, 4, 4).value = 3; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
167 %! c(1, 2, 3, 4).value = 2; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
168 %! c(3, 3, 3, 3).value = 1; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
169 %! d = reshape ({c.value}, size(c)); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
170 %! assert ([d{4, 4, 4, 4}, d{1, 2, 3, 4}, d{3, 3, 3, 3}], |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
171 %! [3, 2, 1]); |
8603
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
172 |
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
173 ## test assignment to mixed cs-list of field element subranges |
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
174 %!test |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
175 %! b = struct ("name", {"a", "b", "c"; "d", "e", "f"}, "value", 100); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
176 %! [b(1:2, [1, 3]).name, b(2, 1:3).value] = ... |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
177 %! deal (1, 2, 3, 4, "5", "6", "7"); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
178 %! assert ({b.name}, {1, 2, "b", "e", 3, 4}); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
179 %! assert ({b.value}, {100, "5", 100, "6", 100, "7"}); |
8603
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
180 |
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
181 %!error <a cs-list cannot be further indexed> |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
182 %! [a(1:3).x] = deal ([1, 5], [3, 7], [8, 9]); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
183 %! [a(2:3).x(2)] = deal (10, 11); |
8603
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
184 |
10588
c1111769f595
test_struct: update expected error message text
John W. Eaton <jwe@octave.org>
parents:
10399
diff
changeset
|
185 %!error <a cs-list cannot be further indexed> |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
186 %! [a(1:3).x] = deal ([1, 5], [3, 7], [8, 9]); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
187 %! a(2:3).x(2); |
8603
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
188 |
10399
81bcdf5fd7a9
modernize failing tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10366
diff
changeset
|
189 %!error id=Octave:index-out-of-bounds |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
190 %! a(1).x.x = 1; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
191 %! a(2).x; |
8603
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
192 |
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
193 %!error <invalid number of output arguments for constant expression> |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
194 %! a = struct ("value", {1, 2, 3, 4, 5}); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
195 %! [a(2:4).value] = 1; |
8603
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
196 |
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
197 %!error <invalid assignment to cs-list outside multiple assignment> |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
198 %! c(4, 4, 4, 4).name = "a"; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
199 %! c(3, 3, 3, 3).value = 1; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
200 %! c([1, 3], 2, :, [3, 4]).value = 1; |
8603
4c68e26e3ba1
Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
201 |
9122
8ca06fd9c6ef
test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9112
diff
changeset
|
202 ## test lazy copying in structs: nested assignment to self |
8ca06fd9c6ef
test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9112
diff
changeset
|
203 %!test |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
204 %! a.a = 1; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
205 %! a.b = a; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
206 %! a.b.c = a; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
207 %! assert (a.b.c.b, struct ("a", 1)); |
9122
8ca06fd9c6ef
test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9112
diff
changeset
|
208 |
8ca06fd9c6ef
test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9112
diff
changeset
|
209 ## test lazy copying in structs: indirect nested assignment to self |
8ca06fd9c6ef
test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9112
diff
changeset
|
210 %!test |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
211 %! a.a = 1; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
212 %! a.b = 2; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
213 %! b.c = a; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
214 %! b.d = 3; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
215 %! c.d = b; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
216 %! c.e = 4; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
217 %! a.b = c; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
218 %! a.b.e = a; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
219 %! assert (a.b.e.b.d.c, struct ("a", 1, "b", 2)); |
9122
8ca06fd9c6ef
test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9112
diff
changeset
|
220 |
8ca06fd9c6ef
test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9112
diff
changeset
|
221 ## test lazy copying in structs: nested assignment via function |
8ca06fd9c6ef
test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9112
diff
changeset
|
222 %!function aa = do_nest (a); |
8ca06fd9c6ef
test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9112
diff
changeset
|
223 %! aa = a; |
8ca06fd9c6ef
test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9112
diff
changeset
|
224 %! aa.b = a; |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
225 %!endfunction |
9122
8ca06fd9c6ef
test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9112
diff
changeset
|
226 %!test |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
227 %! a.c = 1; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
228 %! a = do_nest (a); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
229 %! a = do_nest (a); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
230 %! a = do_nest (a); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
231 %! assert (a.b.b.b, struct ("c", 1)); |
9122
8ca06fd9c6ef
test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9112
diff
changeset
|
232 |
8ca06fd9c6ef
test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9112
diff
changeset
|
233 ## test lazy copying in structs: nested assignment via function |
8ca06fd9c6ef
test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9112
diff
changeset
|
234 %!function aa = do_nest (a); |
8ca06fd9c6ef
test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9112
diff
changeset
|
235 %! aa = a; |
8ca06fd9c6ef
test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9112
diff
changeset
|
236 %! aa.b = a; |
8ca06fd9c6ef
test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9112
diff
changeset
|
237 %! aa.b.c = aa; |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
238 %!endfunction |
9122
8ca06fd9c6ef
test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9112
diff
changeset
|
239 %!test |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
240 %! a.c = 1; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
241 %! a = do_nest (a); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
242 %! a = do_nest (a); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
243 %! a = do_nest (a); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
244 %! assert (a.b.c.b.b.c.b.b.c.b, struct ("c", 1)); |
9122
8ca06fd9c6ef
test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9112
diff
changeset
|
245 |
8ca06fd9c6ef
test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9112
diff
changeset
|
246 ## test lazy copying in structs: nested assignment on different levels. |
8ca06fd9c6ef
test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9112
diff
changeset
|
247 %!test |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
248 %! a.b = 1; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
249 %! b.c = a; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
250 %! b.d.e = a; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
251 %! b.f.g.h = a; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
252 %! b.i.j.k.l = a; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
253 %! a.m = b; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
254 %! a.m.c.b = a; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
255 %! assert (a.m.c.b.m.i.j.k.l, struct ("b", 1)); |
9130
67fa54583fe8
Add test to prevent regression of empty struct assignment bug
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9122
diff
changeset
|
256 |
67fa54583fe8
Add test to prevent regression of empty struct assignment bug
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9122
diff
changeset
|
257 ## test indexed assignment into empty struct array |
67fa54583fe8
Add test to prevent regression of empty struct assignment bug
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9122
diff
changeset
|
258 %!test |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
259 %! s = resize (struct (), 3,2); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
260 %! s(3).foo = 42; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
261 %! assert (s(3), struct ("foo", 42)); |
9130
67fa54583fe8
Add test to prevent regression of empty struct assignment bug
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9122
diff
changeset
|
262 |
10399
81bcdf5fd7a9
modernize failing tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10366
diff
changeset
|
263 %!error id=Octave:index-out-of-bounds |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
264 %! s = resize (struct (),3,2); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
265 %! s(3).foo = 42; |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
266 %! s(7); |