Mercurial > octave-nkf
annotate test/test_prefer.m @ 10843:229675bb7647 ss-3-3-52
version is now 3.3.52
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 01 Aug 2010 11:49:45 -0400 |
parents | f5b51f54f44e |
children | fd0a3ac60b0e |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2006, 2007, 2008, 2009 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/prefer/prefer-1.m |
20 %!test | |
21 %! m = [3 2]; | |
22 %! assert(all (m == (3:-1:2))); | |
23 | |
24 %% test/octave.test/prefer/prefer-2.m | |
25 %!test | |
26 %! m = [3, | |
27 %! 2]; | |
28 %! assert(all (m == (3:-1:2)')); | |
29 | |
30 %% test/octave.test/prefer/prefer-3.m | |
31 %!test | |
32 %! a = 2; | |
33 %! assert([a - 1],1); | |
34 | |
35 %% test/octave.test/prefer/prefer-4.m | |
36 %!test | |
37 %! m = [3,2]; | |
38 %! fail("[m ']"); | |
39 | |
40 %% test/octave.test/prefer/prefer-5.m | |
41 %!assert(all ([3 2] == (3:-1:2))); | |
42 | |
43 %% test/octave.test/prefer/prefer-6.m | |
44 %!assert(all ([3, 2] == (3:-1:2))); | |
45 | |
46 %% test/octave.test/prefer/prefer-7.m | |
47 %!test | |
48 %! m = [3,2]; | |
49 %! assert(all ([m (1)] == (3:-1:1))); | |
50 | |
51 %% test/octave.test/prefer/prefer-8.m | |
52 %!test | |
53 %! m = [3,2]; | |
54 %! assert([m(1)],3); | |
55 | |
56 %% test/octave.test/prefer/prefer-9.m | |
57 %!test | |
58 %! m = [3,2]; | |
59 %! assert(all ([m (1)] == (3:-1:1))); | |
60 | |
61 %% test/octave.test/prefer/prefer-10.m | |
62 %!test | |
63 %! a = 2; | |
64 %! assert([a- 1],1); | |
65 | |
66 %% test/octave.test/prefer/prefer-11.m | |
67 %!test | |
68 %! a = 1; | |
69 %! assert(all ([a -1] == (1:-2:-1))); | |
70 | |
71 %% test/octave.test/prefer/prefer-12.m | |
72 %!test | |
5781 | 73 %! wsn = warning ("query", "Octave:str-to-num"); |
74 %! warning ("off", "Octave:str-to-num"); | |
5590 | 75 %! assert("d" + 0,100); |
5781 | 76 %! warning (wsn.state, "Octave:str-to-num"); |
5590 | 77 |
78 %% test/octave.test/prefer/prefer-13.m | |
79 %!test | |
5781 | 80 %! wsn = warning ("query", "Octave:str-to-num"); |
81 %! warning ("on", "Octave:str-to-num"); | |
5590 | 82 %! fail("'d' + 0","warning"); |
5781 | 83 %! warning (wsn.state, "Octave:str-to-num"); |
5590 | 84 |
85 %% test/octave.test/prefer/prefer-14.m | |
86 %!test | |
5781 | 87 %! wir = warning ("query", "Ocave:imag-to-real"); |
88 %! warning ("off", "Ocave:imag-to-real"); | |
5590 | 89 %! assert(eye (1+i),1); |
5781 | 90 %! warning (wir.state, "Ocave:imag-to-real"); |
5590 | 91 |
92 %% test/octave.test/prefer/prefer-15.m | |
93 %!test | |
5781 | 94 %! wir = warning ("query", "Ocave:imag-to-real"); |
95 %! warning ("on", "Ocave:imag-to-real"); | |
5590 | 96 %! fail("eye (1+i)","warning"); |
5781 | 97 %! warning (wir.state, "Ocave:imag-to-real"); |
5590 | 98 |
99 %% test/octave.test/prefer/prefer-17.m | |
100 %!test | |
5781 | 101 %! wrre = warning ("query", "Octave:resize-on-range-error"); |
102 %! warning ("off", "Octave:resize-on-range-error"); | |
5590 | 103 %! clear a; |
104 %! a(2) = 1; a(3) = 2; | |
105 %! assert(all (a == [0,1,2])); | |
5781 | 106 %! warning (wrre.state, "Octave:resize-on-range-error"); |
5590 | 107 |
108 %% test/octave.test/prefer/prefer-18.m | |
109 %!test | |
110 %! clear a; | |
111 %! a(1) = 1; a(2) = 2; | |
112 %! assert(all (a == [1,2])); | |
113 | |
5775 | 114 %% FIXME How the hell do I test this one in test/assert |
5590 | 115 %% test/octave.test/prefer/prefer-19.m |
116 %!#test | |
5794 | 117 %! pid = print_answer_id_name (); |
118 %! print_answer_id_name (0); | |
5590 | 119 %! a = 1 |
5794 | 120 %! print_answer_id_name (pid); |
5590 | 121 |
5775 | 122 %% FIXME How the hell do I test this one in test/assert |
5590 | 123 %% test/octave.test/prefer/prefer-20.m |
124 %!#test | |
5794 | 125 %! pid = print_answer_id_name (); |
126 %! print_answer_id_name (1); | |
5590 | 127 %! a = 1 |
5794 | 128 %! print_answer_id_name (pid); |
5590 | 129 |
130 %% test/octave.test/prefer/prefer-21.m | |
131 %!test | |
5794 | 132 %! ped = print_empty_dimensions (); |
133 %! print_empty_dimensions (0); | |
5590 | 134 %! a = cell (1, 1); |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8583
diff
changeset
|
135 %! b = type ("-q", "a"); |
8583
27b2db6ff0d7
test/test_prefer.m: update test to reflect new API of the 'type' function.
sh@sh-t400
parents:
8281
diff
changeset
|
136 %! assert (!isempty (findstr (b{1}, "[]"))); |
27b2db6ff0d7
test/test_prefer.m: update test to reflect new API of the 'type' function.
sh@sh-t400
parents:
8281
diff
changeset
|
137 %! assert (isempty (findstr (b{1} ,"[](0x0)"))); |
5794 | 138 %! print_empty_dimensions (ped); |
5590 | 139 |
140 %% test/octave.test/prefer/prefer-22.m | |
141 %!test | |
5794 | 142 %! ped = print_empty_dimensions (); |
143 %! print_empty_dimensions (1); | |
5590 | 144 %! a = cell (1, 1); |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8583
diff
changeset
|
145 %! b = type ("-q", "a"); |
8583
27b2db6ff0d7
test/test_prefer.m: update test to reflect new API of the 'type' function.
sh@sh-t400
parents:
8281
diff
changeset
|
146 %! assert (!isempty (findstr (b{1}, "[](0x0)"))); |
5794 | 147 %! print_empty_dimensions (ped); |
5590 | 148 |
149 %% test/octave.test/prefer/prefer-23.m | |
150 %!assert(all (size (inv ([])) == [0, 0])); | |
151 | |
152 %% test/octave.test/prefer/prefer-24.m | |
153 %!assert(all (svd ([]) == zeros (0, 1))); | |
154 | |
155 %% test/octave.test/prefer/prefer-27.m | |
156 %!test | |
5794 | 157 %! sp = save_precision (); |
158 %! save_precision (1); | |
5590 | 159 %! x = pi; |
160 %! nm = tmpnam(); | |
161 %! save("-text",nm,"x"); | |
162 %! clear x; | |
163 %! load(nm); | |
164 %! unlink(nm); | |
165 %! assert(x,3); | |
5794 | 166 %! save_precision (sp); |
5590 | 167 |
168 %% test/octave.test/prefer/prefer-28.m | |
169 %!test | |
5794 | 170 %! sp = save_precision (); |
171 %! save_precision (5); | |
5590 | 172 %! x = pi; |
173 %! nm = tmpnam(); | |
174 %! save("-text",nm,"x"); | |
175 %! clear x; | |
176 %! load(nm); | |
177 %! unlink(nm); | |
178 %! assert(x,3.1416); | |
5794 | 179 %! save_precision (sp); |
5590 | 180 |
5775 | 181 %% FIXME Same problem as above!!! |
5590 | 182 %% test/octave.test/prefer/prefer-29.m |
183 %!function f () | |
184 %! 1 | |
185 %!#test | |
5794 | 186 %! sf = silent_functions (); |
187 %! silent_functions (0); | |
5590 | 188 %! f |
189 %! assert(??); | |
5794 | 190 %! silent_functions (sf); |
5590 | 191 |
5775 | 192 %% FIXME Same problem as above!!! |
5590 | 193 %% test/octave.test/prefer/prefer-30.m |
194 %!function f () | |
195 %! 1 | |
196 %!#test | |
5794 | 197 %! sf = silent_functions (); |
198 %! silent_functions (1); | |
5590 | 199 %! f |
200 %! assert(??); | |
5794 | 201 %! silent_functions (sf); |
5590 | 202 |
203 %% test/octave.test/prefer/prefer-32.m | |
204 %!test | |
5781 | 205 %! wndz = warning ("query", "Octave:neg-dim-as-zero"); |
206 %! warning ("on", "Octave:neg-dim-as-zero"); | |
5590 | 207 %! fail("eye (-1) == []","warning"); |
5781 | 208 %! warning (wndz.state, "Octave:neg-dim-as-zero"); |
5590 | 209 |
210 %% test/octave.test/prefer/prefer-33.m | |
211 %!test | |
5781 | 212 %! wndz = warning ("query", "Octave:neg-dim-as-zero"); |
213 %! warning ("off", "Octave:neg-dim-as-zero"); | |
5590 | 214 %! assert(all (size (eye (-1)) == [0, 0])); |
5781 | 215 %! warning (wndz.state, "Octave:neg-dim-as-zero"); |
5590 | 216 |
217 %% test/octave.test/prefer/prefer-34.m | |
218 %!test | |
5781 | 219 %! watv = warning ("query", "Octave:assign-as-truth-value"); |
220 %! warning ("off", "Octave:assign-as-truth-value"); | |
5590 | 221 %! if (x = 1) 1; endif |
5781 | 222 %! warning (watv.state, "Octave:assign-as-truth-value"); |
5590 | 223 |
224 %% test/octave.test/prefer/prefer-35.m | |
225 %!test | |
5781 | 226 %! watv = warning ("query", "Octave:assign-as-truth-value"); |
227 %! warning ("on", "Octave:assign-as-truth-value"); | |
5590 | 228 %! fail("if (x = 1) 1; endif","warning"); |
5781 | 229 %! warning (watv.state, "Octave:assign-as-truth-value"); |
5590 | 230 |
231 %% test/octave.test/prefer/prefer-38.m | |
232 %!test | |
5781 | 233 %! wdbz = warning ("query", "Octave:divide-by-zero"); |
234 %! warning ("off", "Octave:divide-by-zero"); | |
5590 | 235 %! assert(isinf (1/0)); |
5781 | 236 %! warning (wdbz.state, "Octave:divide-by-zero"); |
5590 | 237 |
238 %% test/octave.test/prefer/prefer-39.m | |
239 %!test | |
5781 | 240 %! wdbz = warning ("query", "Octave:divide-by-zero"); |
241 %! warning ("on", "Octave:divide-by-zero"); | |
5590 | 242 %! a = 1; |
243 %! b = 0; | |
244 %! fail("isinf (a/b);","warning") | |
5781 | 245 %! warning (wdbz.state, "Octave:divide-by-zero"); |
5590 | 246 |