annotate test/struct.tst @ 20619:96163bdd2ea1

Fix assigning into structs with trailing singleton dimensions (bug #35841) * ov-struct.cc (subsasgn): If indexing results in empty matrix, substitute a 1x1 empty cell. Change test so that if numel of indexing operation is '<= 1' operation proceeds rather than '== 1'. * struct.tst: Add BIST test for bug #35841.
author Lachlan Andrew <lachlanbis@gmail.com>
date Tue, 13 Oct 2015 09:55:46 -0700
parents 4197fc428c7d
children a4faec57f4c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
1 ## Copyright (C) 2006-2015 John W. Eaton
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5751
diff changeset
2 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5751
diff changeset
3 ## This file is part of Octave.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5751
diff changeset
4 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5751
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5751
diff changeset
6 ## under the terms of the GNU General Public License as published by
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5751
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5751
diff changeset
8 ## your option) any later version.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5751
diff changeset
9 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5751
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5751
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5751
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5751
diff changeset
13 ## General Public License for more details.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5751
diff changeset
14 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5751
diff changeset
15 ## You should have received a copy of the GNU General Public License
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5751
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5751
diff changeset
17 ## <http://www.gnu.org/licenses/>.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5751
diff changeset
18
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
19 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
20 %! s.a = 1;
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
21 %! 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
22 %! assert (iscell (c) && strcmp (c{1}, "a"));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
23
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
24 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
25 %! s.a.b = 1;
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
26 %! 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
27 %! assert (iscell (c) && strcmp (c{1}, "b"));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
28
13915
5fa482628bf6 Remove unnecessary regular expression '.*' from ends of %!error blocks
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
29 %!error <Invalid call to fieldnames> fieldnames ();
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
30
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
31 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
32 %! 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
33 %! fail ("fieldnames (s, 1)", "Invalid call to fieldnames");
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
34
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
35 %!error fieldnames (1);
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
36
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
37 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
38 %! s.aaa = 1;
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
39 %! 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
40 %! assert (isfield (s, "a"));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
41
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
42 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
43 %! s.aaa = 1;
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
44 %! 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
45 %! assert (!(isfield (s, "b")));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
46
13915
5fa482628bf6 Remove unnecessary regular expression '.*' from ends of %!error blocks
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
47 %!error <Invalid call to isfield> isfield ();
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
48
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
49 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
50 %! s.aaa = 1;
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
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 %! fail ("isfield (s, 'a', 3);", "Invalid call to isfield");
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
53
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
54 %!assert (isfield (1, "m") == 0);
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
55
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
56 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
57 %! 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
58 %! assert (isfield (s, 2) == 0);
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
59
20619
96163bdd2ea1 Fix assigning into structs with trailing singleton dimensions (bug #35841)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
60 %!assert (isstruct (1), false)
96163bdd2ea1 Fix assigning into structs with trailing singleton dimensions (bug #35841)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
61 %!assert (isstruct ([1, 2]), false)
96163bdd2ea1 Fix assigning into structs with trailing singleton dimensions (bug #35841)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
62 %!assert (isstruct ([]), false)
96163bdd2ea1 Fix assigning into structs with trailing singleton dimensions (bug #35841)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
63 %!assert (isstruct ([1, 2; 3, 4]), false)
96163bdd2ea1 Fix assigning into structs with trailing singleton dimensions (bug #35841)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
64 %!assert (isstruct ("t"), false)
96163bdd2ea1 Fix assigning into structs with trailing singleton dimensions (bug #35841)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
65 %!assert (isstruct ("test"), false)
96163bdd2ea1 Fix assigning into structs with trailing singleton dimensions (bug #35841)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
66 %!assert (isstruct (["test"; "ing"]), false)
96163bdd2ea1 Fix assigning into structs with trailing singleton dimensions (bug #35841)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
67 %!assert (isstruct ({1}), false)
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
68
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
69 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
70 %! 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
71 %! assert (isstruct (s));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
72
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
73 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
74 %! 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
75 %! assert (isstruct (s.a));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
76
13915
5fa482628bf6 Remove unnecessary regular expression '.*' from ends of %!error blocks
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
77 %!error <Invalid call to isstruct> isstruct ();
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
78
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
79 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
80 %! 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
81 %! fail ("isstruct (s, 1)", "Invalid call to isstruct");
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
82
8603
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
83 ## 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
84 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
85 %! 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
86 %! 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
87 %! 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
88
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
89 ## 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
90 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
91 %! [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
92 %! 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
93 %! 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
94
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
95 ## 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
96 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
97 %! 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
98 %! [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
99 %! 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
100
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
101 ## 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
102 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
103 %! 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
104 %! 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
105 %! 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
106
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
107 ## 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
108 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
109 %! 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
110 %! 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
111 %! [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
112 %! 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
113 %! 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
114
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
115 ## 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
116 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
117 %! 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
118 %! 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
119 %! 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
120
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
121 ## 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
122 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
123 %! 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
124 %! 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
125 %! [c([1, 3], 2, :, [3, 4]).value] = deal (1);
16213
b1283d4c06c2 test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents: 16030
diff changeset
126 %! assert (length (find ([c.value] == 1)), 17);
b1283d4c06c2 test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents: 16030
diff changeset
127 %! 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
128
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
129 ## 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
130 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
131 %! 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
132 %! [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
133 %! 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
134
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
135 ## 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
136 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
137 %! 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
138 %! 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
139 %! c(3, 3, 3, 3).value = 1;
16213
b1283d4c06c2 test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents: 16030
diff changeset
140 %! d = reshape ({c.value}, size (c));
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
141 %! 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
142 %! [3, 2, 1]);
8603
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
143
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
144 ## 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
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 %! 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
147 %! [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
148 %! 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
149 %! 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
150 %! 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
151
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
152 %!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
153 %! [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
154 %! [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
155
10588
c1111769f595 test_struct: update expected error message text
John W. Eaton <jwe@octave.org>
parents: 10399
diff changeset
156 %!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
157 %! [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
158 %! 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
159
10399
81bcdf5fd7a9 modernize failing tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10366
diff changeset
160 %!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
161 %! 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
162 %! a(2).x;
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 %!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
165 %! 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
166 %! [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
167
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
168 %!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
169 %! 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
170 %! 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
171 %! 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
172
9122
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
173 ## 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
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 %! a.a = 1;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
176 %! a.b = a;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
177 %! 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
178 %! 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
179
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
180 ## 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
181 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
182 %! a.a = 1;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
183 %! a.b = 2;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
184 %! b.c = a;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
185 %! b.d = 3;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
186 %! c.d = b;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
187 %! c.e = 4;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
188 %! a.b = c;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
189 %! 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
190 %! 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
191
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
192 ## 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
193 %!function aa = do_nest (a);
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
194 %! aa = a;
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
195 %! 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
196 %!endfunction
9122
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
197 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
198 %! a.c = 1;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
199 %! 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
200 %! 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
201 %! 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
202 %! 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
203
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
204 ## 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
205 %!function aa = do_nest (a);
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
206 %! aa = a;
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
207 %! aa.b = a;
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
208 %! 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
209 %!endfunction
9122
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.c = 1;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
212 %! 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
213 %! 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
214 %! 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
215 %! 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
216
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
217 ## 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
218 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
219 %! a.b = 1;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
220 %! b.c = a;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
221 %! 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
222 %! 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
223 %! 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
224 %! a.m = b;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
225 %! 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
226 %! 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
227
67fa54583fe8 Add test to prevent regression of empty struct assignment bug
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9122
diff changeset
228 ## 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
229 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
230 %! 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
231 %! 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
232 %! 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
233
20619
96163bdd2ea1 Fix assigning into structs with trailing singleton dimensions (bug #35841)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
234 ## test assigning to multi-dim struct with trailing singleton dimensions,
96163bdd2ea1 Fix assigning into structs with trailing singleton dimensions (bug #35841)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
235 ## Bug #35841.
96163bdd2ea1 Fix assigning into structs with trailing singleton dimensions (bug #35841)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
236 %!test
96163bdd2ea1 Fix assigning into structs with trailing singleton dimensions (bug #35841)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
237 %! a(1,1,1).b(1) = 1;
96163bdd2ea1 Fix assigning into structs with trailing singleton dimensions (bug #35841)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
238 %! a(1,1,1).b(1) = 2;
96163bdd2ea1 Fix assigning into structs with trailing singleton dimensions (bug #35841)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
239 %! a(1,1,:).b(1) = 3;
96163bdd2ea1 Fix assigning into structs with trailing singleton dimensions (bug #35841)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
240 %! assert (a(1,1,1).b(1) == 3);
96163bdd2ea1 Fix assigning into structs with trailing singleton dimensions (bug #35841)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19697
diff changeset
241
10399
81bcdf5fd7a9 modernize failing tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10366
diff changeset
242 %!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
243 %! 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
244 %! 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
245 %! s(7);