comparison test/test_func.m @ 14131:c3309e1ec50d stable

test: Use Octave coding and spacing conventions for fixed test scripts * build_bc_overload_tests.sh, build_bc_overloads_expected.m, build_sparse_tests.sh, test_args.m, test_contin.m, test_diag_perm.m, test_error.m, test_eval-catch.m, test_for.m, test_func.m, test_global.m, test_if.m, test_index.m, test_io.m, test_logical_index.m, test_null_assign.m, test_parser.m, test_prefer.m, test_range.m, test_recursion.m, test_return.m, test_slice.m, test_struct.m, test_switch.m, test_system.m, test_transpose.m, test_try.m, test_unwind.m, test_while.m: Use Octave coding and spacing conventions for fixed test scripts.
author Rik <octave@nomad.inbox5.com>
date Sun, 01 Jan 2012 20:04:52 -0800
parents fd0a3ac60b0e
children 72c96de7a403
comparison
equal deleted inserted replaced
14130:e13bfbc2c4c5 14131:c3309e1ec50d
21 ## preserve type. Even if the object is an empty matrix. This code is 21 ## preserve type. Even if the object is an empty matrix. This code is
22 ## not to check that the function itself returns teh correct result, 22 ## not to check that the function itself returns teh correct result,
23 ## just that the results are consistent for all types. 23 ## just that the results are consistent for all types.
24 24
25 %!function __fntestfunc__ (fn, mn, varargin) 25 %!function __fntestfunc__ (fn, mn, varargin)
26 %! typ = {'double', 'complex', 'logical', 'sparse', 'complex sparse', ... 26 %! typ = {"double", "complex", "logical", "sparse", "complex sparse", ...
27 %! 'logical sparse', 'int8', 'int16', 'int32', 'int64', 'uint8', ... 27 %! "logical sparse", "int8", "int16", "int32", "int64", "uint8", ...
28 %! 'uint16', 'uint32', 'uint64', 'char', 'cell', 'struct', ... 28 %! "uint16", "uint32", "uint64", "char", "cell", "struct", ...
29 %! 'single', 'single complex'}; 29 %! "single", "single complex"};
30 %! 30 %!
31 %! cmplx = [2, 5, 18]; 31 %! cmplx = [2, 5, 18];
32 %! nlogical = [3, 6]; 32 %! nlogical = [3, 6];
33 %! ninteger = [7, 8, 9, 10, 11, 12, 13, 14]; 33 %! ninteger = [7, 8, 9, 10, 11, 12, 13, 14];
34 %! nsparse = [4, 5, 6]; 34 %! nsparse = [4, 5, 6];
37 %! if (length (varargin) > 0 && iscell (varargin{1})) 37 %! if (length (varargin) > 0 && iscell (varargin{1}))
38 %! skip = varargin{1}; 38 %! skip = varargin{1};
39 %! varargin(1) = []; 39 %! varargin(1) = [];
40 %! endif 40 %! endif
41 %! 41 %!
42 %! for i = 1 : length(typ) 42 %! for i = 1 : length (typ)
43 %! if (any (strcmp (skip, typ {i}))) 43 %! if (any (strcmp (skip, typ {i})))
44 %! continue; 44 %! continue;
45 %! endif 45 %! endif
46 %! m = mn; 46 %! m = mn;
47 %! 47 %!
48 %! if (any (nsparse == i)) 48 %! if (any (nsparse == i))
49 %! if (ndims (m) > 2) 49 %! if (ndims (m) > 2)
50 %! sz = size (m); 50 %! sz = size (m);
51 %! m = reshape (m, [sz(1), prod(sz (2:end))]); 51 %! m = reshape (m, [sz(1), prod(sz(2:end))]);
52 %! endif 52 %! endif
53 %! if (any (cmplx == i)) 53 %! if (any (cmplx == i))
54 %! m = sparse ((1 + 1i) * m); 54 %! m = sparse ((1 + 1i) * m);
55 %! else 55 %! else
56 %! m = sparse (m); 56 %! m = sparse (m);
59 %! if (any (cmplx == i)) 59 %! if (any (cmplx == i))
60 %! m = (1 + 1i) * m; 60 %! m = (1 + 1i) * m;
61 %! endif 61 %! endif
62 %! endif 62 %! endif
63 %! if (any (nlogical == i)) 63 %! if (any (nlogical == i))
64 %! m = cast (m, 'logical'); 64 %! m = cast (m, "logical");
65 %! endif 65 %! endif
66 %! if (any (ninteger == i)) 66 %! if (any (ninteger == i))
67 %! m = cast (m, typ{i}); 67 %! m = cast (m, typ{i});
68 %! endif 68 %! endif
69 %! if (strcmp (typ{i}, 'cell')) 69 %! if (strcmp (typ{i}, "cell"))
70 %! m = num2cell (m); 70 %! m = num2cell (m);
71 %! elseif (strcmp (typ{i}, 'struct')) 71 %! elseif (strcmp (typ{i}, "struct"))
72 %! m = struct ('fld', num2cell (m)); 72 %! m = struct ("fld", num2cell (m));
73 %! endif 73 %! endif
74 %! 74 %!
75 %! y = feval (fn, m, varargin{:}); 75 %! y = feval (fn, m, varargin{:});
76 %! y2 = feval (fn, reshape (mn, size (m)), varargin{:}); 76 %! y2 = feval (fn, reshape (mn, size (m)), varargin{:});
77 %! if (!strcmp (class (y), class (m)) || 77 %! if (!strcmp (class (y), class (m)) ||
78 %! issparse (y) != issparse (m) || !size_equal (y, y2)) 78 %! issparse (y) != issparse (m) || !size_equal (y, y2))
79 %! error ('failed for type %s\n', typ{i}); 79 %! error ("failed for type %s\n", typ{i});
80 %! endif 80 %! endif
81 %! if (!(strcmp (typ{i}, 'cell') || strcmp (typ{i}, 'struct')) && 81 %! if (!(strcmp (typ{i}, "cell") || strcmp (typ{i}, "struct")) &&
82 %! any (vec (cast (real (y), 'double')) != 82 %! any (vec (cast (real (y), "double")) !=
83 %! vec (feval (fn , cast (real (m), 'double'), varargin{:})))) 83 %! vec (feval (fn , cast (real (m), "double"), varargin{:}))))
84 %! error ('failed for type %s\n', typ{i}); 84 %! error ("failed for type %s\n", typ{i});
85 %! endif 85 %! endif
86 %! endfor 86 %! endfor
87 %! endfunction 87 %!endfunction
88 88
89 %!shared m0, m1, m2, m3 89 %!shared m0, m1, m2, m3
90 %! m0 = [1:5]; 90 %! m0 = [1:5];
91 %! m1 = reshape ([1 : 30], [5, 6]); 91 %! m1 = reshape ([1 : 30], [5, 6]);
92 %! m2 = reshape ([1 : 30], [5, 1, 6]); 92 %! m2 = reshape ([1 : 30], [5, 1, 6]);
93 %! m3 = []; 93 %! m3 = [];
94 94
95 %!test 95 %!test
96 %! __fntestfunc__('triu', m1, {'struct'}); 96 %! __fntestfunc__("triu", m1, {"struct"});
97 %!test 97 %!test
98 %! __fntestfunc__ ('triu', m1, {'struct'}, -1); 98 %! __fntestfunc__ ("triu", m1, {"struct"}, -1);
99 %!test 99 %!test
100 %! __fntestfunc__ ('triu', m1, {'struct'}, 1); 100 %! __fntestfunc__ ("triu", m1, {"struct"}, 1);
101 %!test 101 %!test
102 %! __fntestfunc__('triu', m3, {'struct'}); 102 %! __fntestfunc__("triu", m3, {"struct"});
103 %!test 103 %!test
104 %! __fntestfunc__ ('tril', m1, {'struct'}); 104 %! __fntestfunc__ ("tril", m1, {"struct"});
105 %!test 105 %!test
106 %! __fntestfunc__ ('tril', m1, {'struct'}, -1); 106 %! __fntestfunc__ ("tril", m1, {"struct"}, -1);
107 %!test 107 %!test
108 %! __fntestfunc__ ('tril', m1, {'struct'}, 1); 108 %! __fntestfunc__ ("tril", m1, {"struct"}, 1);
109 %!test 109 %!test
110 %! __fntestfunc__('tril', m3, {'struct'}); 110 %! __fntestfunc__("tril", m3, {"struct"});
111 %!test 111 %!test
112 %! __fntestfunc__ ('squeeze', m2); 112 %! __fntestfunc__ ("squeeze", m2);
113 %!test 113 %!test
114 %! __fntestfunc__ ('squeeze', m3); 114 %! __fntestfunc__ ("squeeze", m3);
115 %!test 115 %!test
116 %! __fntestfunc__ ('permute', m1, [2, 1]); 116 %! __fntestfunc__ ("permute", m1, [2, 1]);
117 %!test 117 %!test
118 %! __fntestfunc__ ('permute', m2, {'sparse', 'logical sparse', 'complex sparse'}, [3, 1, 2]); 118 %! __fntestfunc__ ("permute", m2, {"sparse", "logical sparse", "complex sparse"}, [3, 1, 2]);
119 %!test 119 %!test
120 %! __fntestfunc__ ('permute', m3, [2, 1]); 120 %! __fntestfunc__ ("permute", m3, [2, 1]);
121 %!test 121 %!test
122 %! __fntestfunc__ ('ipermute', m1, [2, 1]); 122 %! __fntestfunc__ ("ipermute", m1, [2, 1]);
123 %!test 123 %!test
124 %! __fntestfunc__ ('ipermute', m2, {'sparse', 'logical sparse', 'complex sparse'}, [3, 1, 2]); 124 %! __fntestfunc__ ("ipermute", m2, {"sparse", "logical sparse", "complex sparse"}, [3, 1, 2]);
125 %!test 125 %!test
126 %! __fntestfunc__ ('ipermute', m3, [2, 1]); 126 %! __fntestfunc__ ("ipermute", m3, [2, 1]);
127 %!test 127 %!test
128 %! __fntestfunc__ ('shiftdim', m2, 1); 128 %! __fntestfunc__ ("shiftdim", m2, 1);
129 %!test 129 %!test
130 %! __fntestfunc__ ('shiftdim', m2, {'sparse', 'logical sparse', 'complex sparse'}, -1); 130 %! __fntestfunc__ ("shiftdim", m2, {"sparse", "logical sparse", "complex sparse"}, -1);
131 %!test 131 %!test
132 %! __fntestfunc__ ('shiftdim', m3, 1); 132 %! __fntestfunc__ ("shiftdim", m3, 1);
133 %!test 133 %!test
134 %! __fntestfunc__ ('circshift', m2, 1); 134 %! __fntestfunc__ ("circshift", m2, 1);
135 %!test 135 %!test
136 %! __fntestfunc__ ('circshift', m2, [1, -1]); 136 %! __fntestfunc__ ("circshift", m2, [1, -1]);
137 %!test 137 %!test
138 %! __fntestfunc__ ('circshift', m3, 1); 138 %! __fntestfunc__ ("circshift", m3, 1);
139 %!test 139 %!test
140 %! __fntestfunc__ ('reshape', m2, [6, 5]); 140 %! __fntestfunc__ ("reshape", m2, [6, 5]);
141 %!test 141 %!test
142 %! __fntestfunc__ ('reshape', m3, [1, 0]); 142 %! __fntestfunc__ ("reshape", m3, [1, 0]);
143 %!test 143 %!test
144 %! __fntestfunc__ ('diag', m0, {'struct'}); 144 %! __fntestfunc__ ("diag", m0, {"struct"});
145 %!test 145 %!test
146 %! __fntestfunc__ ('diag', m0, {'struct'}, 1); 146 %! __fntestfunc__ ("diag", m0, {"struct"}, 1);
147 %!test 147 %!test
148 %! __fntestfunc__ ('diag', m0, {'struct'}, -1); 148 %! __fntestfunc__ ("diag", m0, {"struct"}, -1);
149 %!test 149 %!test
150 %! __fntestfunc__ ('diag', m1, {'struct'}); 150 %! __fntestfunc__ ("diag", m1, {"struct"});
151 %!test 151 %!test
152 %! __fntestfunc__ ('diag', m1, {'struct'}, 1); 152 %! __fntestfunc__ ("diag", m1, {"struct"}, 1);
153 %!test 153 %!test
154 %! __fntestfunc__ ('diag', m1, {'struct'}, -1); 154 %! __fntestfunc__ ("diag", m1, {"struct"}, -1);
155 %!test 155 %!test
156 %! __fntestfunc__ ('diag', m3, {'struct'}); 156 %! __fntestfunc__ ("diag", m3, {"struct"});
157 %!test 157 %!test
158 %! __fntestfunc__ ('fliplr', m1); 158 %! __fntestfunc__ ("fliplr", m1);
159 %!test 159 %!test
160 %! __fntestfunc__ ('fliplr', m3); 160 %! __fntestfunc__ ("fliplr", m3);
161 %!test 161 %!test
162 %! __fntestfunc__ ('flipud', m1); 162 %! __fntestfunc__ ("flipud", m1);
163 %!test 163 %!test
164 %! __fntestfunc__ ('flipud', m3); 164 %! __fntestfunc__ ("flipud", m3);
165 %!test 165 %!test
166 %! __fntestfunc__ ('flipdim', m1, 2); 166 %! __fntestfunc__ ("flipdim", m1, 2);
167 %!test 167 %!test
168 %! __fntestfunc__ ('flipdim', m3, 2); 168 %! __fntestfunc__ ("flipdim", m3, 2);
169 %!test 169 %!test
170 %! __fntestfunc__ ('transpose', m1); 170 %! __fntestfunc__ ("transpose", m1);
171 %!test 171 %!test
172 %! __fntestfunc__ ('transpose', m3); 172 %! __fntestfunc__ ("transpose", m3);
173 %!test 173 %!test
174 %! __fntestfunc__ ('ctranspose', m1); 174 %! __fntestfunc__ ("ctranspose", m1);
175 %!test 175 %!test
176 %! __fntestfunc__ ('ctranspose', m3); 176 %! __fntestfunc__ ("ctranspose", m3);
177 %!test 177 %!test
178 %! __fntestfunc__ ('rot90', m1); 178 %! __fntestfunc__ ("rot90", m1);
179 %!test 179 %!test
180 %! __fntestfunc__ ('rot90', m1, 2); 180 %! __fntestfunc__ ("rot90", m1, 2);
181 %!test 181 %!test
182 %! __fntestfunc__ ('rot90', m1, -1); 182 %! __fntestfunc__ ("rot90", m1, -1);
183 %!test 183 %!test
184 %! __fntestfunc__ ('rot90', m3); 184 %! __fntestfunc__ ("rot90", m3);
185 %!test 185 %!test
186 %! __fntestfunc__ ('rotdim', m2, 1, [1, 2]); 186 %! __fntestfunc__ ("rotdim", m2, 1, [1, 2]);
187 %!test 187 %!test
188 %! __fntestfunc__ ('rotdim', m2, 2, [1, 2]); 188 %! __fntestfunc__ ("rotdim", m2, 2, [1, 2]);
189 %!test 189 %!test
190 %! __fntestfunc__ ('rotdim', m2, -1, [1, 2]); 190 %! __fntestfunc__ ("rotdim", m2, -1, [1, 2]);
191 %!test 191 %!test
192 %! __fntestfunc__ ('rotdim', m3, 1, [1, 2]); 192 %! __fntestfunc__ ("rotdim", m3, 1, [1, 2]);