comparison test/index.tst @ 16030:1af8d21608b7

rename all test files in the test directory from test_X.m to X.tst * Use - instead of _ for .tst file names. Fix all file lists in module.mk and Makefile.am files. * __run_test_suite__.m: Adapt to new naming convention.
author John W. Eaton <jwe@octave.org>
date Sat, 09 Feb 2013 21:35:55 -0500
parents test/test_index.m@72c96de7a403
children 1c8234f0b642
comparison
equal deleted inserted replaced
16029:b8157404614f 16030:1af8d21608b7
1 ## Copyright (C) 2006-2012 John W. Eaton
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
19 %!test
20 %! a = [];
21 %! assert (isempty (a));
22
23 %!shared a
24 %! a = 1;
25 %!assert (a(1), 1)
26 %!assert (a(:), 1)
27 %!assert (a(:,:), 1)
28 %!assert (a(1,:), 1)
29 %!assert (a(:,1),1)
30 %!assert (isempty (a(logical (0))))
31 %!error a(-1)
32 %!error a(2)
33 %!error a(2,:)
34 %!error a(:,2)
35 %!error a(-1,:)
36 %!error a(:,-1)
37 %!error a([1,2,3])
38 %!error a([1;2;3])
39 %!error a([1,2;3,4])
40 %!error a([0,1])
41 %!error a([0;1])
42 %!error a([-1,0])
43 %!error a([-1;0])
44
45 %!shared a, a_prime, mid_a
46 %! a = [4,3,2,1];
47 %! a_prime = [4;3;2;1];
48 %! mid_a = [3,2];
49
50 %!assert (a(1),4)
51 %!assert (a(2),3)
52 %!assert (all (a(:) == a_prime))
53 %!assert (all (a(1,:) == a))
54 %!assert (a(:,3),2)
55 %!assert (all (a(:,:) == a))
56 %!assert (all (a(logical ([0,1,1,0])) == mid_a))
57 %!error a(0)
58 %!error a(5)
59 %!error a(0,1)
60 %!assert (isempty (a(logical (0),:)))
61 %!error a(:,0)
62 %!assert (isempty (a([])))
63 %!assert (isempty (a([],:)))
64 %!assert (isempty (a(:,[])))
65
66 %!shared a, a_fvec, a_col_1, a_col_2, a_row_1, a_row_2
67 %! a = [1,2;3,4];
68 %! a_fvec = [1;3;2;4];
69 %! a_col_1 = [1;3];
70 %! a_col_2 = [2;4];
71 %! a_row_1 = [1,2];
72 %! a_row_2 = [3,4];
73
74 %!assert (all (all (a(:,:) == a)))
75 %!assert (all (a(:) == a_fvec))
76 %!error a(0)
77 %!assert (a(2), 3)
78
79 %% Additional tests
80
81 %!shared a, b
82 %! a = [1,2;3,4];
83 %! b = a;
84 %! b(:,:,2) = [5,6;7,8];
85
86 %!assert (a(:), [1;3;2;4])
87 %!assert (a(1:2), [1,3])
88 %!assert (a(:,:), [1,2;3,4])
89 %!assert (a(:,1), [1;3])
90 %!assert (a(1,1), 1)
91 %!assert (a(1:2,1), [1;3])
92 %!assert (a(:,:,1), [1,2;3,4])
93
94 %!test
95 %! c(:,:,1) = [1,2;3,4];
96 %! c(:,:,2) = [1,2;3,4];
97 %! assert (a(:,:,[1,1]), c)
98
99 %!test
100 %! c(:,:,1,1) = [1,2;3,4];
101 %! c(:,:,1,2) = [1,2;3,4];
102 %! assert (a(:,:,1,[1,1]), c)
103
104 %!test
105 %! c(:,:,1,1) = [1,2;3,4];
106 %! c(:,:,2,1) = [1,2;3,4];
107 %! c(:,:,1,2) = [1,2;3,4];
108 %! c(:,:,2,2) = [1,2;3,4];
109 %! assert (a(:,:,[1,1],[1,1]), c)
110
111 %!assert (a(1,[]), zeros (1,0))
112 %!assert (a(1,[],[1,1]), zeros (1,0,2))
113 %!assert (a(1,1,[]), zeros (1,1,0))
114
115 %!test
116 %! c (1:10,1) = 1:10;
117 %! assert (c, [1:10]');
118
119 %!assert (b(:), [1; 3; 2; 4; 5; 7; 6; 8])
120 %!assert (b(:,:), [1, 2, 5, 6; 3, 4, 7, 8])
121 %!assert (b(:,1), [1;3])
122 %!assert (b(:,:,:), reshape ([1,3,2,4,5,7,6,8],[2,2,2]))
123 %!assert (b(:,1,1), [1;3])
124 %!assert (b(:,1,1,[1,1]),reshape ([1,3,1,3],[2,1,1,2]))
125 %!assert (b(1,3), 5)
126 %!assert (b(1,[3,4]), [5,6])
127 %!assert (b(1,1:4), [1,2,5,6])
128 %!assert (b(1,[],:), zeros (1,0,2))
129 %!assert (b(1,[]), zeros(1,0))
130 %!assert (b(:,3), [5;7])
131 %!assert (b([1,2],3), [5;7])
132 %!assert (b(true(2,1),3), [5;7])
133 %!assert (b(false(2,1),3), zeros(0,1))
134 %!assert (b([],3), zeros(0,1))
135
136 %!shared x
137 %! # Dummy shared block to clear any previous definitions
138 %! x = 1;
139
140 %!test
141 %! a(1,:) = [1,3];
142 %! assert (a, [1,3]);
143
144 %!test
145 %! a(1,:) = [1;3];
146 %! assert (a, [1,3]);
147
148 %!test
149 %! a(:,1) = [1;3];
150 %! assert (a, [1;3]);
151
152 %!test
153 %! a = [1,2;3,4];
154 %! b (1,:,:) = a;
155 %! assert (b, reshape (a, [1,2,2]));
156
157 %!test
158 %! a(1,1:4,2) = reshape (1:4, [1,1,4]);
159 %! b(:,:,2) = 1:4;
160 %! assert (a, b);
161
162 %!test
163 %! a(:,:,:) = 1:4;
164 %! assert (a, [1:4]);
165
166 %!test
167 %! a(:,:,1) = 1:4;;
168 %! assert (a, [1:4]);
169
170 %!test
171 %! a(:,:,1) = [1:4]';
172 %! assert (a, [1:4]');
173
174 %!test
175 %! a(:,:,1) = reshape (1:4,[1,1,4]);
176 %! assert (a, [1:4]');
177
178 %!test
179 %! a(:,1,:) = 1:4;
180 %! assert (a, reshape (1:4,[1,1,4]));
181
182 %!test
183 %! a(:,1,:) = [1:4]';
184 %! assert (a, [1:4]');
185
186 %!test
187 %! a(:,1,:) = reshape (1:4,[1,1,4]);;
188 %! assert (a, [1:4]');
189
190 %!test
191 %! a(1,:,:) = 1:4;
192 %! assert (a, reshape (1:4,[1,1,4]));
193
194 %!test
195 %! a(1,:,:) = [1:4]';
196 %! assert (a, [1:4]);
197
198 %!test
199 %! a(1,:,:) = reshape (1:4,[1,1,4]);
200 %! assert (a, [1:4]);
201
202 %!test
203 %! a(1,:,:,:) = reshape (1:4,[1,1,4]);
204 %! assert (a, reshape (1:4,[1,1,1,4]));
205
206 %!error (a(1:2,1:2) = 1:4)
207
208 %!shared x
209 %! x = 1:5;
210 %!error <attempted to use a complex scalar as an index> x(i)
211 %!error <attempted to use a complex scalar as an index> x(j)
212 %!error <attempted to use a complex scalar as an index> x(1+i)