annotate test/struct.tst @ 17481:576cf0589c6d

Overhaul contour labeling functions. * scripts/plot/clabel.m: Use 'h', rather than 'retval', to match variables to documentation. Improve performance of input processing by using try/catch block and eliminating for loops. * scripts/plot/private/__clabel__.m: Get X and Y spacing in points from axis rather than assuming 4"x3" plot figure. Fix incorrect determination of axis limits if no contour handle provided. Rename loop vars i1, j1 to i,j. Performance improvement by using bsxfun over repmat. Use find to replace while loop (slow). Keep label rotation in the range [-90, 90] for readability.
author Rik <rik@octave.org>
date Tue, 24 Sep 2013 13:16:50 -0700
parents 57fad64de019
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
60 %!assert (!(isstruct (1)))
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
61
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
62 %!assert (!(isstruct ([1, 2])))
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
63
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
64 %!assert (!(isstruct ([])))
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
65
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
66 %!assert (!(isstruct ([1, 2; 3, 4])))
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
67
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
68 %!assert (!(isstruct ("t")))
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
69
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
70 %!assert (!(isstruct ("test")))
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
71
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 (["test"; "ing"])))
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
73
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
74 %!assert (!(isstruct ({1})))
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
75
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
76 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
77 %! 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
78 %! assert (isstruct (s));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
79
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
80 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
81 %! 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
82 %! assert (isstruct (s.a));
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
83
13915
5fa482628bf6 Remove unnecessary regular expression '.*' from ends of %!error blocks
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
84 %!error <Invalid call to isstruct> isstruct ();
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
85
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
86 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
87 %! 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
88 %! fail ("isstruct (s, 1)", "Invalid call to isstruct");
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
89
8603
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
90 ## 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
91 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
92 %! 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
93 %! 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
94 %! 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
95
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
96 ## 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
97 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
98 %! [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
99 %! 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
100 %! 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
101
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
102 ## 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
103 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
104 %! 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
105 %! [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
106 %! 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
107
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
108 ## 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
109 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
110 %! 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
111 %! 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
112 %! 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
113
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
114 ## 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
115 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
116 %! 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
117 %! 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
118 %! [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
119 %! 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
120 %! 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
121
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
122 ## 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
123 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
124 %! 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
125 %! 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
126 %! 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
127
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
128 ## 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
129 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
130 %! 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
131 %! 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
132 %! [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
133 %! 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
134 %! 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
135
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
136 ## 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
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([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
140 %! 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
141
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
142 ## 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
143 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
144 %! 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
145 %! 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
146 %! 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
147 %! 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
148 %! 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
149 %! [3, 2, 1]);
8603
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
150
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
151 ## 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
152 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
153 %! 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
154 %! [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
155 %! 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
156 %! 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
157 %! 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
158
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
159 %!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
160 %! [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
161 %! [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
162
10588
c1111769f595 test_struct: update expected error message text
John W. Eaton <jwe@octave.org>
parents: 10399
diff changeset
163 %!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
164 %! [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
165 %! 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
166
10399
81bcdf5fd7a9 modernize failing tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10366
diff changeset
167 %!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
168 %! 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
169 %! a(2).x;
8603
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
170
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
171 %!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
172 %! 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
173 %! [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
174
4c68e26e3ba1 Add tests to prevent regression of struct array indexing
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7017
diff changeset
175 %!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
176 %! 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
177 %! 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
178 %! 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
179
9122
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
180 ## 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
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 = a;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
184 %! 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
185 %! 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
186
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
187 ## 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
188 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
189 %! a.a = 1;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
190 %! a.b = 2;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
191 %! b.c = a;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
192 %! b.d = 3;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
193 %! c.d = b;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
194 %! c.e = 4;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
195 %! a.b = c;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
196 %! 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
197 %! 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
198
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
199 ## 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
200 %!function aa = do_nest (a);
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
201 %! aa = a;
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
202 %! 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
203 %!endfunction
9122
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
204 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
205 %! a.c = 1;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
206 %! 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
207 %! 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
208 %! 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
209 %! 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
210
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
211 ## 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
212 %!function aa = do_nest (a);
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
213 %! aa = a;
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
214 %! aa.b = a;
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
215 %! 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
216 %!endfunction
9122
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
217 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
218 %! a.c = 1;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
219 %! 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
220 %! 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
221 %! 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
222 %! 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
223
8ca06fd9c6ef test lazy copying in structures
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9112
diff changeset
224 ## 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
225 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
226 %! a.b = 1;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
227 %! b.c = a;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
228 %! 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
229 %! 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
230 %! 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
231 %! a.m = b;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
232 %! 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
233 %! 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
234
67fa54583fe8 Add test to prevent regression of empty struct assignment bug
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9122
diff changeset
235 ## 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
236 %!test
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
237 %! 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
238 %! 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
239 %! 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
240
10399
81bcdf5fd7a9 modernize failing tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10366
diff changeset
241 %!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
242 %! 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
243 %! 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
244 %! s(7);