Mercurial > hg > octave-nkf
annotate test/test_string.m @ 12541:dd2c70b30f28
Add tests for ifftshift.m
author | Robert T. Short <octave@phaselockedsystems.com.com> |
---|---|
date | Sat, 26 Mar 2011 06:50:12 -0700 |
parents | fd0a3ac60b0e |
children |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2006-2011 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/string/str-esc-1.m |
20 %!test | |
21 %! x = 7; | |
22 %! if (strcmp ("\a", setstr (x))) | |
23 %! printf_assert ("ok\n"); | |
24 %! endif | |
25 %! assert(prog_output_assert("ok")); | |
26 | |
27 %% test/octave.test/string/str-esc-2.m | |
28 %!test | |
29 %! x = 8; | |
30 %! if (strcmp ("\b", setstr (x))) | |
31 %! printf_assert ("ok\n"); | |
32 %! endif | |
33 %! assert(prog_output_assert("ok")); | |
34 | |
35 %% test/octave.test/string/str-esc-3.m | |
36 %!test | |
37 %! x = 12; | |
38 %! if (strcmp ("\f", setstr (x))) | |
39 %! printf_assert ("ok\n"); | |
40 %! endif | |
41 %! assert(prog_output_assert("ok")); | |
42 | |
43 %% test/octave.test/string/str-esc-4.m | |
44 %!test | |
45 %! x = 10; | |
46 %! if (strcmp ("\n", setstr (x))) | |
47 %! printf_assert ("ok\n"); | |
48 %! endif | |
49 %! assert(prog_output_assert("ok")); | |
50 | |
51 %% test/octave.test/string/str-esc-5.m | |
52 %!test | |
53 %! x = 13; | |
54 %! if (strcmp ("\r", setstr (x))) | |
55 %! printf_assert ("ok\n"); | |
56 %! endif | |
57 %! assert(prog_output_assert("ok")); | |
58 | |
59 %% test/octave.test/string/str-esc-6.m | |
60 %!test | |
61 %! x = 9; | |
62 %! if (strcmp ("\t", setstr (x))) | |
63 %! printf_assert ("ok\n"); | |
64 %! endif | |
65 %! assert(prog_output_assert("ok")); | |
66 | |
67 %% test/octave.test/string/str-esc-7.m | |
68 %!test | |
69 %! x = 11; | |
70 %! if (strcmp ("\v", setstr (x))) | |
71 %! printf_assert ("ok\n"); | |
72 %! endif | |
73 %! assert(prog_output_assert("ok")); | |
74 | |
75 %% test/octave.test/string/str-esc-8.m | |
76 %!test | |
77 %! x = 92; | |
78 %! if (strcmp ("\\", setstr (x))) | |
79 %! printf_assert ("ok\n"); | |
80 %! endif | |
81 %! assert(prog_output_assert("ok")); | |
82 | |
83 %% test/octave.test/string/str-esc-9.m | |
84 %!test | |
85 %! x = 39; | |
86 %! if (strcmp ("\'", setstr (x))) | |
87 %! printf_assert ("ok\n"); | |
88 %! endif | |
89 %! assert(prog_output_assert("ok")); | |
90 | |
91 %% test/octave.test/string/str-esc-10.m | |
92 %!test | |
93 %! x = 34; | |
94 %! if (strcmp ("\"", setstr (x))) | |
95 %! printf_assert ("ok\n"); | |
96 %! endif | |
97 %! assert(prog_output_assert("ok")); | |
98 | |
99 %% test/octave.test/string/str-esc-11.m | |
100 %!test | |
101 %! x = 120; | |
102 %! fail('strcmp ("\x", setstr (x))',"warning",".*unrecognized escape sequence.*"); | |
103 | |
104 %% test/octave.test/string/str-esc-12.m | |
105 %!test | |
106 %! x = [7, 8, 12, 10, 13, 9, 11, 92, 39, 34]; | |
107 %! if (strcmp ("\a\b\f\n\r\t\v\\\'\"", setstr (x))) | |
108 %! printf_assert ("ok\n"); | |
109 %! endif | |
110 %! assert(prog_output_assert("ok")); | |
111 | |
5775 | 112 %% FIXME |
5590 | 113 %% Why do the next two tests fail? |
114 %% test/octave.test/string/string_fill_char-1.m | |
115 %!#test | |
116 %! sfc = string_fill_char; | |
117 %! string_fill_char = "X"; | |
118 %! str = ["these"; "are"; "strings"]; | |
119 %! assert(str,["theseXX"; "areXXXX"; "strings"]); | |
120 %! string_fill_char = sfc; | |
121 | |
122 %% test/octave.test/string/string_fill_char-2.m | |
123 %!#test | |
124 %! sfc = string_fill_char; | |
125 %! string_fill_char = " "; | |
126 %! str = ["these"; "are"; "strings"]; | |
127 %! assert(str,["these "; "are "; "strings"]); | |
128 %! string_fill_char = sfc; | |
129 | |
130 %% test/octave.test/string/ischar-1.m | |
131 %!assert(!(ischar (1))); | |
132 | |
133 %% test/octave.test/string/ischar-2.m | |
134 %!assert(!(ischar ([1, 2]))); | |
135 | |
136 %% test/octave.test/string/ischar-3.m | |
137 %!assert(!(ischar ([]))); | |
138 | |
139 %% test/octave.test/string/ischar-4.m | |
140 %!assert(!(ischar ([1, 2; 3, 4]))); | |
141 | |
142 %% test/octave.test/string/ischar-5.m | |
143 %!assert(ischar ("")); | |
144 | |
145 %% test/octave.test/string/ischar-6.m | |
146 %!assert(ischar ("t")); | |
147 | |
148 %% test/octave.test/string/ischar-7.m | |
149 %!assert(ischar ("test")); | |
150 | |
151 %% test/octave.test/string/ischar-8.m | |
152 %!assert(ischar (["test"; "ing"])); | |
153 | |
154 %% test/octave.test/string/ischar-9.m | |
155 %!test | |
156 %! s.a = "test"; | |
157 %! assert(!(ischar (s))); | |
158 | |
159 %% test/octave.test/string/ischar-10.m | |
5751 | 160 %!error <Invalid call to ischar.*> ischar (); |
5590 | 161 |
162 %% test/octave.test/string/ischar-11.m | |
5751 | 163 %!error <Invalid call to ischar.*> ischar ("test", 1); |
5590 | 164 |
165 | |
166 %% test/octave.test/string/char-1.m | |
167 %!assert(strcmp (char ([65, 83, 67, 73, 73]), "ASCII")); | |
168 | |
169 %% test/octave.test/string/char-2.m | |
5751 | 170 %!error <Invalid call to char.*> char (); |
5590 | 171 |
172 %% test/octave.test/string/char-3.m | |
173 %!test | |
174 %! x = char ("foo", "bar", "foobar"); | |
175 %! assert((strcmp (x(1,:), "foo ") | |
176 %! && strcmp (x(2,:), "bar ") | |
177 %! && strcmp (x(3,:), "foobar"))); | |
178 | |
179 | |
180 %% test/octave.test/string/strcmp-1.m | |
181 %!assert(strcmp ("foobar", "foobar") && strcmp ("fooba", "foobar") == 0); | |
182 | |
183 %% test/octave.test/string/strcmp-2.m | |
5751 | 184 %!error <Invalid call to strcmp.*> strcmp (); |
5590 | 185 |
186 %% test/octave.test/string/strcmp-3.m | |
5751 | 187 %!error <Invalid call to strcmp.*> strcmp ("foo", "bar", 3); |
5590 | 188 |
189 | |
190 | |
191 %% test/octave.test/string/undo_string_escapes-1.m | |
192 %!assert(strcmp (undo_string_escapes ("abc\a\b\n\r\t\v\f123"), | |
193 %! "abc\\a\\b\\n\\r\\t\\v\\f123")); | |
194 | |
195 %% test/octave.test/string/undo_string_escapes-2.m | |
5751 | 196 %!error <Invalid call to undo_string_escapes.*> undo_string_escapes (); |
5590 | 197 |
198 %% test/octave.test/string/undo_string_escapes-3.m | |
5751 | 199 %!error <Invalid call to undo_string_escapes.*> undo_string_escapes ("string", 2); |
5590 | 200 |
201 %% test/octave.test/string/toascii-1.m | |
202 %!test | |
203 %! charset = setstr (0:127); | |
204 %! | |
205 %! result = 0:127; | |
206 %! | |
207 %! assert(all (toascii (charset) == result)); | |
208 | |
209 %% test/octave.test/string/toascii-3.m | |
210 %!error toascii (1, 2); | |
211 | |
212 %% test/octave.test/string/toascii-3.m | |
213 %!error toascii (1, 2); | |
214 | |
215 %% test/octave.test/string/tolower-1.m | |
216 %!test | |
217 %! charset = setstr (0:127); | |
218 %! | |
219 %! result = charset; | |
220 %! | |
221 %! result ((toascii("A"):toascii("Z"))+1) \ | |
222 %! = result ((toascii("a"):toascii("z"))+1); | |
223 %! | |
224 %! assert(all (tolower (charset) == result)); | |
225 | |
226 %% test/octave.test/string/tolower-3.m | |
227 %!error tolower (1, 2); | |
228 | |
229 %% test/octave.test/string/tolower-3.m | |
230 %!error tolower (1, 2); | |
231 | |
232 %% test/octave.test/string/toupper-1.m | |
233 %!test | |
234 %! charset = setstr (0:127); | |
235 %! | |
236 %! result = charset; | |
237 %! | |
238 %! result ((toascii("a"):toascii("z"))+1) \ | |
239 %! = result ((toascii("A"):toascii("Z"))+1); | |
240 %! | |
241 %! assert(all (toupper (charset) == result)); | |
242 | |
243 %% test/octave.test/string/toupper-3.m | |
244 %!error toupper (1, 2); | |
245 | |
246 %% test/octave.test/string/toupper-3.m | |
247 %!error toupper (1, 2); | |
248 | |
249 %% test/octave.test/string/isalnum-1.m | |
250 %!test | |
251 %! charset = setstr (0:127); | |
252 %! | |
253 %! result = zeros (1, 128); | |
254 %! | |
255 %! result ((toascii("A"):toascii("Z"))+1) = 1; | |
256 %! result ((toascii("0"):toascii("9"))+1) = 1; | |
257 %! result ((toascii("a"):toascii("z"))+1) = 1; | |
258 %! | |
259 %! assert(all (isalnum (charset) == result)); | |
260 | |
261 %% test/octave.test/string/isalnum-2.m | |
262 %!error isalnum (1, 2); | |
263 | |
264 %% test/octave.test/string/isalnum-3.m | |
265 %!error isalnum (); | |
266 | |
267 %% test/octave.test/string/isalpha-1.m | |
268 %!test | |
269 %! charset = setstr (0:127); | |
270 %! | |
271 %! result = zeros (1, 128); | |
272 %! | |
273 %! result ((toascii("A"):toascii("Z"))+1) = 1; | |
274 %! result ((toascii("a"):toascii("z"))+1) = 1; | |
275 %! | |
276 %! assert(all (isalpha (charset) == result)); | |
277 | |
278 %% test/octave.test/string/isalpha-2.m | |
279 %!error isalpha (1, 2); | |
280 | |
281 %% test/octave.test/string/isalpha-3.m | |
282 %!error isalpha (); | |
283 | |
284 %% test/octave.test/string/isascii-1.m | |
285 %!test | |
286 %! charset = setstr (0:127); | |
287 %! | |
288 %! result = ones (1, 128); | |
289 %! | |
290 %! assert(all (isascii (charset) == result)); | |
291 | |
292 %% test/octave.test/string/isascii-2.m | |
293 %!error isascii (1, 2); | |
294 | |
295 %% test/octave.test/string/isascii-3.m | |
296 %!error isascii (); | |
297 | |
298 %% test/octave.test/string/iscntrl-1.m | |
299 %!test | |
300 %! charset = setstr (0:127); | |
301 %! | |
302 %! result = zeros (1, 128); | |
303 %! | |
304 %! result (1:32) = 1; | |
305 %! result (128) = 1; | |
306 %! | |
307 %! assert(all (iscntrl (charset) == result)); | |
308 | |
309 %% test/octave.test/string/iscntrl-2.m | |
310 %!error iscntrl (1, 2); | |
311 | |
312 %% test/octave.test/string/iscntrl-3.m | |
313 %!error iscntrl (); | |
314 | |
315 %% test/octave.test/string/isdigit-1.m | |
316 %!test | |
317 %! charset = setstr (0:127); | |
318 %! | |
319 %! result = zeros (1, 128); | |
320 %! | |
321 %! result ((toascii("0"):toascii("9"))+1) = 1; | |
322 %! | |
323 %! assert(all (isdigit (charset) == result)); | |
324 | |
325 %% test/octave.test/string/isdigit-2.m | |
326 %!error isdigit (1, 2); | |
327 | |
328 %% test/octave.test/string/isdigit-3.m | |
329 %!error isdigit (); | |
330 | |
331 %% test/octave.test/string/isgraph-1.m | |
332 %!test | |
333 %! charset = setstr (0:127); | |
334 %! | |
335 %! result = zeros (1, 128); | |
336 %! | |
337 %! result (34:127) = 1; | |
338 %! | |
339 %! assert(all (isgraph (charset) == result)); | |
340 | |
341 %% test/octave.test/string/isgraph-2.m | |
342 %!error isgraph (1, 2); | |
343 | |
344 %% test/octave.test/string/isgraph-3.m | |
345 %!error isgraph (); | |
346 | |
347 %% test/octave.test/string/islower-1.m | |
348 %!test | |
349 %! charset = setstr (0:127); | |
350 %! | |
351 %! result = zeros (1, 128); | |
352 %! | |
353 %! result ((toascii("a"):toascii("z"))+1) = 1; | |
354 %! | |
355 %! assert(all (islower (charset) == result)); | |
356 | |
357 %% test/octave.test/string/islower-2.m | |
358 %!error islower (1, 2); | |
359 | |
360 %% test/octave.test/string/islower-3.m | |
361 %!error islower (); | |
362 | |
363 %% test/octave.test/string/isprint-1.m | |
364 %!test | |
365 %! charset = setstr (0:127); | |
366 %! | |
367 %! result = zeros (1, 128); | |
368 %! | |
369 %! result (33:127) = 1; | |
7706
30564b8b19f5
Fix various tests under Win32.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7411
diff
changeset
|
370 %! if (ispc () && ! isunix ()) |
30564b8b19f5
Fix various tests under Win32.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7411
diff
changeset
|
371 %! result(10) = 1; |
30564b8b19f5
Fix various tests under Win32.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7411
diff
changeset
|
372 %! endif |
5590 | 373 %! |
374 %! assert(all (isprint (charset) == result)); | |
375 | |
376 %% test/octave.test/string/isprint-2.m | |
377 %!error isprint (1, 2); | |
378 | |
379 %% test/octave.test/string/isprint-3.m | |
380 %!error isprint (); | |
381 | |
382 %% test/octave.test/string/ispunct-1.m | |
383 %!test | |
384 %! charset = setstr (0:127); | |
385 %! | |
386 %! result = zeros (1, 128); | |
387 %! | |
388 %! result (34:48) = 1; | |
389 %! result (59:65) = 1; | |
390 %! result (92:97) = 1; | |
391 %! result (124:127) = 1; | |
392 %! | |
393 %! assert(all (ispunct (charset) == result)); | |
394 | |
395 %% test/octave.test/string/ispunct-2.m | |
396 %!error ispunct (1, 2); | |
397 | |
398 %% test/octave.test/string/ispunct-3.m | |
399 %!error ispunct (); | |
400 | |
401 %% test/octave.test/string/isspace-1.m | |
402 %!test | |
403 %! charset = setstr (0:127); | |
404 %! | |
405 %! result = zeros (1, 128); | |
406 %! | |
407 %! result (toascii (" \f\n\r\t\v")+1) = 1; | |
408 %! | |
409 %! assert(all (isspace (charset) == result)); | |
410 | |
411 %% test/octave.test/string/isspace-2.m | |
412 %!error isspace (1, 2); | |
413 | |
414 %% test/octave.test/string/isspace-3.m | |
415 %!error isspace (); | |
416 | |
417 %% test/octave.test/string/isupper-1.m | |
418 %!test | |
419 %! charset = setstr (0:127); | |
420 %! | |
421 %! result = zeros (1, 128); | |
422 %! | |
423 %! result ((toascii("A"):toascii("Z"))+1) = 1; | |
424 %! | |
425 %! assert(all (isupper (charset) == result)); | |
426 | |
427 %% test/octave.test/string/isupper-2.m | |
428 %!error isupper (1, 2); | |
429 | |
430 %% test/octave.test/string/isupper-3.m | |
431 %!error isupper (); | |
432 | |
433 %% test/octave.test/string/isxdigit-1.m | |
434 %!test | |
435 %! charset = setstr (0:127); | |
436 %! | |
437 %! result = zeros (1, 128); | |
438 %! | |
439 %! result ((toascii("A"):toascii("F"))+1) = 1; | |
440 %! result ((toascii("0"):toascii("9"))+1) = 1; | |
441 %! result ((toascii("a"):toascii("f"))+1) = 1; | |
442 %! | |
443 %! assert(all (isxdigit (charset) == result)); | |
444 | |
445 %% test/octave.test/string/isxdigit-2.m | |
446 %!error isxdigit (1, 2); | |
447 | |
448 %% test/octave.test/string/isxdigit-3.m | |
449 %!error isxdigit (); | |
450 | |
9150
e716cafee800
Add tests for concatenation of strings with all-zero matrices
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
9112
diff
changeset
|
451 %% test concatenation with all zero matrices |
e716cafee800
Add tests for concatenation of strings with all-zero matrices
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
9112
diff
changeset
|
452 %!assert([ '' 65*ones(1,10) ], 'AAAAAAAAAA'); |
e716cafee800
Add tests for concatenation of strings with all-zero matrices
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
9112
diff
changeset
|
453 %!assert([ 65*ones(1,10) '' ], 'AAAAAAAAAA'); |
e716cafee800
Add tests for concatenation of strings with all-zero matrices
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
9112
diff
changeset
|
454 |