Mercurial > hg > octave-nkf
changeset 14429:eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
* data.cc, defaults.cc, dirfns.cc, file-io.cc, graphics.cc, mappers.cc,
oct-map.cc, octave.cc, ov-base.cc, ov-bool-mat.cc, ov-cell.cc,
ov-fcn-handle.cc, ov-fcn-inline.cc, ov-flt-re-mat.cc, ov-int16.cc, ov-int32.cc,
ov-int64.cc, ov-int8.cc, ov-null-mat.cc, ov-oncleanup.cc, ov-range.cc,
ov-re-mat.cc, ov-struct.cc, ov-typeinfo.cc, ov-uint16.cc, ov-uint32.cc,
ov-uint64.cc, ov-uint8.cc, ov.cc, pr-output.cc, pt-binop.cc, pt-eval.cc,
pt-idx.cc, pt-mat.cc, sighandlers.cc, strfns.cc, symtab.cc, syscalls.cc,
sysdep.cc, toplev.cc, utils.cc, variables.cc: Update %!tests in src/ directory
with Octave coding conventions.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 04 Mar 2012 12:21:10 -0800 |
parents | 099bd779466c |
children | df5488e46dca |
files | src/data.cc src/defaults.cc src/dirfns.cc src/file-io.cc src/graphics.cc src/mappers.cc src/oct-map.cc src/octave.cc src/ov-base.cc src/ov-bool-mat.cc src/ov-cell.cc src/ov-fcn-handle.cc src/ov-fcn-inline.cc src/ov-flt-re-mat.cc src/ov-int16.cc src/ov-int32.cc src/ov-int64.cc src/ov-int8.cc src/ov-null-mat.cc src/ov-oncleanup.cc src/ov-range.cc src/ov-re-mat.cc src/ov-struct.cc src/ov-typeinfo.cc src/ov-uint16.cc src/ov-uint32.cc src/ov-uint64.cc src/ov-uint8.cc src/ov.cc src/pr-output.cc src/pt-binop.cc src/pt-eval.cc src/pt-idx.cc src/pt-mat.cc src/sighandlers.cc src/strfns.cc src/symtab.cc src/syscalls.cc src/sysdep.cc src/toplev.cc src/utils.cc src/variables.cc |
diffstat | 42 files changed, 1758 insertions(+), 1837 deletions(-) [+] |
line wrap: on
line diff
--- a/src/data.cc +++ b/src/data.cc @@ -132,27 +132,25 @@ } /* - %!test %! x = ones (3); %! x(1,1) = 0; -%! assert((all (all (rand (3) + 1) == [1, 1, 1]) == 1 -%! && all (all (x) == [0, 1, 1]) == 1 -%! && all (x, 1) == [0, 1, 1] -%! && all (x, 2) == [0; 1; 1])); +%! assert (all (all (rand (3) + 1) == [1, 1, 1]) == 1); +%! assert (all (all (x) == [0, 1, 1]) == 1); +%! assert (all (x, 1) == [0, 1, 1]); +%! assert (all (x, 2) == [0; 1; 1]); %!test -%! x = ones (3, 'single'); +%! x = ones (3, "single"); %! x(1,1) = 0; -%! assert((all (all (single (rand (3) + 1)) == [1, 1, 1]) == 1 -%! && all (all (x) == [0, 1, 1]) == 1 -%! && all (x, 1) == [0, 1, 1] -%! && all (x, 2) == [0; 1; 1])); - -%!error <Invalid call to all> all (); -%!error <Invalid call to all> all (1, 2, 3); - - */ +%! assert (all (all (single (rand (3) + 1)) == [1, 1, 1]) == 1); +%! assert (all (all (x) == [0, 1, 1]) == 1); +%! assert (all (x, 1) == [0, 1, 1]); +%! assert (all (x, 2) == [0; 1; 1]); + +%!error all () +%!error all (1, 2, 3) +*/ DEFUN (any, args, , "-*- texinfo -*-\n\ @@ -188,27 +186,25 @@ } /* - %!test %! x = zeros (3); %! x(3,3) = 1; -%! assert((all (any (x) == [0, 0, 1]) == 1 -%! && all (any (ones (3)) == [1, 1, 1]) == 1 -%! && any (x, 1) == [0, 0, 1] -%! && any (x, 2) == [0; 0; 1])); +%! assert (all (any (x) == [0, 0, 1]) == 1); +%! assert (all (any (ones (3)) == [1, 1, 1]) == 1); +%! assert (any (x, 1) == [0, 0, 1]); +%! assert (any (x, 2) == [0; 0; 1]); %!test -%! x = zeros (3,'single'); +%! x = zeros (3, "single"); %! x(3,3) = 1; -%! assert((all (any (x) == [0, 0, 1]) == 1 -%! && all (any (ones (3, 'single')) == [1, 1, 1]) == 1 -%! && any (x, 1) == [0, 0, 1] -%! && any (x, 2) == [0; 0; 1])); - -%!error <Invalid call to any> any (); -%!error <Invalid call to any> any (1, 2, 3); - - */ +%! assert (all (any (x) == [0, 0, 1]) == 1); +%! assert (all (any (ones (3, "single")) == [1, 1, 1]) == 1); +%! assert (any (x, 1) == [0, 0, 1]); +%! assert (any (x, 2) == [0; 0; 1]); + +%!error any () +%!error any (1, 2, 3) +*/ // These mapping functions may also be useful in other places, eh? @@ -283,19 +279,18 @@ %! v = [0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0]; %! y = [0, rt3, 1, rt3, -rt3, -1, -rt3, 0]; %! x = [1, 3, 1, 1, 1, 1, 3, 1]; -%! assert(atan2 (y, x), v, sqrt (eps)); +%! assert (atan2 (y, x), v, sqrt (eps)); %!test %! rt2 = sqrt (2); %! rt3 = sqrt (3); -%! v = single([0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0]); -%! y = single([0, rt3, 1, rt3, -rt3, -1, -rt3, 0]); -%! x = single([1, 3, 1, 1, 1, 1, 3, 1]); -%! assert(atan2 (y, x), v, sqrt (eps('single'))); - -%!error <Invalid call to atan2> atan2 (); -%!error <Invalid call to atan2> atan2 (1, 2, 3); - +%! v = single ([0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0]); +%! y = single ([0, rt3, 1, rt3, -rt3, -1, -rt3, 0]); +%! x = single ([1, 3, 1, 1, 1, 1, 3, 1]); +%! assert (atan2 (y, x), v, sqrt (eps ("single"))); + +%!error atan2 () +%!error atan2 (1, 2, 3) */ @@ -397,8 +392,8 @@ %!assert (size (hypot (rand (2, 3, 4), 1)), [2, 3, 4]) %!assert (size (hypot (1, rand (2, 3, 4))), [2, 3, 4]) %!assert (size (hypot (1, 2)), [1, 1]) -%!assert (hypot (1:10, 1:10), sqrt(2) * [1:10], 16*eps) -%!assert (hypot (single(1:10), single(1:10)), single(sqrt(2) * [1:10])); +%!assert (hypot (1:10, 1:10), sqrt (2) * [1:10], 16*eps) +%!assert (hypot (single (1:10), single (1:10)), single (sqrt (2) * [1:10])) */ template<typename T, typename ET> @@ -498,16 +493,16 @@ } /* -%!assert(log2 ([1/4, 1/2, 1, 2, 4]), [-2, -1, 0, 1, 2]); -%!assert(log2(Inf), Inf); -%!assert(isnan(log2(NaN))); -%!assert(log2(4*i), 2 + log2(1*i)); -%!assert(log2(complex(0,Inf)), Inf + log2(i)); +%!assert (log2 ([1/4, 1/2, 1, 2, 4]), [-2, -1, 0, 1, 2]) +%!assert (log2 (Inf), Inf) +%!assert (isnan (log2 (NaN))) +%!assert (log2 (4*i), 2 + log2 (1*i)) +%!assert (log2 (complex (0,Inf)), Inf + log2 (i)) %!test %! [f, e] = log2 ([0,-1; 2,-4; Inf,-Inf]); %! assert (f, [0,-0.5; 0.5,-0.5; Inf,-Inf]); -%! assert (e(1:2,:), [0,1;2,3]) +%! assert (e(1:2,:), [0,1;2,3]); %!test %! [f, e] = log2 (complex (zeros (3, 2), [0,-1; 2,-4; Inf,-Inf])); @@ -620,21 +615,21 @@ } /* - -%!assert(rem ([1, 2, 3; -1, -2, -3], 2), [1, 0, 1; -1, 0, -1]); -%!assert(rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3)),[1, 0, 1; -1, 0, -1]); -%!error rem (); -%!error rem (1, 2, 3); -%!error rem ([1, 2], [3, 4, 5]); -%!error rem (i, 1); -%!assert(rem (uint8([1, 2, 3; -1, -2, -3]), uint8 (2)), uint8([1, 0, 1; -1, 0, -1])); -%!assert(uint8(rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3))),uint8([1, 0, 1; -1, 0, -1])); -%!error rem (uint(8),int8(5)); -%!error rem (uint8([1, 2]), uint8([3, 4, 5])); - +%!assert (rem ([1, 2, 3; -1, -2, -3], 2), [1, 0, 1; -1, 0, -1]) +%!assert (rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3)),[1, 0, 1; -1, 0, -1]) +%!assert (rem (uint8 ([1, 2, 3; -1, -2, -3]), uint8 (2)), uint8 ([1, 0, 1; -1, 0, -1])) +%!assert (uint8 (rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3))),uint8 ([1, 0, 1; -1, 0, -1])) + +%!error rem (uint (8), int8 (5)) +%!error rem (uint8 ([1, 2]), uint8 ([3, 4, 5])) +%!error rem () +%!error rem (1, 2, 3) +%!error rem ([1, 2], [3, 4, 5]) +%!error rem (i, 1) */ /* + %!assert (size (fmod (zeros (0, 2), zeros (0, 2))), [0, 2]) %!assert (size (fmod (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4]) %!assert (size (fmod (rand (2, 3, 4), 1)), [2, 3, 4]) @@ -754,48 +749,48 @@ /* ## empty input test -%!assert (isempty(mod([], []))); +%!assert (isempty (mod ([], []))) ## x mod y, y != 0 tests -%!assert (mod(5, 3), 2); -%!assert (mod(-5, 3), 1); -%!assert (mod(0, 3), 0); -%!assert (mod([-5, 5, 0], [3, 3, 3]), [1, 2, 0]); -%!assert (mod([-5; 5; 0], [3; 3; 3]), [1; 2; 0]); -%!assert (mod([-5, 5; 0, 3], [3, 3 ; 3, 1]), [1, 2 ; 0, 0]); +%!assert (mod (5, 3), 2) +%!assert (mod (-5, 3), 1) +%!assert (mod (0, 3), 0) +%!assert (mod ([-5, 5, 0], [3, 3, 3]), [1, 2, 0]) +%!assert (mod ([-5; 5; 0], [3; 3; 3]), [1; 2; 0]) +%!assert (mod ([-5, 5; 0, 3], [3, 3 ; 3, 1]), [1, 2 ; 0, 0]) ## x mod 0 tests -%!assert (mod(5, 0), 5); -%!assert (mod(-5, 0), -5); -%!assert (mod([-5, 5, 0], [3, 0, 3]), [1, 5, 0]); -%!assert (mod([-5; 5; 0], [3; 0; 3]), [1; 5; 0]); -%!assert (mod([-5, 5; 0, 3], [3, 0 ; 3, 1]), [1, 5 ; 0, 0]); -%!assert (mod([-5, 5; 0, 3], [0, 0 ; 0, 0]), [-5, 5; 0, 3]); +%!assert (mod (5, 0), 5) +%!assert (mod (-5, 0), -5) +%!assert (mod ([-5, 5, 0], [3, 0, 3]), [1, 5, 0]) +%!assert (mod ([-5; 5; 0], [3; 0; 3]), [1; 5; 0]) +%!assert (mod ([-5, 5; 0, 3], [3, 0 ; 3, 1]), [1, 5 ; 0, 0]) +%!assert (mod ([-5, 5; 0, 3], [0, 0 ; 0, 0]), [-5, 5; 0, 3]) ## mixed scalar/matrix tests -%!assert (mod([-5, 5; 0, 3], 0), [-5, 5; 0, 3]); -%!assert (mod([-5, 5; 0, 3], 3), [1, 2; 0, 0]); -%!assert (mod(-5,[0,0; 0,0]), [-5, -5; -5, -5]); -%!assert (mod(-5,[3,0; 3,1]), [1, -5; 1, 0]); -%!assert (mod(-5,[3,2; 3,1]), [1, 1; 1, 0]); +%!assert (mod ([-5, 5; 0, 3], 0), [-5, 5; 0, 3]) +%!assert (mod ([-5, 5; 0, 3], 3), [1, 2; 0, 0]) +%!assert (mod (-5, [0,0; 0,0]), [-5, -5; -5, -5]) +%!assert (mod (-5, [3,0; 3,1]), [1, -5; 1, 0]) +%!assert (mod (-5, [3,2; 3,1]), [1, 1; 1, 0]) ## integer types -%!assert (mod(uint8(5),uint8(4)),uint8(1)) -%!assert (mod(uint8([1:5]),uint8(4)),uint8([1,2,3,0,1])) -%!assert (mod(uint8([1:5]),uint8(0)),uint8([1:5])) -%!error (mod(uint8(5),int8(4))) +%!assert (mod (uint8 (5), uint8 (4)), uint8 (1)) +%!assert (mod (uint8 ([1:5]), uint8 (4)), uint8 ([1,2,3,0,1])) +%!assert (mod (uint8 ([1:5]), uint8 (0)), uint8 ([1:5])) +%!error (mod (uint8 (5), int8 (4))) ## mixed integer/real types -%!assert (mod(uint8(5),4),uint8(1)) -%!assert (mod(5,uint8(4)),uint8(1)) -%!assert (mod(uint8([1:5]),4),uint8([1,2,3,0,1])) +%!assert (mod (uint8 (5), 4), uint8 (1)) +%!assert (mod (5, uint8 (4)), uint8 (1)) +%!assert (mod (uint8 ([1:5]), 4), uint8 ([1,2,3,0,1])) ## non-integer real numbers %!assert (mod (2.1, 0.1), 0) %!assert (mod (2.1, 0.2), 0.1, eps) */ -// FIXME Need to convert the reduction functions of this file for single precision +// FIXME: Need to convert the reduction functions of this file for single precision #define NATIVE_REDUCTION_1(FCN, TYPE, DIM) \ (arg.is_ ## TYPE ## _type ()) \ @@ -1068,26 +1063,24 @@ } /* - -%!assert (cumprod ([1, 2, 3]), [1, 2, 6]); -%!assert (cumprod ([-1; -2; -3]), [-1; 2; -6]); -%!assert (cumprod ([i, 2+i, -3+2i, 4]), [i, -1+2i, -1-8i, -4-32i]); -%!assert (cumprod ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [1, 2, 3; i, 4i, 9i; -1+i, -8+8i, -27+27i]); - -%!assert (cumprod (single([1, 2, 3])), single([1, 2, 6])); -%!assert (cumprod (single([-1; -2; -3])), single([-1; 2; -6])); -%!assert (cumprod (single([i, 2+i, -3+2i, 4])), single([i, -1+2i, -1-8i, -4-32i])); -%!assert (cumprod (single([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single([1, 2, 3; i, 4i, 9i; -1+i, -8+8i, -27+27i])); - -%!error <Invalid call to cumprod> cumprod (); - -%!assert (cumprod ([2, 3; 4, 5], 1), [2, 3; 8, 15]); -%!assert (cumprod ([2, 3; 4, 5], 2), [2, 6; 4, 20]); - -%!assert (cumprod (single([2, 3; 4, 5]), 1), single([2, 3; 8, 15])); -%!assert (cumprod (single([2, 3; 4, 5]), 2), single([2, 6; 4, 20])); - - */ +%!assert (cumprod ([1, 2, 3]), [1, 2, 6]) +%!assert (cumprod ([-1; -2; -3]), [-1; 2; -6]) +%!assert (cumprod ([i, 2+i, -3+2i, 4]), [i, -1+2i, -1-8i, -4-32i]) +%!assert (cumprod ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [1, 2, 3; i, 4i, 9i; -1+i, -8+8i, -27+27i]) + +%!assert (cumprod (single ([1, 2, 3])), single ([1, 2, 6])) +%!assert (cumprod (single ([-1; -2; -3])), single ([-1; 2; -6])) +%!assert (cumprod (single ([i, 2+i, -3+2i, 4])), single ([i, -1+2i, -1-8i, -4-32i])) +%!assert (cumprod (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single ([1, 2, 3; i, 4i, 9i; -1+i, -8+8i, -27+27i])) + +%!assert (cumprod ([2, 3; 4, 5], 1), [2, 3; 8, 15]) +%!assert (cumprod ([2, 3; 4, 5], 2), [2, 6; 4, 20]) + +%!assert (cumprod (single ([2, 3; 4, 5]), 1), single ([2, 3; 8, 15])) +%!assert (cumprod (single ([2, 3; 4, 5]), 2), single ([2, 6; 4, 20])) + +%!error cumprod () +*/ DEFUN (cumsum, args, , "-*- texinfo -*-\n\ @@ -1219,26 +1212,24 @@ } /* - -%!assert (cumsum ([1, 2, 3]), [1, 3, 6]); -%!assert (cumsum ([-1; -2; -3]), [-1; -3; -6]); -%!assert (cumsum ([i, 2+i, -3+2i, 4]), [i, 2+2i, -1+4i, 3+4i]); -%!assert (cumsum ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [1, 2, 3; 1+i, 2+2i, 3+3i; 2+2i, 4+4i, 6+6i]); - -%!assert (cumsum (single([1, 2, 3])), single([1, 3, 6])); -%!assert (cumsum (single([-1; -2; -3])), single([-1; -3; -6])); -%!assert (cumsum (single([i, 2+i, -3+2i, 4])), single([i, 2+2i, -1+4i, 3+4i])); -%!assert (cumsum (single([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single([1, 2, 3; 1+i, 2+2i, 3+3i; 2+2i, 4+4i, 6+6i])); - -%!error <Invalid call to cumsum> cumsum (); - -%!assert (cumsum ([1, 2; 3, 4], 1), [1, 2; 4, 6]); -%!assert (cumsum ([1, 2; 3, 4], 2), [1, 3; 3, 7]); - -%!assert (cumsum (single([1, 2; 3, 4]), 1), single([1, 2; 4, 6])); -%!assert (cumsum (single([1, 2; 3, 4]), 2), single([1, 3; 3, 7])); - - */ +%!assert (cumsum ([1, 2, 3]), [1, 3, 6]) +%!assert (cumsum ([-1; -2; -3]), [-1; -3; -6]) +%!assert (cumsum ([i, 2+i, -3+2i, 4]), [i, 2+2i, -1+4i, 3+4i]) +%!assert (cumsum ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [1, 2, 3; 1+i, 2+2i, 3+3i; 2+2i, 4+4i, 6+6i]) + +%!assert (cumsum (single ([1, 2, 3])), single ([1, 3, 6])) +%!assert (cumsum (single ([-1; -2; -3])), single ([-1; -3; -6])) +%!assert (cumsum (single ([i, 2+i, -3+2i, 4])), single ([i, 2+2i, -1+4i, 3+4i])) +%!assert (cumsum (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single ([1, 2, 3; 1+i, 2+2i, 3+3i; 2+2i, 4+4i, 6+6i])) + +%!assert (cumsum ([1, 2; 3, 4], 1), [1, 2; 4, 6]) +%!assert (cumsum ([1, 2; 3, 4], 2), [1, 3; 3, 7]) + +%!assert (cumsum (single ([1, 2; 3, 4]), 1), single ([1, 2; 4, 6])) +%!assert (cumsum (single ([1, 2; 3, 4]), 2), single ([1, 3; 3, 7])) + +%!error cumsum () +*/ DEFUN (diag, args, , "-*- texinfo -*-\n\ @@ -1308,46 +1299,44 @@ } /* - -%!assert(full (diag ([1; 2; 3])), [1, 0, 0; 0, 2, 0; 0, 0, 3]); -%!assert(diag ([1; 2; 3], 1), [0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]); -%!assert(diag ([1; 2; 3], 2), [0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0]); -%!assert(diag ([1; 2; 3],-1), [0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]); -%!assert(diag ([1; 2; 3],-2), [0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0]); - -%!assert(diag ([1, 0, 0; 0, 2, 0; 0, 0, 3]), [1; 2; 3]); -%!assert(diag ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0], 1), [1; 2; 3]); -%!assert(diag ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0], -1), [1; 2; 3]); -%!assert(diag (ones(1, 0), 2), zeros (2)); -%!assert(diag (1:3, 4, 2), [1, 0; 0, 2; 0, 0; 0, 0]); - -%!assert(full (diag (single([1; 2; 3]))), single([1, 0, 0; 0, 2, 0; 0, 0, 3])); -%!assert(diag (single([1; 2; 3]), 1), single([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])); -%!assert(diag (single([1; 2; 3]), 2), single([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0])); -%!assert(diag (single([1; 2; 3]),-1), single([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0])); -%!assert(diag (single([1; 2; 3]),-2), single([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0])); - -%!assert(diag (single([1, 0, 0; 0, 2, 0; 0, 0, 3])), single([1; 2; 3])); -%!assert(diag (single([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), single([1; 2; 3])); -%!assert(diag (single([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), single([1; 2; 3])); - -%!assert(diag (int8([1; 2; 3])), int8([1, 0, 0; 0, 2, 0; 0, 0, 3])); -%!assert(diag (int8([1; 2; 3]), 1), int8([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])); -%!assert(diag (int8([1; 2; 3]), 2), int8([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0])); -%!assert(diag (int8([1; 2; 3]),-1), int8([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0])); -%!assert(diag (int8([1; 2; 3]),-2), int8([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0])); - -%!assert(diag (int8([1, 0, 0; 0, 2, 0; 0, 0, 3])), int8([1; 2; 3])); -%!assert(diag (int8([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), int8([1; 2; 3])); -%!assert(diag (int8([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), int8([1; 2; 3])); - -%% Test input validation -%!error <Invalid call to diag> diag (); -%!error <Invalid call to diag> diag (1,2,3,4); -%!error diag (ones (2), 3, 3); -%!error diag (1:3, -4, 3); - - */ +%!assert (full (diag ([1; 2; 3])), [1, 0, 0; 0, 2, 0; 0, 0, 3]) +%!assert (diag ([1; 2; 3], 1), [0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]) +%!assert (diag ([1; 2; 3], 2), [0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0]) +%!assert (diag ([1; 2; 3],-1), [0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]) +%!assert (diag ([1; 2; 3],-2), [0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0]) + +%!assert (diag ([1, 0, 0; 0, 2, 0; 0, 0, 3]), [1; 2; 3]) +%!assert (diag ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0], 1), [1; 2; 3]) +%!assert (diag ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0], -1), [1; 2; 3]) +%!assert (diag (ones (1, 0), 2), zeros (2)) +%!assert (diag (1:3, 4, 2), [1, 0; 0, 2; 0, 0; 0, 0]) + +%!assert (full (diag (single ([1; 2; 3]))), single ([1, 0, 0; 0, 2, 0; 0, 0, 3])) +%!assert (diag (single ([1; 2; 3]), 1), single ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])) +%!assert (diag (single ([1; 2; 3]), 2), single ([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0])) +%!assert (diag (single ([1; 2; 3]),-1), single ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0])) +%!assert (diag (single ([1; 2; 3]),-2), single ([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0])) + +%!assert (diag (single ([1, 0, 0; 0, 2, 0; 0, 0, 3])), single ([1; 2; 3])) +%!assert (diag (single ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), single ([1; 2; 3])) +%!assert (diag (single ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), single ([1; 2; 3])) + +%!assert (diag (int8 ([1; 2; 3])), int8 ([1, 0, 0; 0, 2, 0; 0, 0, 3])) +%!assert (diag (int8 ([1; 2; 3]), 1), int8 ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])) +%!assert (diag (int8 ([1; 2; 3]), 2), int8 ([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0])) +%!assert (diag (int8 ([1; 2; 3]),-1), int8 ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0])) +%!assert (diag (int8 ([1; 2; 3]),-2), int8 ([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0])) + +%!assert (diag (int8 ([1, 0, 0; 0, 2, 0; 0, 0, 3])), int8 ([1; 2; 3])) +%!assert (diag (int8 ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), int8 ([1; 2; 3])) +%!assert (diag (int8 ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), int8 ([1; 2; 3])) + +## Test input validation +%!error diag () +%!error diag (1,2,3,4) +%!error diag (ones (2), 3, 3) +%!error diag (1:3, -4, 3) +*/ DEFUN (prod, args, , "-*- texinfo -*-\n\ @@ -1362,50 +1351,48 @@ } /* - -%!assert (prod ([1, 2, 3]), 6); -%!assert (prod ([-1; -2; -3]), -6); -%!assert (prod ([i, 2+i, -3+2i, 4]), -4 - 32i); -%!assert (prod ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [-1+i, -8+8i, -27+27i]); - -%!assert (prod (single([1, 2, 3])), single(6)); -%!assert (prod (single([-1; -2; -3])), single(-6)); -%!assert (prod (single([i, 2+i, -3+2i, 4])), single(-4 - 32i)); -%!assert (prod (single([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single([-1+i, -8+8i, -27+27i])); - -%!error <Invalid call to prod> prod (); - -%!assert (prod ([1, 2; 3, 4], 1), [3, 8]); -%!assert (prod ([1, 2; 3, 4], 2), [2; 12]); -%!assert (prod (zeros (1, 0)), 1); -%!assert (prod (zeros (1, 0), 1), zeros (1, 0)); -%!assert (prod (zeros (1, 0), 2), 1); -%!assert (prod (zeros (0, 1)), 1); -%!assert (prod (zeros (0, 1), 1), 1); -%!assert (prod (zeros (0, 1), 2), zeros (0, 1)); -%!assert (prod (zeros (2, 0)), zeros (1, 0)); -%!assert (prod (zeros (2, 0), 1), zeros (1, 0)); -%!assert (prod (zeros (2, 0), 2), [1; 1]); -%!assert (prod (zeros (0, 2)), [1, 1]); -%!assert (prod (zeros (0, 2), 1), [1, 1]); -%!assert (prod (zeros (0, 2), 2), zeros(0, 1)); - -%!assert (prod (single([1, 2; 3, 4]), 1), single([3, 8])); -%!assert (prod (single([1, 2; 3, 4]), 2), single([2; 12])); -%!assert (prod (zeros (1, 0, 'single')), single(1)); -%!assert (prod (zeros (1, 0, 'single'), 1), zeros (1, 0, 'single')); -%!assert (prod (zeros (1, 0, 'single'), 2), single(1)); -%!assert (prod (zeros (0, 1, 'single')), single(1)); -%!assert (prod (zeros (0, 1, 'single'), 1), single(1)); -%!assert (prod (zeros (0, 1, 'single'), 2), zeros (0, 1, 'single')); -%!assert (prod (zeros (2, 0, 'single')), zeros (1, 0, 'single')); -%!assert (prod (zeros (2, 0, 'single'), 1), zeros (1, 0, 'single')); -%!assert (prod (zeros (2, 0, 'single'), 2), single([1; 1])); -%!assert (prod (zeros (0, 2, 'single')), single([1, 1])); -%!assert (prod (zeros (0, 2, 'single'), 1), single([1, 1])); -%!assert (prod (zeros (0, 2, 'single'), 2), zeros(0, 1, 'single')); - - */ +%!assert (prod ([1, 2, 3]), 6) +%!assert (prod ([-1; -2; -3]), -6) +%!assert (prod ([i, 2+i, -3+2i, 4]), -4 - 32i) +%!assert (prod ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [-1+i, -8+8i, -27+27i]) + +%!assert (prod (single ([1, 2, 3])), single (6)) +%!assert (prod (single ([-1; -2; -3])), single (-6)) +%!assert (prod (single ([i, 2+i, -3+2i, 4])), single (-4 - 32i)) +%!assert (prod (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single ([-1+i, -8+8i, -27+27i])) + +%!assert (prod ([1, 2; 3, 4], 1), [3, 8]) +%!assert (prod ([1, 2; 3, 4], 2), [2; 12]) +%!assert (prod (zeros (1, 0)), 1) +%!assert (prod (zeros (1, 0), 1), zeros (1, 0)) +%!assert (prod (zeros (1, 0), 2), 1) +%!assert (prod (zeros (0, 1)), 1) +%!assert (prod (zeros (0, 1), 1), 1) +%!assert (prod (zeros (0, 1), 2), zeros (0, 1)) +%!assert (prod (zeros (2, 0)), zeros (1, 0)) +%!assert (prod (zeros (2, 0), 1), zeros (1, 0)) +%!assert (prod (zeros (2, 0), 2), [1; 1]) +%!assert (prod (zeros (0, 2)), [1, 1]) +%!assert (prod (zeros (0, 2), 1), [1, 1]) +%!assert (prod (zeros (0, 2), 2), zeros (0, 1)) + +%!assert (prod (single ([1, 2; 3, 4]), 1), single ([3, 8])) +%!assert (prod (single ([1, 2; 3, 4]), 2), single ([2; 12])) +%!assert (prod (zeros (1, 0, "single")), single (1)) +%!assert (prod (zeros (1, 0, "single"), 1), zeros (1, 0, "single")) +%!assert (prod (zeros (1, 0, "single"), 2), single (1)) +%!assert (prod (zeros (0, 1, "single")), single (1)) +%!assert (prod (zeros (0, 1, "single"), 1), single (1)) +%!assert (prod (zeros (0, 1, "single"), 2), zeros (0, 1, "single")) +%!assert (prod (zeros (2, 0, "single")), zeros (1, 0, "single")) +%!assert (prod (zeros (2, 0, "single"), 1), zeros (1, 0, "single")) +%!assert (prod (zeros (2, 0, "single"), 2), single ([1; 1])) +%!assert (prod (zeros (0, 2, "single")), single ([1, 1])) +%!assert (prod (zeros (0, 2, "single"), 1), single ([1, 1])) +%!assert (prod (zeros (0, 2, "single"), 2), zeros (0, 1, "single")) + +%!error prod () +*/ static bool all_scalar_1x1 (const octave_value_list& args) @@ -1875,194 +1862,195 @@ } /* -%% test concatenation with all zero matrices -%!assert(horzcat ('', 65*ones(1,10)), 'AAAAAAAAAA'); -%!assert(horzcat (65*ones(1,10), ''), 'AAAAAAAAAA'); - -%!assert (class (horzcat (int64(1), int64(1))), 'int64') -%!assert (class (horzcat (int64(1), int32(1))), 'int64') -%!assert (class (horzcat (int64(1), int16(1))), 'int64') -%!assert (class (horzcat (int64(1), int8(1))), 'int64') -%!assert (class (horzcat (int64(1), uint64(1))), 'int64') -%!assert (class (horzcat (int64(1), uint32(1))), 'int64') -%!assert (class (horzcat (int64(1), uint16(1))), 'int64') -%!assert (class (horzcat (int64(1), uint8(1))), 'int64') -%!assert (class (horzcat (int64(1), single(1))), 'int64') -%!assert (class (horzcat (int64(1), double(1))), 'int64') -%!assert (class (horzcat (int64(1), cell(1))), 'cell') -%!assert (class (horzcat (int64(1), true)), 'int64') -%!assert (class (horzcat (int64(1), 'a')), 'char') - -%!assert (class (horzcat (int32(1), int64(1))), 'int32') -%!assert (class (horzcat (int32(1), int32(1))), 'int32') -%!assert (class (horzcat (int32(1), int16(1))), 'int32') -%!assert (class (horzcat (int32(1), int8(1))), 'int32') -%!assert (class (horzcat (int32(1), uint64(1))), 'int32') -%!assert (class (horzcat (int32(1), uint32(1))), 'int32') -%!assert (class (horzcat (int32(1), uint16(1))), 'int32') -%!assert (class (horzcat (int32(1), uint8(1))), 'int32') -%!assert (class (horzcat (int32(1), single(1))), 'int32') -%!assert (class (horzcat (int32(1), double(1))), 'int32') -%!assert (class (horzcat (int32(1), cell(1))), 'cell') -%!assert (class (horzcat (int32(1), true)), 'int32') -%!assert (class (horzcat (int32(1), 'a')), 'char') - -%!assert (class (horzcat (int16(1), int64(1))), 'int16') -%!assert (class (horzcat (int16(1), int32(1))), 'int16') -%!assert (class (horzcat (int16(1), int16(1))), 'int16') -%!assert (class (horzcat (int16(1), int8(1))), 'int16') -%!assert (class (horzcat (int16(1), uint64(1))), 'int16') -%!assert (class (horzcat (int16(1), uint32(1))), 'int16') -%!assert (class (horzcat (int16(1), uint16(1))), 'int16') -%!assert (class (horzcat (int16(1), uint8(1))), 'int16') -%!assert (class (horzcat (int16(1), single(1))), 'int16') -%!assert (class (horzcat (int16(1), double(1))), 'int16') -%!assert (class (horzcat (int16(1), cell(1))), 'cell') -%!assert (class (horzcat (int16(1), true)), 'int16') -%!assert (class (horzcat (int16(1), 'a')), 'char') - -%!assert (class (horzcat (int8(1), int64(1))), 'int8') -%!assert (class (horzcat (int8(1), int32(1))), 'int8') -%!assert (class (horzcat (int8(1), int16(1))), 'int8') -%!assert (class (horzcat (int8(1), int8(1))), 'int8') -%!assert (class (horzcat (int8(1), uint64(1))), 'int8') -%!assert (class (horzcat (int8(1), uint32(1))), 'int8') -%!assert (class (horzcat (int8(1), uint16(1))), 'int8') -%!assert (class (horzcat (int8(1), uint8(1))), 'int8') -%!assert (class (horzcat (int8(1), single(1))), 'int8') -%!assert (class (horzcat (int8(1), double(1))), 'int8') -%!assert (class (horzcat (int8(1), cell(1))), 'cell') -%!assert (class (horzcat (int8(1), true)), 'int8') -%!assert (class (horzcat (int8(1), 'a')), 'char') - -%!assert (class (horzcat (uint64(1), int64(1))), 'uint64') -%!assert (class (horzcat (uint64(1), int32(1))), 'uint64') -%!assert (class (horzcat (uint64(1), int16(1))), 'uint64') -%!assert (class (horzcat (uint64(1), int8(1))), 'uint64') -%!assert (class (horzcat (uint64(1), uint64(1))), 'uint64') -%!assert (class (horzcat (uint64(1), uint32(1))), 'uint64') -%!assert (class (horzcat (uint64(1), uint16(1))), 'uint64') -%!assert (class (horzcat (uint64(1), uint8(1))), 'uint64') -%!assert (class (horzcat (uint64(1), single(1))), 'uint64') -%!assert (class (horzcat (uint64(1), double(1))), 'uint64') -%!assert (class (horzcat (uint64(1), cell(1))), 'cell') -%!assert (class (horzcat (uint64(1), true)), 'uint64') -%!assert (class (horzcat (uint64(1), 'a')), 'char') - -%!assert (class (horzcat (uint32(1), int64(1))), 'uint32') -%!assert (class (horzcat (uint32(1), int32(1))), 'uint32') -%!assert (class (horzcat (uint32(1), int16(1))), 'uint32') -%!assert (class (horzcat (uint32(1), int8(1))), 'uint32') -%!assert (class (horzcat (uint32(1), uint64(1))), 'uint32') -%!assert (class (horzcat (uint32(1), uint32(1))), 'uint32') -%!assert (class (horzcat (uint32(1), uint16(1))), 'uint32') -%!assert (class (horzcat (uint32(1), uint8(1))), 'uint32') -%!assert (class (horzcat (uint32(1), single(1))), 'uint32') -%!assert (class (horzcat (uint32(1), double(1))), 'uint32') -%!assert (class (horzcat (uint32(1), cell(1))), 'cell') -%!assert (class (horzcat (uint32(1), true)), 'uint32') -%!assert (class (horzcat (uint32(1), 'a')), 'char') - -%!assert (class (horzcat (uint16(1), int64(1))), 'uint16') -%!assert (class (horzcat (uint16(1), int32(1))), 'uint16') -%!assert (class (horzcat (uint16(1), int16(1))), 'uint16') -%!assert (class (horzcat (uint16(1), int8(1))), 'uint16') -%!assert (class (horzcat (uint16(1), uint64(1))), 'uint16') -%!assert (class (horzcat (uint16(1), uint32(1))), 'uint16') -%!assert (class (horzcat (uint16(1), uint16(1))), 'uint16') -%!assert (class (horzcat (uint16(1), uint8(1))), 'uint16') -%!assert (class (horzcat (uint16(1), single(1))), 'uint16') -%!assert (class (horzcat (uint16(1), double(1))), 'uint16') -%!assert (class (horzcat (uint16(1), cell(1))), 'cell') -%!assert (class (horzcat (uint16(1), true)), 'uint16') -%!assert (class (horzcat (uint16(1), 'a')), 'char') - -%!assert (class (horzcat (uint8(1), int64(1))), 'uint8') -%!assert (class (horzcat (uint8(1), int32(1))), 'uint8') -%!assert (class (horzcat (uint8(1), int16(1))), 'uint8') -%!assert (class (horzcat (uint8(1), int8(1))), 'uint8') -%!assert (class (horzcat (uint8(1), uint64(1))), 'uint8') -%!assert (class (horzcat (uint8(1), uint32(1))), 'uint8') -%!assert (class (horzcat (uint8(1), uint16(1))), 'uint8') -%!assert (class (horzcat (uint8(1), uint8(1))), 'uint8') -%!assert (class (horzcat (uint8(1), single(1))), 'uint8') -%!assert (class (horzcat (uint8(1), double(1))), 'uint8') -%!assert (class (horzcat (uint8(1), cell(1))), 'cell') -%!assert (class (horzcat (uint8(1), true)), 'uint8') -%!assert (class (horzcat (uint8(1), 'a')), 'char') - -%!assert (class (horzcat (single(1), int64(1))), 'int64') -%!assert (class (horzcat (single(1), int32(1))), 'int32') -%!assert (class (horzcat (single(1), int16(1))), 'int16') -%!assert (class (horzcat (single(1), int8(1))), 'int8') -%!assert (class (horzcat (single(1), uint64(1))), 'uint64') -%!assert (class (horzcat (single(1), uint32(1))), 'uint32') -%!assert (class (horzcat (single(1), uint16(1))), 'uint16') -%!assert (class (horzcat (single(1), uint8(1))), 'uint8') -%!assert (class (horzcat (single(1), single(1))), 'single') -%!assert (class (horzcat (single(1), double(1))), 'single') -%!assert (class (horzcat (single(1), cell(1))), 'cell') -%!assert (class (horzcat (single(1), true)), 'single') -%!assert (class (horzcat (single(1), 'a')), 'char') - -%!assert (class (horzcat (double(1), int64(1))), 'int64') -%!assert (class (horzcat (double(1), int32(1))), 'int32') -%!assert (class (horzcat (double(1), int16(1))), 'int16') -%!assert (class (horzcat (double(1), int8(1))), 'int8') -%!assert (class (horzcat (double(1), uint64(1))), 'uint64') -%!assert (class (horzcat (double(1), uint32(1))), 'uint32') -%!assert (class (horzcat (double(1), uint16(1))), 'uint16') -%!assert (class (horzcat (double(1), uint8(1))), 'uint8') -%!assert (class (horzcat (double(1), single(1))), 'single') -%!assert (class (horzcat (double(1), double(1))), 'double') -%!assert (class (horzcat (double(1), cell(1))), 'cell') -%!assert (class (horzcat (double(1), true)), 'double') -%!assert (class (horzcat (double(1), 'a')), 'char') - -%!assert (class (horzcat (cell(1), int64(1))), 'cell') -%!assert (class (horzcat (cell(1), int32(1))), 'cell') -%!assert (class (horzcat (cell(1), int16(1))), 'cell') -%!assert (class (horzcat (cell(1), int8(1))), 'cell') -%!assert (class (horzcat (cell(1), uint64(1))), 'cell') -%!assert (class (horzcat (cell(1), uint32(1))), 'cell') -%!assert (class (horzcat (cell(1), uint16(1))), 'cell') -%!assert (class (horzcat (cell(1), uint8(1))), 'cell') -%!assert (class (horzcat (cell(1), single(1))), 'cell') -%!assert (class (horzcat (cell(1), double(1))), 'cell') -%!assert (class (horzcat (cell(1), cell(1))), 'cell') -%!assert (class (horzcat (cell(1), true)), 'cell') -%!assert (class (horzcat (cell(1), 'a')), 'cell') - -%!assert (class (horzcat (true, int64(1))), 'int64') -%!assert (class (horzcat (true, int32(1))), 'int32') -%!assert (class (horzcat (true, int16(1))), 'int16') -%!assert (class (horzcat (true, int8(1))), 'int8') -%!assert (class (horzcat (true, uint64(1))), 'uint64') -%!assert (class (horzcat (true, uint32(1))), 'uint32') -%!assert (class (horzcat (true, uint16(1))), 'uint16') -%!assert (class (horzcat (true, uint8(1))), 'uint8') -%!assert (class (horzcat (true, single(1))), 'single') -%!assert (class (horzcat (true, double(1))), 'double') -%!assert (class (horzcat (true, cell(1))), 'cell') -%!assert (class (horzcat (true, true)), 'logical') -%!assert (class (horzcat (true, 'a')), 'char') - -%!assert (class (horzcat ('a', int64(1))), 'char') -%!assert (class (horzcat ('a', int32(1))), 'char') -%!assert (class (horzcat ('a', int16(1))), 'char') -%!assert (class (horzcat ('a', int8(1))), 'char') -%!assert (class (horzcat ('a', int64(1))), 'char') -%!assert (class (horzcat ('a', int32(1))), 'char') -%!assert (class (horzcat ('a', int16(1))), 'char') -%!assert (class (horzcat ('a', int8(1))), 'char') -%!assert (class (horzcat ('a', single(1))), 'char') -%!assert (class (horzcat ('a', double(1))), 'char') -%!assert (class (horzcat ('a', cell(1))), 'cell') -%!assert (class (horzcat ('a', true)), 'char') -%!assert (class (horzcat ('a', 'a')), 'char') - -%!assert (class (horzcat (cell(1), struct('foo', 'bar'))), 'cell') -%!error horzcat (struct('foo', 'bar'), cell(1)); +## Test concatenation with all zero matrices +%!assert (horzcat ("", 65*ones (1,10)), "AAAAAAAAAA"); +%!assert (horzcat (65*ones (1,10), ""), "AAAAAAAAAA"); + +%!assert (class (horzcat (int64 (1), int64 (1))), "int64") +%!assert (class (horzcat (int64 (1), int32 (1))), "int64") +%!assert (class (horzcat (int64 (1), int16 (1))), "int64") +%!assert (class (horzcat (int64 (1), int8 (1))), "int64") +%!assert (class (horzcat (int64 (1), uint64 (1))), "int64") +%!assert (class (horzcat (int64 (1), uint32 (1))), "int64") +%!assert (class (horzcat (int64 (1), uint16 (1))), "int64") +%!assert (class (horzcat (int64 (1), uint8 (1))), "int64") +%!assert (class (horzcat (int64 (1), single (1))), "int64") +%!assert (class (horzcat (int64 (1), double (1))), "int64") +%!assert (class (horzcat (int64 (1), cell (1))), "cell") +%!assert (class (horzcat (int64 (1), true)), "int64") +%!assert (class (horzcat (int64 (1), "a")), "char") + +%!assert (class (horzcat (int32 (1), int64 (1))), "int32") +%!assert (class (horzcat (int32 (1), int32 (1))), "int32") +%!assert (class (horzcat (int32 (1), int16 (1))), "int32") +%!assert (class (horzcat (int32 (1), int8 (1))), "int32") +%!assert (class (horzcat (int32 (1), uint64 (1))), "int32") +%!assert (class (horzcat (int32 (1), uint32 (1))), "int32") +%!assert (class (horzcat (int32 (1), uint16 (1))), "int32") +%!assert (class (horzcat (int32 (1), uint8 (1))), "int32") +%!assert (class (horzcat (int32 (1), single (1))), "int32") +%!assert (class (horzcat (int32 (1), double (1))), "int32") +%!assert (class (horzcat (int32 (1), cell (1))), "cell") +%!assert (class (horzcat (int32 (1), true)), "int32") +%!assert (class (horzcat (int32 (1), "a")), "char") + +%!assert (class (horzcat (int16 (1), int64 (1))), "int16") +%!assert (class (horzcat (int16 (1), int32 (1))), "int16") +%!assert (class (horzcat (int16 (1), int16 (1))), "int16") +%!assert (class (horzcat (int16 (1), int8 (1))), "int16") +%!assert (class (horzcat (int16 (1), uint64 (1))), "int16") +%!assert (class (horzcat (int16 (1), uint32 (1))), "int16") +%!assert (class (horzcat (int16 (1), uint16 (1))), "int16") +%!assert (class (horzcat (int16 (1), uint8 (1))), "int16") +%!assert (class (horzcat (int16 (1), single (1))), "int16") +%!assert (class (horzcat (int16 (1), double (1))), "int16") +%!assert (class (horzcat (int16 (1), cell (1))), "cell") +%!assert (class (horzcat (int16 (1), true)), "int16") +%!assert (class (horzcat (int16 (1), "a")), "char") + +%!assert (class (horzcat (int8 (1), int64 (1))), "int8") +%!assert (class (horzcat (int8 (1), int32 (1))), "int8") +%!assert (class (horzcat (int8 (1), int16 (1))), "int8") +%!assert (class (horzcat (int8 (1), int8 (1))), "int8") +%!assert (class (horzcat (int8 (1), uint64 (1))), "int8") +%!assert (class (horzcat (int8 (1), uint32 (1))), "int8") +%!assert (class (horzcat (int8 (1), uint16 (1))), "int8") +%!assert (class (horzcat (int8 (1), uint8 (1))), "int8") +%!assert (class (horzcat (int8 (1), single (1))), "int8") +%!assert (class (horzcat (int8 (1), double (1))), "int8") +%!assert (class (horzcat (int8 (1), cell (1))), "cell") +%!assert (class (horzcat (int8 (1), true)), "int8") +%!assert (class (horzcat (int8 (1), "a")), "char") + +%!assert (class (horzcat (uint64 (1), int64 (1))), "uint64") +%!assert (class (horzcat (uint64 (1), int32 (1))), "uint64") +%!assert (class (horzcat (uint64 (1), int16 (1))), "uint64") +%!assert (class (horzcat (uint64 (1), int8 (1))), "uint64") +%!assert (class (horzcat (uint64 (1), uint64 (1))), "uint64") +%!assert (class (horzcat (uint64 (1), uint32 (1))), "uint64") +%!assert (class (horzcat (uint64 (1), uint16 (1))), "uint64") +%!assert (class (horzcat (uint64 (1), uint8 (1))), "uint64") +%!assert (class (horzcat (uint64 (1), single (1))), "uint64") +%!assert (class (horzcat (uint64 (1), double (1))), "uint64") +%!assert (class (horzcat (uint64 (1), cell (1))), "cell") +%!assert (class (horzcat (uint64 (1), true)), "uint64") +%!assert (class (horzcat (uint64 (1), "a")), "char") + +%!assert (class (horzcat (uint32 (1), int64 (1))), "uint32") +%!assert (class (horzcat (uint32 (1), int32 (1))), "uint32") +%!assert (class (horzcat (uint32 (1), int16 (1))), "uint32") +%!assert (class (horzcat (uint32 (1), int8 (1))), "uint32") +%!assert (class (horzcat (uint32 (1), uint64 (1))), "uint32") +%!assert (class (horzcat (uint32 (1), uint32 (1))), "uint32") +%!assert (class (horzcat (uint32 (1), uint16 (1))), "uint32") +%!assert (class (horzcat (uint32 (1), uint8 (1))), "uint32") +%!assert (class (horzcat (uint32 (1), single (1))), "uint32") +%!assert (class (horzcat (uint32 (1), double (1))), "uint32") +%!assert (class (horzcat (uint32 (1), cell (1))), "cell") +%!assert (class (horzcat (uint32 (1), true)), "uint32") +%!assert (class (horzcat (uint32 (1), "a")), "char") + +%!assert (class (horzcat (uint16 (1), int64 (1))), "uint16") +%!assert (class (horzcat (uint16 (1), int32 (1))), "uint16") +%!assert (class (horzcat (uint16 (1), int16 (1))), "uint16") +%!assert (class (horzcat (uint16 (1), int8 (1))), "uint16") +%!assert (class (horzcat (uint16 (1), uint64 (1))), "uint16") +%!assert (class (horzcat (uint16 (1), uint32 (1))), "uint16") +%!assert (class (horzcat (uint16 (1), uint16 (1))), "uint16") +%!assert (class (horzcat (uint16 (1), uint8 (1))), "uint16") +%!assert (class (horzcat (uint16 (1), single (1))), "uint16") +%!assert (class (horzcat (uint16 (1), double (1))), "uint16") +%!assert (class (horzcat (uint16 (1), cell (1))), "cell") +%!assert (class (horzcat (uint16 (1), true)), "uint16") +%!assert (class (horzcat (uint16 (1), "a")), "char") + +%!assert (class (horzcat (uint8 (1), int64 (1))), "uint8") +%!assert (class (horzcat (uint8 (1), int32 (1))), "uint8") +%!assert (class (horzcat (uint8 (1), int16 (1))), "uint8") +%!assert (class (horzcat (uint8 (1), int8 (1))), "uint8") +%!assert (class (horzcat (uint8 (1), uint64 (1))), "uint8") +%!assert (class (horzcat (uint8 (1), uint32 (1))), "uint8") +%!assert (class (horzcat (uint8 (1), uint16 (1))), "uint8") +%!assert (class (horzcat (uint8 (1), uint8 (1))), "uint8") +%!assert (class (horzcat (uint8 (1), single (1))), "uint8") +%!assert (class (horzcat (uint8 (1), double (1))), "uint8") +%!assert (class (horzcat (uint8 (1), cell (1))), "cell") +%!assert (class (horzcat (uint8 (1), true)), "uint8") +%!assert (class (horzcat (uint8 (1), "a")), "char") + +%!assert (class (horzcat (single (1), int64 (1))), "int64") +%!assert (class (horzcat (single (1), int32 (1))), "int32") +%!assert (class (horzcat (single (1), int16 (1))), "int16") +%!assert (class (horzcat (single (1), int8 (1))), "int8") +%!assert (class (horzcat (single (1), uint64 (1))), "uint64") +%!assert (class (horzcat (single (1), uint32 (1))), "uint32") +%!assert (class (horzcat (single (1), uint16 (1))), "uint16") +%!assert (class (horzcat (single (1), uint8 (1))), "uint8") +%!assert (class (horzcat (single (1), single (1))), "single") +%!assert (class (horzcat (single (1), double (1))), "single") +%!assert (class (horzcat (single (1), cell (1))), "cell") +%!assert (class (horzcat (single (1), true)), "single") +%!assert (class (horzcat (single (1), "a")), "char") + +%!assert (class (horzcat (double (1), int64 (1))), "int64") +%!assert (class (horzcat (double (1), int32 (1))), "int32") +%!assert (class (horzcat (double (1), int16 (1))), "int16") +%!assert (class (horzcat (double (1), int8 (1))), "int8") +%!assert (class (horzcat (double (1), uint64 (1))), "uint64") +%!assert (class (horzcat (double (1), uint32 (1))), "uint32") +%!assert (class (horzcat (double (1), uint16 (1))), "uint16") +%!assert (class (horzcat (double (1), uint8 (1))), "uint8") +%!assert (class (horzcat (double (1), single (1))), "single") +%!assert (class (horzcat (double (1), double (1))), "double") +%!assert (class (horzcat (double (1), cell (1))), "cell") +%!assert (class (horzcat (double (1), true)), "double") +%!assert (class (horzcat (double (1), "a")), "char") + +%!assert (class (horzcat (cell (1), int64 (1))), "cell") +%!assert (class (horzcat (cell (1), int32 (1))), "cell") +%!assert (class (horzcat (cell (1), int16 (1))), "cell") +%!assert (class (horzcat (cell (1), int8 (1))), "cell") +%!assert (class (horzcat (cell (1), uint64 (1))), "cell") +%!assert (class (horzcat (cell (1), uint32 (1))), "cell") +%!assert (class (horzcat (cell (1), uint16 (1))), "cell") +%!assert (class (horzcat (cell (1), uint8 (1))), "cell") +%!assert (class (horzcat (cell (1), single (1))), "cell") +%!assert (class (horzcat (cell (1), double (1))), "cell") +%!assert (class (horzcat (cell (1), cell (1))), "cell") +%!assert (class (horzcat (cell (1), true)), "cell") +%!assert (class (horzcat (cell (1), "a")), "cell") + +%!assert (class (horzcat (true, int64 (1))), "int64") +%!assert (class (horzcat (true, int32 (1))), "int32") +%!assert (class (horzcat (true, int16 (1))), "int16") +%!assert (class (horzcat (true, int8 (1))), "int8") +%!assert (class (horzcat (true, uint64 (1))), "uint64") +%!assert (class (horzcat (true, uint32 (1))), "uint32") +%!assert (class (horzcat (true, uint16 (1))), "uint16") +%!assert (class (horzcat (true, uint8 (1))), "uint8") +%!assert (class (horzcat (true, single (1))), "single") +%!assert (class (horzcat (true, double (1))), "double") +%!assert (class (horzcat (true, cell (1))), "cell") +%!assert (class (horzcat (true, true)), "logical") +%!assert (class (horzcat (true, "a")), "char") + +%!assert (class (horzcat ("a", int64 (1))), "char") +%!assert (class (horzcat ("a", int32 (1))), "char") +%!assert (class (horzcat ("a", int16 (1))), "char") +%!assert (class (horzcat ("a", int8 (1))), "char") +%!assert (class (horzcat ("a", int64 (1))), "char") +%!assert (class (horzcat ("a", int32 (1))), "char") +%!assert (class (horzcat ("a", int16 (1))), "char") +%!assert (class (horzcat ("a", int8 (1))), "char") +%!assert (class (horzcat ("a", single (1))), "char") +%!assert (class (horzcat ("a", double (1))), "char") +%!assert (class (horzcat ("a", cell (1))), "cell") +%!assert (class (horzcat ("a", true)), "char") +%!assert (class (horzcat ("a", "a")), "char") + +%!assert (class (horzcat (cell (1), struct ("foo", "bar"))), "cell") + +%!error horzcat (struct ("foo", "bar"), cell (1)) */ DEFUN (vertcat, args, , @@ -2085,8 +2073,8 @@ /* %!test -%! c = {'foo'; 'bar'; 'bazoloa'}; -%! assert (vertcat (c, 'a', 'bc', 'def'), {'foo'; 'bar'; 'bazoloa'; 'a'; 'bc'; 'def'}); +%! c = {"foo"; "bar"; "bazoloa"}; +%! assert (vertcat (c, "a", "bc", "def"), {"foo"; "bar"; "bazoloa"; "a"; "bc"; "def"}); */ DEFUN (cat, args, , @@ -2158,132 +2146,131 @@ } /* - %!function ret = __testcat (t1, t2, tr, cmplx) -%! assert (cat (1, cast ([], t1), cast([], t2)), cast ([], tr)); -%! -%! assert (cat (1, cast (1, t1), cast (2, t2)), cast ([1; 2], tr)); -%! assert (cat (1, cast (1, t1), cast ([2; 3], t2)), cast ([1; 2; 3], tr)); -%! assert (cat (1, cast ([1; 2], t1), cast (3, t2)), cast ([1; 2; 3], tr)); -%! assert (cat (1, cast ([1; 2], t1), cast ([3; 4], t2)), cast ([1; 2; 3; 4], tr)); -%! assert (cat (2, cast (1, t1), cast (2, t2)), cast ([1, 2], tr)); -%! assert (cat (2, cast (1, t1), cast ([2, 3], t2)), cast ([1, 2, 3], tr)); -%! assert (cat (2, cast ([1, 2], t1), cast (3, t2)), cast ([1, 2, 3], tr)); -%! assert (cat (2, cast ([1, 2], t1), cast ([3, 4], t2)), cast ([1, 2, 3, 4], tr)); -%! -%! assert ([cast(1, t1); cast(2, t2)], cast ([1; 2], tr)); -%! assert ([cast(1, t1); cast([2; 3], t2)], cast ([1; 2; 3], tr)); -%! assert ([cast([1; 2], t1); cast(3, t2)], cast ([1; 2; 3], tr)); -%! assert ([cast([1; 2], t1); cast([3; 4], t2)], cast ([1; 2; 3; 4], tr)); -%! assert ([cast(1, t1), cast(2, t2)], cast ([1, 2], tr)); -%! assert ([cast(1, t1), cast([2, 3], t2)], cast ([1, 2, 3], tr)); -%! assert ([cast([1, 2], t1), cast(3, t2)], cast ([1, 2, 3], tr)); -%! assert ([cast([1, 2], t1), cast([3, 4], t2)], cast ([1, 2, 3, 4], tr)); -%! -%! if (nargin == 3 || cmplx) -%! assert (cat (1, cast (1i, t1), cast (2, t2)), cast ([1i; 2], tr)); -%! assert (cat (1, cast (1i, t1), cast ([2; 3], t2)), cast ([1i; 2; 3], tr)); -%! assert (cat (1, cast ([1i; 2], t1), cast (3, t2)), cast ([1i; 2; 3], tr)); -%! assert (cat (1, cast ([1i; 2], t1), cast ([3; 4], t2)), cast ([1i; 2; 3; 4], tr)); -%! assert (cat (2, cast (1i, t1), cast (2, t2)), cast ([1i, 2], tr)); -%! assert (cat (2, cast (1i, t1), cast ([2, 3], t2)), cast ([1i, 2, 3], tr)); -%! assert (cat (2, cast ([1i, 2], t1), cast (3, t2)), cast ([1i, 2, 3], tr)); -%! assert (cat (2, cast ([1i, 2], t1), cast ([3, 4], t2)), cast ([1i, 2, 3, 4], tr)); -%! -%! assert ([cast(1i, t1); cast(2, t2)], cast ([1i; 2], tr)); -%! assert ([cast(1i, t1); cast([2; 3], t2)], cast ([1i; 2; 3], tr)); -%! assert ([cast([1i; 2], t1); cast(3, t2)], cast ([1i; 2; 3], tr)); -%! assert ([cast([1i; 2], t1); cast([3; 4], t2)], cast ([1i; 2; 3; 4], tr)); -%! assert ([cast(1i, t1), cast(2, t2)], cast ([1i, 2], tr)); -%! assert ([cast(1i, t1), cast([2, 3], t2)], cast ([1i, 2, 3], tr)); -%! assert ([cast([1i, 2], t1), cast(3, t2)], cast ([1i, 2, 3], tr)); -%! assert ([cast([1i, 2], t1), cast([3, 4], t2)], cast ([1i, 2, 3, 4], tr)); -%! -%! assert (cat (1, cast (1, t1), cast (2i, t2)), cast ([1; 2i], tr)); -%! assert (cat (1, cast (1, t1), cast ([2i; 3], t2)), cast ([1; 2i; 3], tr)); -%! assert (cat (1, cast ([1; 2], t1), cast (3i, t2)), cast ([1; 2; 3i], tr)); -%! assert (cat (1, cast ([1; 2], t1), cast ([3i; 4], t2)), cast ([1; 2; 3i; 4], tr)); -%! assert (cat (2, cast (1, t1), cast (2i, t2)), cast ([1, 2i], tr)); -%! assert (cat (2, cast (1, t1), cast ([2i, 3], t2)), cast ([1, 2i, 3], tr)); -%! assert (cat (2, cast ([1, 2], t1), cast (3i, t2)), cast ([1, 2, 3i], tr)); -%! assert (cat (2, cast ([1, 2], t1), cast ([3i, 4], t2)), cast ([1, 2, 3i, 4], tr)); -%! -%! assert ([cast(1, t1); cast(2i, t2)], cast ([1; 2i], tr)); -%! assert ([cast(1, t1); cast([2i; 3], t2)], cast ([1; 2i; 3], tr)); -%! assert ([cast([1; 2], t1); cast(3i, t2)], cast ([1; 2; 3i], tr)); -%! assert ([cast([1; 2], t1); cast([3i; 4], t2)], cast ([1; 2; 3i; 4], tr)); -%! assert ([cast(1, t1), cast(2i, t2)], cast ([1, 2i], tr)); -%! assert ([cast(1, t1), cast([2i, 3], t2)], cast ([1, 2i, 3], tr)); -%! assert ([cast([1, 2], t1), cast(3i, t2)], cast ([1, 2, 3i], tr)); -%! assert ([cast([1, 2], t1), cast([3i, 4], t2)], cast ([1, 2, 3i, 4], tr)); -%! -%! assert (cat (1, cast (1i, t1), cast (2i, t2)), cast ([1i; 2i], tr)); -%! assert (cat (1, cast (1i, t1), cast ([2i; 3], t2)), cast ([1i; 2i; 3], tr)); -%! assert (cat (1, cast ([1i; 2], t1), cast (3i, t2)), cast ([1i; 2; 3i], tr)); -%! assert (cat (1, cast ([1i; 2], t1), cast ([3i; 4], t2)), cast ([1i; 2; 3i; 4], tr)); -%! assert (cat (2, cast (1i, t1), cast (2i, t2)), cast ([1i, 2i], tr)); -%! assert (cat (2, cast (1i, t1), cast ([2i, 3], t2)), cast ([1i, 2i, 3], tr)); -%! assert (cat (2, cast ([1i, 2], t1), cast (3i, t2)), cast ([1i, 2, 3i], tr)); -%! assert (cat (2, cast ([1i, 2], t1), cast ([3i, 4], t2)), cast ([1i, 2, 3i, 4], tr)); -%! -%! assert ([cast(1i, t1); cast(2i, t2)], cast ([1i; 2i], tr)); -%! assert ([cast(1i, t1); cast([2i; 3], t2)], cast ([1i; 2i; 3], tr)); -%! assert ([cast([1i; 2], t1); cast(3i, t2)], cast ([1i; 2; 3i], tr)); -%! assert ([cast([1i; 2], t1); cast([3i; 4], t2)], cast ([1i; 2; 3i; 4], tr)); -%! assert ([cast(1i, t1), cast(2i, t2)], cast ([1i, 2i], tr)); -%! assert ([cast(1i, t1), cast([2i, 3], t2)], cast ([1i, 2i, 3], tr)); -%! assert ([cast([1i, 2], t1), cast(3i, t2)], cast ([1i, 2, 3i], tr)); -%! assert ([cast([1i, 2], t1), cast([3i, 4], t2)], cast ([1i, 2, 3i, 4], tr)); -%! endif -%! ret = true; +%! assert (cat (1, cast ([], t1), cast([], t2)), cast ([], tr)); +%! +%! assert (cat (1, cast (1, t1), cast (2, t2)), cast ([1; 2], tr)); +%! assert (cat (1, cast (1, t1), cast ([2; 3], t2)), cast ([1; 2; 3], tr)); +%! assert (cat (1, cast ([1; 2], t1), cast (3, t2)), cast ([1; 2; 3], tr)); +%! assert (cat (1, cast ([1; 2], t1), cast ([3; 4], t2)), cast ([1; 2; 3; 4], tr)); +%! assert (cat (2, cast (1, t1), cast (2, t2)), cast ([1, 2], tr)); +%! assert (cat (2, cast (1, t1), cast ([2, 3], t2)), cast ([1, 2, 3], tr)); +%! assert (cat (2, cast ([1, 2], t1), cast (3, t2)), cast ([1, 2, 3], tr)); +%! assert (cat (2, cast ([1, 2], t1), cast ([3, 4], t2)), cast ([1, 2, 3, 4], tr)); +%! +%! assert ([cast(1, t1); cast(2, t2)], cast ([1; 2], tr)); +%! assert ([cast(1, t1); cast([2; 3], t2)], cast ([1; 2; 3], tr)); +%! assert ([cast([1; 2], t1); cast(3, t2)], cast ([1; 2; 3], tr)); +%! assert ([cast([1; 2], t1); cast([3; 4], t2)], cast ([1; 2; 3; 4], tr)); +%! assert ([cast(1, t1), cast(2, t2)], cast ([1, 2], tr)); +%! assert ([cast(1, t1), cast([2, 3], t2)], cast ([1, 2, 3], tr)); +%! assert ([cast([1, 2], t1), cast(3, t2)], cast ([1, 2, 3], tr)); +%! assert ([cast([1, 2], t1), cast([3, 4], t2)], cast ([1, 2, 3, 4], tr)); +%! +%! if (nargin == 3 || cmplx) +%! assert (cat (1, cast (1i, t1), cast (2, t2)), cast ([1i; 2], tr)); +%! assert (cat (1, cast (1i, t1), cast ([2; 3], t2)), cast ([1i; 2; 3], tr)); +%! assert (cat (1, cast ([1i; 2], t1), cast (3, t2)), cast ([1i; 2; 3], tr)); +%! assert (cat (1, cast ([1i; 2], t1), cast ([3; 4], t2)), cast ([1i; 2; 3; 4], tr)); +%! assert (cat (2, cast (1i, t1), cast (2, t2)), cast ([1i, 2], tr)); +%! assert (cat (2, cast (1i, t1), cast ([2, 3], t2)), cast ([1i, 2, 3], tr)); +%! assert (cat (2, cast ([1i, 2], t1), cast (3, t2)), cast ([1i, 2, 3], tr)); +%! assert (cat (2, cast ([1i, 2], t1), cast ([3, 4], t2)), cast ([1i, 2, 3, 4], tr)); +%! +%! assert ([cast(1i, t1); cast(2, t2)], cast ([1i; 2], tr)); +%! assert ([cast(1i, t1); cast([2; 3], t2)], cast ([1i; 2; 3], tr)); +%! assert ([cast([1i; 2], t1); cast(3, t2)], cast ([1i; 2; 3], tr)); +%! assert ([cast([1i; 2], t1); cast([3; 4], t2)], cast ([1i; 2; 3; 4], tr)); +%! assert ([cast(1i, t1), cast(2, t2)], cast ([1i, 2], tr)); +%! assert ([cast(1i, t1), cast([2, 3], t2)], cast ([1i, 2, 3], tr)); +%! assert ([cast([1i, 2], t1), cast(3, t2)], cast ([1i, 2, 3], tr)); +%! assert ([cast([1i, 2], t1), cast([3, 4], t2)], cast ([1i, 2, 3, 4], tr)); +%! +%! assert (cat (1, cast (1, t1), cast (2i, t2)), cast ([1; 2i], tr)); +%! assert (cat (1, cast (1, t1), cast ([2i; 3], t2)), cast ([1; 2i; 3], tr)); +%! assert (cat (1, cast ([1; 2], t1), cast (3i, t2)), cast ([1; 2; 3i], tr)); +%! assert (cat (1, cast ([1; 2], t1), cast ([3i; 4], t2)), cast ([1; 2; 3i; 4], tr)); +%! assert (cat (2, cast (1, t1), cast (2i, t2)), cast ([1, 2i], tr)); +%! assert (cat (2, cast (1, t1), cast ([2i, 3], t2)), cast ([1, 2i, 3], tr)); +%! assert (cat (2, cast ([1, 2], t1), cast (3i, t2)), cast ([1, 2, 3i], tr)); +%! assert (cat (2, cast ([1, 2], t1), cast ([3i, 4], t2)), cast ([1, 2, 3i, 4], tr)); +%! +%! assert ([cast(1, t1); cast(2i, t2)], cast ([1; 2i], tr)); +%! assert ([cast(1, t1); cast([2i; 3], t2)], cast ([1; 2i; 3], tr)); +%! assert ([cast([1; 2], t1); cast(3i, t2)], cast ([1; 2; 3i], tr)); +%! assert ([cast([1; 2], t1); cast([3i; 4], t2)], cast ([1; 2; 3i; 4], tr)); +%! assert ([cast(1, t1), cast(2i, t2)], cast ([1, 2i], tr)); +%! assert ([cast(1, t1), cast([2i, 3], t2)], cast ([1, 2i, 3], tr)); +%! assert ([cast([1, 2], t1), cast(3i, t2)], cast ([1, 2, 3i], tr)); +%! assert ([cast([1, 2], t1), cast([3i, 4], t2)], cast ([1, 2, 3i, 4], tr)); +%! +%! assert (cat (1, cast (1i, t1), cast (2i, t2)), cast ([1i; 2i], tr)); +%! assert (cat (1, cast (1i, t1), cast ([2i; 3], t2)), cast ([1i; 2i; 3], tr)); +%! assert (cat (1, cast ([1i; 2], t1), cast (3i, t2)), cast ([1i; 2; 3i], tr)); +%! assert (cat (1, cast ([1i; 2], t1), cast ([3i; 4], t2)), cast ([1i; 2; 3i; 4], tr)); +%! assert (cat (2, cast (1i, t1), cast (2i, t2)), cast ([1i, 2i], tr)); +%! assert (cat (2, cast (1i, t1), cast ([2i, 3], t2)), cast ([1i, 2i, 3], tr)); +%! assert (cat (2, cast ([1i, 2], t1), cast (3i, t2)), cast ([1i, 2, 3i], tr)); +%! assert (cat (2, cast ([1i, 2], t1), cast ([3i, 4], t2)), cast ([1i, 2, 3i, 4], tr)); +%! +%! assert ([cast(1i, t1); cast(2i, t2)], cast ([1i; 2i], tr)); +%! assert ([cast(1i, t1); cast([2i; 3], t2)], cast ([1i; 2i; 3], tr)); +%! assert ([cast([1i; 2], t1); cast(3i, t2)], cast ([1i; 2; 3i], tr)); +%! assert ([cast([1i; 2], t1); cast([3i; 4], t2)], cast ([1i; 2; 3i; 4], tr)); +%! assert ([cast(1i, t1), cast(2i, t2)], cast ([1i, 2i], tr)); +%! assert ([cast(1i, t1), cast([2i, 3], t2)], cast ([1i, 2i, 3], tr)); +%! assert ([cast([1i, 2], t1), cast(3i, t2)], cast ([1i, 2, 3i], tr)); +%! assert ([cast([1i, 2], t1), cast([3i, 4], t2)], cast ([1i, 2, 3i, 4], tr)); +%! endif +%! ret = true; %!endfunction -%!assert (__testcat('double', 'double', 'double')) -%!assert (__testcat('single', 'double', 'single')) -%!assert (__testcat('double', 'single', 'single')) -%!assert (__testcat('single', 'single', 'single')) - -%!assert (__testcat('double', 'int8', 'int8', false)) -%!assert (__testcat('int8', 'double', 'int8', false)) -%!assert (__testcat('single', 'int8', 'int8', false)) -%!assert (__testcat('int8', 'single', 'int8', false)) -%!assert (__testcat('int8', 'int8', 'int8', false)) -%!assert (__testcat('double', 'int16', 'int16', false)) -%!assert (__testcat('int16', 'double', 'int16', false)) -%!assert (__testcat('single', 'int16', 'int16', false)) -%!assert (__testcat('int16', 'single', 'int16', false)) -%!assert (__testcat('int16', 'int16', 'int16', false)) -%!assert (__testcat('double', 'int32', 'int32', false)) -%!assert (__testcat('int32', 'double', 'int32', false)) -%!assert (__testcat('single', 'int32', 'int32', false)) -%!assert (__testcat('int32', 'single', 'int32', false)) -%!assert (__testcat('int32', 'int32', 'int32', false)) -%!assert (__testcat('double', 'int64', 'int64', false)) -%!assert (__testcat('int64', 'double', 'int64', false)) -%!assert (__testcat('single', 'int64', 'int64', false)) -%!assert (__testcat('int64', 'single', 'int64', false)) -%!assert (__testcat('int64', 'int64', 'int64', false)) - -%!assert (__testcat('double', 'uint8', 'uint8', false)) -%!assert (__testcat('uint8', 'double', 'uint8', false)) -%!assert (__testcat('single', 'uint8', 'uint8', false)) -%!assert (__testcat('uint8', 'single', 'uint8', false)) -%!assert (__testcat('uint8', 'uint8', 'uint8', false)) -%!assert (__testcat('double', 'uint16', 'uint16', false)) -%!assert (__testcat('uint16', 'double', 'uint16', false)) -%!assert (__testcat('single', 'uint16', 'uint16', false)) -%!assert (__testcat('uint16', 'single', 'uint16', false)) -%!assert (__testcat('uint16', 'uint16', 'uint16', false)) -%!assert (__testcat('double', 'uint32', 'uint32', false)) -%!assert (__testcat('uint32', 'double', 'uint32', false)) -%!assert (__testcat('single', 'uint32', 'uint32', false)) -%!assert (__testcat('uint32', 'single', 'uint32', false)) -%!assert (__testcat('uint32', 'uint32', 'uint32', false)) -%!assert (__testcat('double', 'uint64', 'uint64', false)) -%!assert (__testcat('uint64', 'double', 'uint64', false)) -%!assert (__testcat('single', 'uint64', 'uint64', false)) -%!assert (__testcat('uint64', 'single', 'uint64', false)) -%!assert (__testcat('uint64', 'uint64', 'uint64', false)) +%!assert (__testcat ("double", "double", "double")) +%!assert (__testcat ("single", "double", "single")) +%!assert (__testcat ("double", "single", "single")) +%!assert (__testcat ("single", "single", "single")) + +%!assert (__testcat ("double", "int8", "int8", false)) +%!assert (__testcat ("int8", "double", "int8", false)) +%!assert (__testcat ("single", "int8", "int8", false)) +%!assert (__testcat ("int8", "single", "int8", false)) +%!assert (__testcat ("int8", "int8", "int8", false)) +%!assert (__testcat ("double", "int16", "int16", false)) +%!assert (__testcat ("int16", "double", "int16", false)) +%!assert (__testcat ("single", "int16", "int16", false)) +%!assert (__testcat ("int16", "single", "int16", false)) +%!assert (__testcat ("int16", "int16", "int16", false)) +%!assert (__testcat ("double", "int32", "int32", false)) +%!assert (__testcat ("int32", "double", "int32", false)) +%!assert (__testcat ("single", "int32", "int32", false)) +%!assert (__testcat ("int32", "single", "int32", false)) +%!assert (__testcat ("int32", "int32", "int32", false)) +%!assert (__testcat ("double", "int64", "int64", false)) +%!assert (__testcat ("int64", "double", "int64", false)) +%!assert (__testcat ("single", "int64", "int64", false)) +%!assert (__testcat ("int64", "single", "int64", false)) +%!assert (__testcat ("int64", "int64", "int64", false)) + +%!assert (__testcat ("double", "uint8", "uint8", false)) +%!assert (__testcat ("uint8", "double", "uint8", false)) +%!assert (__testcat ("single", "uint8", "uint8", false)) +%!assert (__testcat ("uint8", "single", "uint8", false)) +%!assert (__testcat ("uint8", "uint8", "uint8", false)) +%!assert (__testcat ("double", "uint16", "uint16", false)) +%!assert (__testcat ("uint16", "double", "uint16", false)) +%!assert (__testcat ("single", "uint16", "uint16", false)) +%!assert (__testcat ("uint16", "single", "uint16", false)) +%!assert (__testcat ("uint16", "uint16", "uint16", false)) +%!assert (__testcat ("double", "uint32", "uint32", false)) +%!assert (__testcat ("uint32", "double", "uint32", false)) +%!assert (__testcat ("single", "uint32", "uint32", false)) +%!assert (__testcat ("uint32", "single", "uint32", false)) +%!assert (__testcat ("uint32", "uint32", "uint32", false)) +%!assert (__testcat ("double", "uint64", "uint64", false)) +%!assert (__testcat ("uint64", "double", "uint64", false)) +%!assert (__testcat ("single", "uint64", "uint64", false)) +%!assert (__testcat ("uint64", "single", "uint64", false)) +%!assert (__testcat ("uint64", "uint64", "uint64", false)) %!assert (cat (3, [], [1,2;3,4]), [1,2;3,4]) %!assert (cat (3, [1,2;3,4], []), [1,2;3,4]) @@ -2293,12 +2280,12 @@ %!assert (cat (3, [], [], 1, 2), cat (3, 1, 2)) %!assert (cat (3, [], [], [1,2;3,4]), [1,2;3,4]) %!assert (cat (4, [], [], [1,2;3,4]), [1,2;3,4]) + +%!assert ([zeros(3,2,2); ones(1,2,2)], repmat ([0;0;0;1],[1,2,2]) ) +%!assert ([zeros(3,2,2); ones(1,2,2)], vertcat (zeros (3,2,2), ones (1,2,2)) ) + %!error <dimension mismatch> cat (3, cat (3, [], []), [1,2;3,4]) %!error <dimension mismatch> cat (3, zeros (0, 0, 2), [1,2;3,4]) - -%!assert ([zeros(3,2,2); ones(1,2,2)], repmat([0;0;0;1],[1,2,2]) ) -%!assert ([zeros(3,2,2); ones(1,2,2)], vertcat(zeros(3,2,2), ones(1,2,2)) ) - */ static octave_value @@ -2803,64 +2790,62 @@ } /* - -%!assert (sum([true,true]), 2) -%!assert (sum([true,true],'native'), true) -%!assert (sum(int8([127,10,-20])), 117); -%!assert (sum(int8([127,10,-20]),'native'), int8(107)); - -%!assert(sum ([1, 2, 3]), 6) -%!assert(sum ([-1; -2; -3]), -6); -%!assert(sum ([i, 2+i, -3+2i, 4]), 3+4i); -%!assert(sum ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [2+2i, 4+4i, 6+6i]); - -%!assert(sum (single([1, 2, 3])), single(6)) -%!assert(sum (single([-1; -2; -3])), single(-6)); -%!assert(sum (single([i, 2+i, -3+2i, 4])), single(3+4i)); -%!assert(sum (single([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single([2+2i, 4+4i, 6+6i])); - -%!error <Invalid call to sum> sum (); - -%!assert (sum ([1, 2; 3, 4], 1), [4, 6]); -%!assert (sum ([1, 2; 3, 4], 2), [3; 7]); -%!assert (sum (zeros (1, 0)), 0); -%!assert (sum (zeros (1, 0), 1), zeros(1, 0)); -%!assert (sum (zeros (1, 0), 2), 0); -%!assert (sum (zeros (0, 1)), 0); -%!assert (sum (zeros (0, 1), 1), 0); -%!assert (sum (zeros (0, 1), 2), zeros(0, 1)); -%!assert (sum (zeros (2, 0)), zeros(1, 0)); -%!assert (sum (zeros (2, 0), 1), zeros(1, 0)); -%!assert (sum (zeros (2, 0), 2), [0; 0]); -%!assert (sum (zeros (0, 2)), [0, 0]); -%!assert (sum (zeros (0, 2), 1), [0, 0]); -%!assert (sum (zeros (0, 2), 2), zeros(0, 1)); -%!assert (sum (zeros (2, 2, 0, 3)), zeros(1, 2, 0, 3)); -%!assert (sum (zeros (2, 2, 0, 3), 2), zeros(2, 1, 0, 3)); -%!assert (sum (zeros (2, 2, 0, 3), 3), zeros(2, 2, 1, 3)); -%!assert (sum (zeros (2, 2, 0, 3), 4), zeros(2, 2, 0)); -%!assert (sum (zeros (2, 2, 0, 3), 7), zeros(2, 2, 0, 3)); - -%!assert (sum (single([1, 2; 3, 4]), 1), single([4, 6])); -%!assert (sum (single([1, 2; 3, 4]), 2), single([3; 7])); -%!assert (sum (zeros (1, 0, 'single')), single(0)); -%!assert (sum (zeros (1, 0, 'single'), 1), zeros(1, 0, 'single')); -%!assert (sum (zeros (1, 0, 'single'), 2), single(0)); -%!assert (sum (zeros (0, 1, 'single')), single(0)); -%!assert (sum (zeros (0, 1, 'single'), 1), single(0)); -%!assert (sum (zeros (0, 1, 'single'), 2), zeros(0, 1, 'single')); -%!assert (sum (zeros (2, 0, 'single')), zeros(1, 0, 'single')); -%!assert (sum (zeros (2, 0, 'single'), 1), zeros(1, 0, 'single')); -%!assert (sum (zeros (2, 0, 'single'), 2), single([0; 0])); -%!assert (sum (zeros (0, 2, 'single')), single([0, 0])); -%!assert (sum (zeros (0, 2, 'single'), 1), single([0, 0])); -%!assert (sum (zeros (0, 2, 'single'), 2), zeros(0, 1, 'single')); -%!assert (sum (zeros (2, 2, 0, 3, 'single')), zeros(1, 2, 0, 3, 'single')); -%!assert (sum (zeros (2, 2, 0, 3, 'single'), 2), zeros(2, 1, 0, 3, 'single')); -%!assert (sum (zeros (2, 2, 0, 3, 'single'), 3), zeros(2, 2, 1, 3, 'single')); -%!assert (sum (zeros (2, 2, 0, 3, 'single'), 4), zeros(2, 2, 0, 'single')); -%!assert (sum (zeros (2, 2, 0, 3, 'single'), 7), zeros(2, 2, 0, 3, 'single')); - +%!assert (sum ([true,true]), 2) +%!assert (sum ([true,true],"native"), true) +%!assert (sum (int8 ([127,10,-20])), 117) +%!assert (sum (int8 ([127,10,-20]),'native'), int8 (107)) + +%!assert (sum ([1, 2, 3]), 6) +%!assert (sum ([-1; -2; -3]), -6) +%!assert (sum ([i, 2+i, -3+2i, 4]), 3+4i) +%!assert (sum ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [2+2i, 4+4i, 6+6i]) + +%!assert (sum (single ([1, 2, 3])), single (6)) +%!assert (sum (single ([-1; -2; -3])), single (-6)) +%!assert (sum (single ([i, 2+i, -3+2i, 4])), single (3+4i)) +%!assert (sum (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single ([2+2i, 4+4i, 6+6i])) + +%!assert (sum ([1, 2; 3, 4], 1), [4, 6]) +%!assert (sum ([1, 2; 3, 4], 2), [3; 7]) +%!assert (sum (zeros (1, 0)), 0) +%!assert (sum (zeros (1, 0), 1), zeros (1, 0)) +%!assert (sum (zeros (1, 0), 2), 0) +%!assert (sum (zeros (0, 1)), 0) +%!assert (sum (zeros (0, 1), 1), 0) +%!assert (sum (zeros (0, 1), 2), zeros (0, 1)) +%!assert (sum (zeros (2, 0)), zeros (1, 0)) +%!assert (sum (zeros (2, 0), 1), zeros (1, 0)) +%!assert (sum (zeros (2, 0), 2), [0; 0]) +%!assert (sum (zeros (0, 2)), [0, 0]) +%!assert (sum (zeros (0, 2), 1), [0, 0]) +%!assert (sum (zeros (0, 2), 2), zeros (0, 1)) +%!assert (sum (zeros (2, 2, 0, 3)), zeros (1, 2, 0, 3)) +%!assert (sum (zeros (2, 2, 0, 3), 2), zeros (2, 1, 0, 3)) +%!assert (sum (zeros (2, 2, 0, 3), 3), zeros (2, 2, 1, 3)) +%!assert (sum (zeros (2, 2, 0, 3), 4), zeros (2, 2, 0)) +%!assert (sum (zeros (2, 2, 0, 3), 7), zeros (2, 2, 0, 3)) + +%!assert (sum (single ([1, 2; 3, 4]), 1), single ([4, 6])) +%!assert (sum (single ([1, 2; 3, 4]), 2), single ([3; 7])) +%!assert (sum (zeros (1, 0, "single")), single (0)) +%!assert (sum (zeros (1, 0, "single"), 1), zeros (1, 0, "single")) +%!assert (sum (zeros (1, 0, "single"), 2), single (0)) +%!assert (sum (zeros (0, 1, "single")), single (0)) +%!assert (sum (zeros (0, 1, "single"), 1), single (0)) +%!assert (sum (zeros (0, 1, "single"), 2), zeros (0, 1, "single")) +%!assert (sum (zeros (2, 0, "single")), zeros (1, 0, "single")) +%!assert (sum (zeros (2, 0, "single"), 1), zeros (1, 0, "single")) +%!assert (sum (zeros (2, 0, "single"), 2), single ([0; 0])) +%!assert (sum (zeros (0, 2, "single")), single ([0, 0])) +%!assert (sum (zeros (0, 2, "single"), 1), single ([0, 0])) +%!assert (sum (zeros (0, 2, "single"), 2), zeros (0, 1, "single")) +%!assert (sum (zeros (2, 2, 0, 3, "single")), zeros (1, 2, 0, 3, "single")) +%!assert (sum (zeros (2, 2, 0, 3, "single"), 2), zeros (2, 1, 0, 3, "single")) +%!assert (sum (zeros (2, 2, 0, 3, "single"), 3), zeros (2, 2, 1, 3, "single")) +%!assert (sum (zeros (2, 2, 0, 3, "single"), 4), zeros (2, 2, 0, "single")) +%!assert (sum (zeros (2, 2, 0, 3, "single"), 7), zeros (2, 2, 0, 3, "single")) + +%!error sum () */ DEFUN (sumsq, args, , @@ -2885,24 +2870,22 @@ } /* - -%!assert(sumsq ([1, 2, 3]), 14) -%!assert(sumsq ([-1; -2; 4i]), 21); -%!assert(sumsq ([1, 2, 3; 2, 3, 4; 4i, 6i, 2]), [21, 49, 29]); - -%!assert(sumsq (single([1, 2, 3])), single(14)) -%!assert(sumsq (single([-1; -2; 4i])), single(21)); -%!assert(sumsq (single([1, 2, 3; 2, 3, 4; 4i, 6i, 2])), single([21, 49, 29])); - -%!error <Invalid call to sumsq> sumsq (); - -%!assert (sumsq ([1, 2; 3, 4], 1), [10, 20]); -%!assert (sumsq ([1, 2; 3, 4], 2), [5; 25]); - -%!assert (sumsq (single([1, 2; 3, 4]), 1), single([10, 20])); -%!assert (sumsq (single([1, 2; 3, 4]), 2), single([5; 25])); - - */ +%!assert (sumsq ([1, 2, 3]), 14) +%!assert (sumsq ([-1; -2; 4i]), 21) +%!assert (sumsq ([1, 2, 3; 2, 3, 4; 4i, 6i, 2]), [21, 49, 29]) + +%!assert (sumsq (single ([1, 2, 3])), single (14)) +%!assert (sumsq (single ([-1; -2; 4i])), single (21)) +%!assert (sumsq (single ([1, 2, 3; 2, 3, 4; 4i, 6i, 2])), single ([21, 49, 29])) + +%!assert (sumsq ([1, 2; 3, 4], 1), [10, 20]) +%!assert (sumsq ([1, 2; 3, 4], 2), [5; 25]) + +%!assert (sumsq (single ([1, 2; 3, 4]), 1), single ([10, 20])) +%!assert (sumsq (single ([1, 2; 3, 4]), 2), single ([5; 25])) + +%!error sumsq () +*/ DEFUN (islogical, args, , "-*- texinfo -*-\n\ @@ -2925,20 +2908,18 @@ DEFALIAS (isbool, islogical); /* - -%!assert (islogical(true), true) -%!assert (islogical(false), true) -%!assert (islogical([true, false]), true) -%!assert (islogical(1), false) -%!assert (islogical(1i), false) -%!assert (islogical([1,1]), false) -%!assert (islogical(single(1)), false) -%!assert (islogical(single(1i)), false) -%!assert (islogical(single([1,1])), false) -%!assert (islogical(sparse ([true, false])), true) -%!assert (islogical(sparse ([1, 0])), false) - - */ +%!assert (islogical (true), true) +%!assert (islogical (false), true) +%!assert (islogical ([true, false]), true) +%!assert (islogical (1), false) +%!assert (islogical (1i), false) +%!assert (islogical ([1,1]), false) +%!assert (islogical (single (1)), false) +%!assert (islogical (single (1i)), false) +%!assert (islogical (single ([1,1])), false) +%!assert (islogical (sparse ([true, false])), true) +%!assert (islogical (sparse ([1, 0])), false) +*/ DEFUN (isinteger, args, , "-*- texinfo -*-\n\ @@ -3343,21 +3324,19 @@ } /* - -%!assert (isnumeric(1), true) -%!assert (isnumeric(1i), true) -%!assert (isnumeric([1,1]), true) -%!assert (isnumeric(single(1)), true) -%!assert (isnumeric(single(1i)), true) -%!assert (isnumeric(single([1,1])), true) -%!assert (isnumeric(int8(1)), true) -%!assert (isnumeric(uint8([1,1])), true) -%!assert (isnumeric("Hello World"), false) -%!assert (isnumeric(true), false) -%!assert (isnumeric(false), false) -%!assert (isnumeric([true, false]), false) -%!assert (isnumeric(sparse ([true, false])), false) - +%!assert (isnumeric (1), true) +%!assert (isnumeric (1i), true) +%!assert (isnumeric ([1,1]), true) +%!assert (isnumeric (single (1)), true) +%!assert (isnumeric (single (1i)), true) +%!assert (isnumeric (single ([1,1])), true) +%!assert (isnumeric (int8 (1)), true) +%!assert (isnumeric (uint8 ([1,1])), true) +%!assert (isnumeric ("Hello World"), false) +%!assert (isnumeric (true), false) +%!assert (isnumeric (false), false) +%!assert (isnumeric ([true, false]), false) +%!assert (isnumeric (sparse ([true, false])), false) */ DEFUN (ismatrix, args, , @@ -3385,30 +3364,28 @@ } /* - -%!assert(ismatrix ([])); -%!assert(ismatrix (1)); -%!assert(ismatrix ([1, 2, 3])); -%!assert(ismatrix ([1, 2; 3, 4])); -%!assert(ismatrix (zeros (3, 2, 4))); - -%!assert(ismatrix (single([]))); -%!assert(ismatrix (single(1))); -%!assert(ismatrix (single([1, 2, 3]))); -%!assert(ismatrix (single([1, 2; 3, 4]))); - -%!assert(ismatrix ("t")); -%!assert(ismatrix ("test")); -%!assert(ismatrix (["test"; "ing"])); +%!assert (ismatrix ([])) +%!assert (ismatrix (1)) +%!assert (ismatrix ([1, 2, 3])) +%!assert (ismatrix ([1, 2; 3, 4])) +%!assert (ismatrix (zeros (3, 2, 4))) + +%!assert (ismatrix (single ([]))) +%!assert (ismatrix (single (1))) +%!assert (ismatrix (single ([1, 2, 3]))) +%!assert (ismatrix (single ([1, 2; 3, 4]))) + +%!assert (ismatrix ("t")) +%!assert (ismatrix ("test")) +%!assert (ismatrix (["test"; "ing"])) %!test %! s.a = 1; -%! assert(ismatrix (s), false); - -%!error <Invalid call to ismatrix> ismatrix (); -%!error <Invalid call to ismatrix> ismatrix ([1, 2; 3, 4], 2); - - */ +%! assert (ismatrix (s), false); + +%!error ismatrix () +%!error ismatrix ([1, 2; 3, 4], 2) +*/ static octave_value fill_matrix (const octave_value_list& args, int val, const char *fcn) @@ -3862,23 +3839,21 @@ } /* - -%!assert(ones (3), [1, 1, 1; 1, 1, 1; 1, 1, 1]); -%!assert(ones (2, 3), [1, 1, 1; 1, 1, 1]); -%!assert(ones (3, 2), [1, 1; 1, 1; 1, 1]); -%!assert(size (ones (3, 4, 5)), [3, 4, 5]); - -%!assert(ones (3,'single'), single([1, 1, 1; 1, 1, 1; 1, 1, 1])); -%!assert(ones (2, 3,'single'), single([1, 1, 1; 1, 1, 1])); -%!assert(ones (3, 2,'single'), single([1, 1; 1, 1; 1, 1])); -%!assert(size (ones (3, 4, 5, 'single')), [3, 4, 5]); - -%!assert(ones (3,'int8'), int8([1, 1, 1; 1, 1, 1; 1, 1, 1])); -%!assert(ones (2, 3,'int8'), int8([1, 1, 1; 1, 1, 1])); -%!assert(ones (3, 2,'int8'), int8([1, 1; 1, 1; 1, 1])); -%!assert(size (ones (3, 4, 5, 'int8')), [3, 4, 5]); - - */ +%!assert (ones (3), [1, 1, 1; 1, 1, 1; 1, 1, 1]) +%!assert (ones (2, 3), [1, 1, 1; 1, 1, 1]) +%!assert (ones (3, 2), [1, 1; 1, 1; 1, 1]) +%!assert (size (ones (3, 4, 5)), [3, 4, 5]) + +%!assert (ones (3, "single"), single ([1, 1, 1; 1, 1, 1; 1, 1, 1])) +%!assert (ones (2, 3, "single"), single ([1, 1, 1; 1, 1, 1])) +%!assert (ones (3, 2, "single"), single ([1, 1; 1, 1; 1, 1])) +%!assert (size (ones (3, 4, 5, "single")), [3, 4, 5]) + +%!assert (ones (3, "int8"), int8 ([1, 1, 1; 1, 1, 1; 1, 1, 1])) +%!assert (ones (2, 3, "int8"), int8 ([1, 1, 1; 1, 1, 1])) +%!assert (ones (3, 2, "int8"), int8 ([1, 1; 1, 1; 1, 1])) +%!assert (size (ones (3, 4, 5, "int8")), [3, 4, 5]) +*/ DEFUN (zeros, args, , "-*- texinfo -*-\n\ @@ -3906,23 +3881,21 @@ } /* - -%!assert(zeros (3), [0, 0, 0; 0, 0, 0; 0, 0, 0]); -%!assert(zeros (2, 3), [0, 0, 0; 0, 0, 0]); -%!assert(zeros (3, 2), [0, 0; 0, 0; 0, 0]); -%!assert(size (zeros (3, 4, 5)), [3, 4, 5]); - -%!assert(zeros (3,'single'), single([0, 0, 0; 0, 0, 0; 0, 0, 0])); -%!assert(zeros (2, 3,'single'), single([0, 0, 0; 0, 0, 0])); -%!assert(zeros (3, 2,'single'), single([0, 0; 0, 0; 0, 0])); -%!assert(size (zeros (3, 4, 5, 'single')), [3, 4, 5]); - -%!assert(zeros (3,'int8'), int8([0, 0, 0; 0, 0, 0; 0, 0, 0])); -%!assert(zeros (2, 3,'int8'), int8([0, 0, 0; 0, 0, 0])); -%!assert(zeros (3, 2,'int8'), int8([0, 0; 0, 0; 0, 0])); -%!assert(size (zeros (3, 4, 5, 'int8')), [3, 4, 5]); - - */ +%!assert (zeros (3), [0, 0, 0; 0, 0, 0; 0, 0, 0]) +%!assert (zeros (2, 3), [0, 0, 0; 0, 0, 0]) +%!assert (zeros (3, 2), [0, 0; 0, 0; 0, 0]) +%!assert (size (zeros (3, 4, 5)), [3, 4, 5]) + +%!assert (zeros (3, "single"), single ([0, 0, 0; 0, 0, 0; 0, 0, 0])) +%!assert (zeros (2, 3, "single"), single ([0, 0, 0; 0, 0, 0])) +%!assert (zeros (3, 2, "single"), single ([0, 0; 0, 0; 0, 0])) +%!assert (size (zeros (3, 4, 5, "single")), [3, 4, 5]) + +%!assert (zeros (3, "int8"), int8 ([0, 0, 0; 0, 0, 0; 0, 0, 0])) +%!assert (zeros (2, 3, "int8"), int8 ([0, 0, 0; 0, 0, 0])) +%!assert (zeros (3, 2, "int8"), int8 ([0, 0; 0, 0; 0, 0])) +%!assert (size (zeros (3, 4, 5, "int8")), [3, 4, 5]) +*/ DEFUN (Inf, args, , "-*- texinfo -*-\n\ @@ -3965,23 +3938,21 @@ DEFALIAS (inf, Inf); /* - -%!assert(inf (3), [Inf, Inf, Inf; Inf, Inf, Inf; Inf, Inf, Inf]); -%!assert(inf (2, 3), [Inf, Inf, Inf; Inf, Inf, Inf]); -%!assert(inf (3, 2), [Inf, Inf; Inf, Inf; Inf, Inf]); -%!assert(size (inf (3, 4, 5)), [3, 4, 5]); - -%!assert(inf (3,'single'), single([Inf, Inf, Inf; Inf, Inf, Inf; Inf, Inf, Inf])); -%!assert(inf (2, 3,'single'), single([Inf, Inf, Inf; Inf, Inf, Inf])); -%!assert(inf (3, 2,'single'), single([Inf, Inf; Inf, Inf; Inf, Inf])); -%!assert(size (inf (3, 4, 5, 'single')), [3, 4, 5]); - -%!error(inf (3,'int8')); -%!error(inf (2, 3,'int8')); -%!error(inf (3, 2,'int8')); -%!error(inf (3, 4, 5, 'int8')); - - */ +%!assert (inf (3), [Inf, Inf, Inf; Inf, Inf, Inf; Inf, Inf, Inf]) +%!assert (inf (2, 3), [Inf, Inf, Inf; Inf, Inf, Inf]) +%!assert (inf (3, 2), [Inf, Inf; Inf, Inf; Inf, Inf]) +%!assert (size (inf (3, 4, 5)), [3, 4, 5]) + +%!assert (inf (3, "single"), single ([Inf, Inf, Inf; Inf, Inf, Inf; Inf, Inf, Inf])) +%!assert (inf (2, 3, "single"), single ([Inf, Inf, Inf; Inf, Inf, Inf])) +%!assert (inf (3, 2, "single"), single ([Inf, Inf; Inf, Inf; Inf, Inf])) +%!assert (size (inf (3, 4, 5, "single")), [3, 4, 5]) + +%!error (inf (3, "int8")) +%!error (inf (2, 3, "int8")) +%!error (inf (3, 2, "int8")) +%!error (inf (3, 4, 5, "int8")) +*/ DEFUN (NaN, args, , "-*- texinfo -*-\n\ @@ -4026,22 +3997,21 @@ DEFALIAS (nan, NaN); /* -%!assert(NaN (3), [NaN, NaN, NaN; NaN, NaN, NaN; NaN, NaN, NaN]); -%!assert(NaN (2, 3), [NaN, NaN, NaN; NaN, NaN, NaN]); -%!assert(NaN (3, 2), [NaN, NaN; NaN, NaN; NaN, NaN]); -%!assert(size (NaN (3, 4, 5)), [3, 4, 5]); - -%!assert(NaN (3,'single'), single([NaN, NaN, NaN; NaN, NaN, NaN; NaN, NaN, NaN])); -%!assert(NaN (2, 3,'single'), single([NaN, NaN, NaN; NaN, NaN, NaN])); -%!assert(NaN (3, 2,'single'), single([NaN, NaN; NaN, NaN; NaN, NaN])); -%!assert(size (NaN (3, 4, 5, 'single')), [3, 4, 5]); - -%!error(NaN (3,'int8')); -%!error(NaN (2, 3,'int8')); -%!error(NaN (3, 2,'int8')); -%!error(NaN (3, 4, 5, 'int8')); - - */ +%!assert (NaN (3), [NaN, NaN, NaN; NaN, NaN, NaN; NaN, NaN, NaN]) +%!assert (NaN (2, 3), [NaN, NaN, NaN; NaN, NaN, NaN]) +%!assert (NaN (3, 2), [NaN, NaN; NaN, NaN; NaN, NaN]) +%!assert (size (NaN (3, 4, 5)), [3, 4, 5]) + +%!assert (NaN (3, "single"), single ([NaN, NaN, NaN; NaN, NaN, NaN; NaN, NaN, NaN])) +%!assert (NaN (2, 3, "single"), single ([NaN, NaN, NaN; NaN, NaN, NaN])) +%!assert (NaN (3, 2, "single"), single ([NaN, NaN; NaN, NaN; NaN, NaN])) +%!assert (size (NaN (3, 4, 5, "single")), [3, 4, 5]) + +%!error (NaN (3, "int8")) +%!error (NaN (2, 3, "int8")) +%!error (NaN (3, 2, "int8")) +%!error (NaN (3, 4, 5, "int8")) +*/ DEFUN (e, args, , "-*- texinfo -*-\n\ @@ -4171,29 +4141,26 @@ } /* - -%!assert(eps(1/2),2^(-53)) -%!assert(eps(1),2^(-52)) -%!assert(eps(2),2^(-51)) -%!assert(eps(realmax),2^971) -%!assert(eps(0),2^(-1074)) -%!assert(eps(realmin/2),2^(-1074)) -%!assert(eps(realmin/16),2^(-1074)) -%!assert(eps(Inf),NaN) -%!assert(eps(NaN),NaN) -%!assert(eps(single(1/2)),single(2^(-24))) -%!assert(eps(single(1)),single(2^(-23))) -%!assert(eps(single(2)),single(2^(-22))) -%!assert(eps(realmax('single')),single(2^104)) -%!assert(eps(single(0)),single(2^(-149))) -%!assert(eps(realmin('single')/2),single(2^(-149))) -%!assert(eps(realmin('single')/16),single(2^(-149))) -%!assert(eps(single(Inf)),single(NaN)) -%!assert(eps(single(NaN)),single(NaN)) - +%!assert (eps (1/2), 2^(-53)) +%!assert (eps (1), 2^(-52)) +%!assert (eps (2), 2^(-51)) +%!assert (eps (realmax), 2^971) +%!assert (eps (0), 2^(-1074)) +%!assert (eps (realmin/2), 2^(-1074)) +%!assert (eps (realmin/16), 2^(-1074)) +%!assert (eps (Inf), NaN) +%!assert (eps (NaN), NaN) +%!assert (eps (single (1/2)), single (2^(-24))) +%!assert (eps (single (1)), single (2^(-23))) +%!assert (eps (single (2)), single (2^(-22))) +%!assert (eps (realmax ("single")), single (2^104)) +%!assert (eps (single (0)), single (2^(-149))) +%!assert (eps (realmin ("single")/2), single (2^(-149))) +%!assert (eps (realmin ("single")/16), single (2^(-149))) +%!assert (eps (single (Inf)), single (NaN)) +%!assert (eps (single (NaN)), single (NaN)) */ - DEFUN (pi, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} pi\n\ @@ -4368,11 +4335,9 @@ } /* - -%!assert(single(NA('double')),NA('single')) -%!assert(double(NA('single')),NA('double')) - - */ +%!assert (single (NA ("double")), NA ("single")) +%!assert (double (NA ("single")), NA ("double")) +*/ DEFUN (false, args, , "-*- texinfo -*-\n\ @@ -4621,21 +4586,18 @@ return retval; } - /* - -%!assert (full (eye(3)), [1, 0, 0; 0, 1, 0; 0, 0, 1]); -%!assert (full (eye(2, 3)), [1, 0, 0; 0, 1, 0]); - -%!assert (full (eye(3,'single')), single([1, 0, 0; 0, 1, 0; 0, 0, 1])); -%!assert (full (eye(2, 3,'single')), single([1, 0, 0; 0, 1, 0])); - -%!assert (eye(3,'int8'), int8([1, 0, 0; 0, 1, 0; 0, 0, 1])); -%!assert (eye(2, 3,'int8'), int8([1, 0, 0; 0, 1, 0])); - -%!error <Invalid call to eye> eye (1, 2, 3); - - */ +%!assert (full (eye (3)), [1, 0, 0; 0, 1, 0; 0, 0, 1]) +%!assert (full (eye (2, 3)), [1, 0, 0; 0, 1, 0]) + +%!assert (full (eye (3,"single")), single ([1, 0, 0; 0, 1, 0; 0, 0, 1])) +%!assert (full (eye (2, 3,"single")), single ([1, 0, 0; 0, 1, 0])) + +%!assert (eye (3, "int8"), int8 ([1, 0, 0; 0, 1, 0; 0, 0, 1])) +%!assert (eye (2, 3, "int8"), int8 ([1, 0, 0; 0, 1, 0])) + +%!error eye (1, 2, 3) +*/ template <class MT> static octave_value @@ -4744,24 +4706,20 @@ /* - %!test %! x1 = linspace (1, 2); %! x2 = linspace (1, 2, 10); %! x3 = linspace (1, -2, 10); -%! assert((size (x1) == [1, 100] && x1(1) == 1 && x1(100) == 2 -%! && size (x2) == [1, 10] && x2(1) == 1 && x2(10) == 2 -%! && size (x3) == [1, 10] && x3(1) == 1 && x3(10) == -2)); - - -% assert(linspace ([1, 2; 3, 4], 5, 6), linspace (1, 5, 6)); - -%!error <Invalid call to linspace> linspace (); -%!error <Invalid call to linspace> linspace (1, 2, 3, 4); - -%!test -%! fail("linspace ([1, 2; 3, 4], 5, 6)","warning"); - +%! assert (size (x1) == [1, 100] && x1(1) == 1 && x1(100) == 2); +%! assert (size (x2) == [1, 10] && x2(1) == 1 && x2(10) == 2); +%! assert (size (x3) == [1, 10] && x3(1) == 1 && x3(10) == -2); + +%#assert (linspace ([1, 2; 3, 4], 5, 6), linspace (1, 5, 6)) + +%!fail ("linspace ([1, 2; 3, 4], 5, 6)", "warning") + +%!error linspace () +%!error linspace (1, 2, 3, 4) */ // FIXME -- should accept dimensions as separate args for N-d @@ -4977,25 +4935,23 @@ } /* - -%!assert(size (reshape (ones (4, 4), 2, 8)), [2, 8]) -%!assert(size (reshape (ones (4, 4), 8, 2)), [8, 2]) -%!assert(size (reshape (ones (15, 4), 1, 60)), [1, 60]) -%!assert(size (reshape (ones (15, 4), 60, 1)), [60, 1]) - -%!assert(size (reshape (ones (4, 4, 'single'), 2, 8)), [2, 8]) -%!assert(size (reshape (ones (4, 4, 'single'), 8, 2)), [8, 2]) -%!assert(size (reshape (ones (15, 4, 'single'), 1, 60)), [1, 60]) -%!assert(size (reshape (ones (15, 4, 'single'), 60, 1)), [60, 1]) +%!assert (size (reshape (ones (4, 4), 2, 8)), [2, 8]) +%!assert (size (reshape (ones (4, 4), 8, 2)), [8, 2]) +%!assert (size (reshape (ones (15, 4), 1, 60)), [1, 60]) +%!assert (size (reshape (ones (15, 4), 60, 1)), [60, 1]) + +%!assert (size (reshape (ones (4, 4, "single"), 2, 8)), [2, 8]) +%!assert (size (reshape (ones (4, 4, "single"), 8, 2)), [8, 2]) +%!assert (size (reshape (ones (15, 4, "single"), 1, 60)), [1, 60]) +%!assert (size (reshape (ones (15, 4, "single"), 60, 1)), [60, 1]) %!test %! s.a = 1; -%! fail("reshape (s, 2, 3)"); - -%!error <Invalid call to reshape> reshape (); -%!error reshape (1, 2, 3, 4); - - */ +%! fail ("reshape (s, 2, 3)"); + +%!error reshape () +%!error reshape (1, 2, 3, 4) +*/ DEFUN (vec, args, , "-*- texinfo -*-\n\ @@ -5049,20 +5005,18 @@ } /* - -%!assert(vec ([1, 2; 3, 4]), [1; 3; 2; 4]) -%!assert(vec ([1, 3, 2, 4]), [1; 3; 2; 4]); -%!assert(vec ([1, 2, 3, 4], 2), [1, 2, 3, 4]); -%!assert(vec ([1, 2; 3, 4]), vec ([1, 2; 3, 4], 1)); -%!assert(vec ([1, 2; 3, 4], 1), [1; 3; 2; 4]); -%!assert(vec ([1, 2; 3, 4], 2), [1, 3, 2, 4]); -%!assert(vec ([1, 3; 2, 4], 3), reshape ([1, 2, 3, 4], 1, 1, 4)); -%!assert(vec ([1, 3; 2, 4], 3), shiftdim (vec ([1, 3; 2, 4]), -2)); - -%!error vec (); -%!error vec (1, 2, 3); -%!error vec ([1, 2; 3, 4], 0); - +%!assert (vec ([1, 2; 3, 4]), [1; 3; 2; 4]) +%!assert (vec ([1, 3, 2, 4]), [1; 3; 2; 4]) +%!assert (vec ([1, 2, 3, 4], 2), [1, 2, 3, 4]) +%!assert (vec ([1, 2; 3, 4]), vec ([1, 2; 3, 4], 1)) +%!assert (vec ([1, 2; 3, 4], 1), [1; 3; 2; 4]) +%!assert (vec ([1, 2; 3, 4], 2), [1, 3, 2, 4]) +%!assert (vec ([1, 3; 2, 4], 3), reshape ([1, 2, 3, 4], 1, 1, 4)) +%!assert (vec ([1, 3; 2, 4], 3), shiftdim (vec ([1, 3; 2, 4]), -2)) + +%!error vec () +%!error vec (1, 2, 3) +%!error vec ([1, 2; 3, 4], 0) */ DEFUN (squeeze, args, , @@ -5227,53 +5181,53 @@ /* %!shared x %! x = [1, -3, 4, 5, -7]; -%!assert(norm(x,1), 20); -%!assert(norm(x,2), 10); -%!assert(norm(x,3), 8.24257059961711, -4*eps); -%!assert(norm(x,Inf), 7); -%!assert(norm(x,-Inf), 1); -%!assert(norm(x,"inf"), 7); -%!assert(norm(x,"fro"), 10, -eps); -%!assert(norm(x), 10); -%!assert(norm([1e200, 1]), 1e200); -%!assert(norm([3+4i, 3-4i, sqrt(31)]), 9, -4*eps); +%!assert (norm (x,1), 20) +%!assert (norm (x,2), 10) +%!assert (norm (x,3), 8.24257059961711, -4*eps) +%!assert (norm (x,Inf), 7) +%!assert (norm (x,-Inf), 1) +%!assert (norm (x,"inf"), 7) +%!assert (norm (x,"fro"), 10, -eps) +%!assert (norm (x), 10) +%!assert (norm ([1e200, 1]), 1e200) +%!assert (norm ([3+4i, 3-4i, sqrt(31)]), 9, -4*eps) %!shared m %! m = magic (4); -%!assert(norm(m,1), 34); -%!assert(norm(m,2), 34, -eps); -%!assert(norm(m,Inf), 34); -%!assert(norm(m,"inf"), 34); +%!assert (norm (m,1), 34) +%!assert (norm (m,2), 34, -eps) +%!assert (norm (m,Inf), 34) +%!assert (norm (m,"inf"), 34) %!shared m2, flo, fhi %! m2 = [1,2;3,4]; %! flo = 1e-300; %! fhi = 1e+300; -%!assert (norm(flo*m2,"fro"), sqrt(30)*flo, -eps) -%!assert (norm(fhi*m2,"fro"), sqrt(30)*fhi, -eps) +%!assert (norm (flo*m2,"fro"), sqrt (30)*flo, -eps) +%!assert (norm (fhi*m2,"fro"), sqrt (30)*fhi, -eps) %!shared x -%! x = single([1, -3, 4, 5, -7]); -%!assert(norm(x,1), single(20)); -%!assert(norm(x,2), single(10)); -%!assert(norm(x,3), single(8.24257059961711), -4*eps('single')); -%!assert(norm(x,Inf), single(7)); -%!assert(norm(x,-Inf), single(1)); -%!assert(norm(x,"inf"), single(7)); -%!assert(norm(x,"fro"), single(10), -eps('single')); -%!assert(norm(x), single(10)); -%!assert(norm(single([1e200, 1])), single(1e200)); -%!assert(norm(single([3+4i, 3-4i, sqrt(31)])), single(9), -4*eps('single')); +%! x = single ([1, -3, 4, 5, -7]); +%!assert (norm (x,1), single (20)) +%!assert (norm (x,2), single (10)) +%!assert (norm (x,3), single (8.24257059961711), -4*eps ("single")) +%!assert (norm (x,Inf), single (7)) +%!assert (norm (x,-Inf), single (1)) +%!assert (norm (x,"inf"), single (7)) +%!assert (norm (x,"fro"), single (10), -eps ("single")) +%!assert (norm (x), single (10)) +%!assert (norm (single ([1e200, 1])), single (1e200)) +%!assert (norm (single ([3+4i, 3-4i, sqrt(31)])), single (9), -4*eps ("single")) %!shared m -%! m = single(magic (4)); -%!assert(norm(m,1), single(34)); -%!assert(norm(m,2), single(34), -eps('single')); -%!assert(norm(m,Inf), single(34)); -%!assert(norm(m,"inf"), single(34)); +%! m = single (magic (4)); +%!assert (norm (m,1), single (34)) +%!assert (norm (m,2), single (34), -eps ("single")) +%!assert (norm (m,Inf), single (34)) +%!assert (norm (m,"inf"), single (34)) %!shared m2, flo, fhi -%! m2 = single([1,2;3,4]); -%! flo = single(1e-300); -%! fhi = single(1e+300); -%!assert (norm(flo*m2,"fro"), single(sqrt(30)*flo), -eps('single')) -%!assert (norm(fhi*m2,"fro"), single(sqrt(30)*fhi), -eps('single')) +%! m2 = single ([1,2;3,4]); +%! flo = single (1e-300); +%! fhi = single (1e+300); +%!assert (norm (flo*m2,"fro"), single (sqrt (30)*flo), -eps ("single")) +%!assert (norm (fhi*m2,"fro"), single (sqrt (30)*fhi), -eps ("single")) */ static octave_value @@ -5330,25 +5284,23 @@ } /* - -%!assert (2.', 2); -%!assert (2i.',2i); -%!assert ([1:4].',[1;2;3;4]); -%!assert ([1;2;3;4].',[1:4]); -%!assert ([1,2;3,4].',[1,3;2,4]); -%!assert ([1,2i;3,4].',[1,3;2i,4]); - -%!assert (transpose ([1,2;3,4]),[1,3;2,4]); - -%!assert (single(2).', single(2)); -%!assert (single(2i).',single(2i)); -%!assert (single([1:4]).',single([1;2;3;4])); -%!assert (single([1;2;3;4]).',single([1:4])); -%!assert (single([1,2;3,4]).',single([1,3;2,4])); -%!assert (single([1,2i;3,4]).',single([1,3;2i,4])); - -%!assert (transpose (single([1,2;3,4])),single([1,3;2,4])); - +%!assert (2.', 2) +%!assert (2i.', 2i) +%!assert ([1:4].', [1;2;3;4]) +%!assert ([1;2;3;4].', [1:4]) +%!assert ([1,2;3,4].', [1,3;2,4]) +%!assert ([1,2i;3,4].', [1,3;2i,4]) + +%!assert (transpose ([1,2;3,4]), [1,3;2,4]) + +%!assert (single (2).', single (2)) +%!assert (single (2i).', single (2i)) +%!assert (single ([1:4]).', single ([1;2;3;4])) +%!assert (single ([1;2;3;4]).', single ([1:4])) +%!assert (single ([1,2;3,4]).', single ([1,3;2,4])) +%!assert (single ([1,2i;3,4]).', single ([1,3;2i,4])) + +%!assert (transpose (single ([1,2;3,4])), single ([1,3;2,4])) */ DEFUN (ctranspose, args, , @@ -5363,25 +5315,23 @@ } /* - -%!assert (2', 2); -%!assert (2i',-2i); -%!assert ([1:4]',[1;2;3;4]); -%!assert ([1;2;3;4]',[1:4]); -%!assert ([1,2;3,4]',[1,3;2,4]); -%!assert ([1,2i;3,4]',[1,3;-2i,4]); - -%!assert (ctranspose ([1,2i;3,4]),[1,3;-2i,4]); - -%!assert (single(2)', single(2)); -%!assert (single(2i)',single(-2i)); -%!assert (single([1:4])',single([1;2;3;4])); -%!assert (single([1;2;3;4])',single([1:4])); -%!assert (single([1,2;3,4])',single([1,3;2,4])); -%!assert (single([1,2i;3,4])',single([1,3;-2i,4])); - -%!assert (ctranspose (single([1,2i;3,4])),single([1,3;-2i,4])); - +%!assert (2', 2) +%!assert (2i', -2i) +%!assert ([1:4]', [1;2;3;4]) +%!assert ([1;2;3;4]', [1:4]) +%!assert ([1,2;3,4]', [1,3;2,4]) +%!assert ([1,2i;3,4]', [1,3;-2i,4]) + +%!assert (ctranspose ([1,2i;3,4]), [1,3;-2i,4]) + +%!assert (single (2)', single (2)) +%!assert (single (2i)', single (-2i)) +%!assert (single ([1:4])', single ([1;2;3;4])) +%!assert (single ([1;2;3;4])', single ([1:4])) +%!assert (single ([1,2;3,4])', single ([1,3;2,4])) +%!assert (single ([1,2i;3,4])', single ([1,3;-2i,4])) + +%!assert (ctranspose (single ([1,2i;3,4])), single ([1,3;-2i,4])) */ static octave_value @@ -6004,8 +5954,7 @@ } /* - -%% Double +## Double %!assert (sort ([NaN, 1, -1, 2, Inf]), [-1, 1, 2, Inf, NaN]) %!assert (sort ([NaN, 1, -1, 2, Inf], 1), [NaN, 1, -1, 2, Inf]) %!assert (sort ([NaN, 1, -1, 2, Inf], 2), [-1, 1, 2, Inf, NaN]) @@ -6021,10 +5970,10 @@ %!test %! [v, i] = sort ([NaN, 1, -1, Inf, 1]); -%! assert (v, [-1, 1, 1, Inf, NaN]) -%! assert (i, [3, 2, 5, 4, 1]) - -%% Complex +%! assert (v, [-1, 1, 1, Inf, NaN]); +%! assert (i, [3, 2, 5, 4, 1]); + +## Complex %!assert (sort ([NaN, 1i, -1, 2, Inf]), [1i, -1, 2, Inf, NaN]) %!assert (sort ([NaN, 1i, -1, 2, Inf], 1), [NaN, 1i, -1, 2, Inf]) %!assert (sort ([NaN, 1i, -1, 2, Inf], 2), [1i, -1, 2, Inf, NaN]) @@ -6040,48 +5989,48 @@ %!test %! [v, i] = sort ([NaN, 1i, -1, Inf, 1, 1i]); -%! assert (v, [1, 1i, 1i, -1, Inf, NaN]) -%! assert (i, [5, 2, 6, 3, 4, 1]) - -%% Single -%!assert (sort (single([NaN, 1, -1, 2, Inf])), single([-1, 1, 2, Inf, NaN])) -%!assert (sort (single([NaN, 1, -1, 2, Inf]), 1), single([NaN, 1, -1, 2, Inf])) -%!assert (sort (single([NaN, 1, -1, 2, Inf]), 2), single([-1, 1, 2, Inf, NaN])) -%!assert (sort (single([NaN, 1, -1, 2, Inf]), 3), single([NaN, 1, -1, 2, Inf])) -%!assert (sort (single([NaN, 1, -1, 2, Inf]), "ascend"), single([-1, 1, 2, Inf, NaN])) -%!assert (sort (single([NaN, 1, -1, 2, Inf]), 2, "ascend"), single([-1, 1, 2, Inf, NaN])) -%!assert (sort (single([NaN, 1, -1, 2, Inf]), "descend"), single([NaN, Inf, 2, 1, -1])) -%!assert (sort (single([NaN, 1, -1, 2, Inf]), 2, "descend"), single([NaN, Inf, 2, 1, -1])) -%!assert (sort (single([3, 1, 7, 5; 8, 2, 6, 4])), single([3, 1, 6, 4; 8, 2, 7, 5])) -%!assert (sort (single([3, 1, 7, 5; 8, 2, 6, 4]), 1), single([3, 1, 6, 4; 8, 2, 7, 5])) -%!assert (sort (single([3, 1, 7, 5; 8, 2, 6, 4]), 2), single([1, 3, 5, 7; 2, 4, 6, 8])) -%!assert (sort (single(1)), single(1)) +%! assert (v, [1, 1i, 1i, -1, Inf, NaN]); +%! assert (i, [5, 2, 6, 3, 4, 1]); + +## Single +%!assert (sort (single ([NaN, 1, -1, 2, Inf])), single ([-1, 1, 2, Inf, NaN])) +%!assert (sort (single ([NaN, 1, -1, 2, Inf]), 1), single ([NaN, 1, -1, 2, Inf])) +%!assert (sort (single ([NaN, 1, -1, 2, Inf]), 2), single ([-1, 1, 2, Inf, NaN])) +%!assert (sort (single ([NaN, 1, -1, 2, Inf]), 3), single ([NaN, 1, -1, 2, Inf])) +%!assert (sort (single ([NaN, 1, -1, 2, Inf]), "ascend"), single ([-1, 1, 2, Inf, NaN])) +%!assert (sort (single ([NaN, 1, -1, 2, Inf]), 2, "ascend"), single ([-1, 1, 2, Inf, NaN])) +%!assert (sort (single ([NaN, 1, -1, 2, Inf]), "descend"), single ([NaN, Inf, 2, 1, -1])) +%!assert (sort (single ([NaN, 1, -1, 2, Inf]), 2, "descend"), single ([NaN, Inf, 2, 1, -1])) +%!assert (sort (single ([3, 1, 7, 5; 8, 2, 6, 4])), single ([3, 1, 6, 4; 8, 2, 7, 5])) +%!assert (sort (single ([3, 1, 7, 5; 8, 2, 6, 4]), 1), single ([3, 1, 6, 4; 8, 2, 7, 5])) +%!assert (sort (single ([3, 1, 7, 5; 8, 2, 6, 4]), 2), single ([1, 3, 5, 7; 2, 4, 6, 8])) +%!assert (sort (single (1)), single (1)) %!test -%! [v, i] = sort (single([NaN, 1, -1, Inf, 1])); -%! assert (v, single([-1, 1, 1, Inf, NaN])) -%! assert (i, [3, 2, 5, 4, 1]) - -%% Single Complex -%!assert (sort (single([NaN, 1i, -1, 2, Inf])), single([1i, -1, 2, Inf, NaN])) -%!assert (sort (single([NaN, 1i, -1, 2, Inf]), 1), single([NaN, 1i, -1, 2, Inf])) -%!assert (sort (single([NaN, 1i, -1, 2, Inf]), 2), single([1i, -1, 2, Inf, NaN])) -%!assert (sort (single([NaN, 1i, -1, 2, Inf]), 3), single([NaN, 1i, -1, 2, Inf])) -%!assert (sort (single([NaN, 1i, -1, 2, Inf]), "ascend"), single([1i, -1, 2, Inf, NaN])) -%!assert (sort (single([NaN, 1i, -1, 2, Inf]), 2, "ascend"), single([1i, -1, 2, Inf, NaN])) -%!assert (sort (single([NaN, 1i, -1, 2, Inf]), "descend"), single([NaN, Inf, 2, -1, 1i])) -%!assert (sort (single([NaN, 1i, -1, 2, Inf]), 2, "descend"), single([NaN, Inf, 2, -1, 1i])) -%!assert (sort (single([3, 1i, 7, 5; 8, 2, 6, 4])), single([3, 1i, 6, 4; 8, 2, 7, 5])) -%!assert (sort (single([3, 1i, 7, 5; 8, 2, 6, 4]), 1), single([3, 1i, 6, 4; 8, 2, 7, 5])) -%!assert (sort (single([3, 1i, 7, 5; 8, 2, 6, 4]), 2), single([1i, 3, 5, 7; 2, 4, 6, 8])) -%!assert (sort (single(1i)),single( 1i)) +%! [v, i] = sort (single ([NaN, 1, -1, Inf, 1])); +%! assert (v, single ([-1, 1, 1, Inf, NaN])); +%! assert (i, [3, 2, 5, 4, 1]); + +## Single Complex +%!assert (sort (single ([NaN, 1i, -1, 2, Inf])), single ([1i, -1, 2, Inf, NaN])) +%!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 1), single ([NaN, 1i, -1, 2, Inf])) +%!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 2), single ([1i, -1, 2, Inf, NaN])) +%!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 3), single ([NaN, 1i, -1, 2, Inf])) +%!assert (sort (single ([NaN, 1i, -1, 2, Inf]), "ascend"), single ([1i, -1, 2, Inf, NaN])) +%!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 2, "ascend"), single ([1i, -1, 2, Inf, NaN])) +%!assert (sort (single ([NaN, 1i, -1, 2, Inf]), "descend"), single ([NaN, Inf, 2, -1, 1i])) +%!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 2, "descend"), single ([NaN, Inf, 2, -1, 1i])) +%!assert (sort (single ([3, 1i, 7, 5; 8, 2, 6, 4])), single ([3, 1i, 6, 4; 8, 2, 7, 5])) +%!assert (sort (single ([3, 1i, 7, 5; 8, 2, 6, 4]), 1), single ([3, 1i, 6, 4; 8, 2, 7, 5])) +%!assert (sort (single ([3, 1i, 7, 5; 8, 2, 6, 4]), 2), single ([1i, 3, 5, 7; 2, 4, 6, 8])) +%!assert (sort (single (1i)), single (1i)) %!test -%! [v, i] = sort (single([NaN, 1i, -1, Inf, 1, 1i])); -%! assert (v, single([1, 1i, 1i, -1, Inf, NaN])) -%! assert (i, [5, 2, 6, 3, 4, 1]) - -%% Bool +%! [v, i] = sort (single ([NaN, 1i, -1, Inf, 1, 1i])); +%! assert (v, single ([1, 1i, 1i, -1, Inf, NaN])); +%! assert (i, [5, 2, 6, 3, 4, 1]); + +## Bool %!assert (sort ([true, false, true, false]), [false, false, true, true]) %!assert (sort ([true, false, true, false], 1), [true, false, true, false]) %!assert (sort ([true, false, true, false], 2), [false, false, true, true]) @@ -6094,10 +6043,10 @@ %!test %! [v, i] = sort ([true, false, true, false]); -%! assert (v, [false, false, true, true]) -%! assert (i, [2, 4, 1, 3]) - -%% Sparse Double +%! assert (v, [false, false, true, true]); +%! assert (i, [2, 4, 1, 3]); + +## Sparse Double %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf])), sparse ([-1, 0, 0, 1, 2, Inf, NaN])) %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 1), sparse ([0, NaN, 1, 0, -1, 2, Inf])) %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2), sparse ([-1, 0, 0, 1, 2, Inf, NaN])) @@ -6109,17 +6058,17 @@ %!shared a %! a = randn (10, 10); -%! a (a < 0) = 0; +%! a(a < 0) = 0; %!assert (sort (sparse (a)), sparse (sort (a))) %!assert (sort (sparse (a), 1), sparse (sort (a, 1))) %!assert (sort (sparse (a), 2), sparse (sort (a, 2))) %!test %! [v, i] = sort (a); %! [vs, is] = sort (sparse (a)); -%! assert (vs, sparse (v)) -%! assert (is, i) - -%% Sparse Complex +%! assert (vs, sparse (v)); +%! assert (is, i); + +## Sparse Complex %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf])), sparse ([0, 0, 1i, -1, 2, Inf, NaN])) %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 1), sparse ([0, NaN, 1i, 0, -1, 2, Inf])) %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2), sparse ([0, 0, 1i, -1, 2, Inf, NaN])) @@ -6131,7 +6080,7 @@ %!shared a %! a = randn (10, 10); -%! a (a < 0) = 0; +%! a(a < 0) = 0; %! a = 1i * a; %!assert (sort (sparse (a)), sparse (sort (a))) %!assert (sort (sparse (a), 1), sparse (sort (a, 1))) @@ -6139,30 +6088,30 @@ %!test %! [v, i] = sort (a); %! [vs, is] = sort (sparse (a)); -%! assert (vs, sparse (v)) -%! assert (is, i) - -%% Sparse Bool +%! assert (vs, sparse (v)); +%! assert (is, i); + +## Sparse Bool %!assert (sort (sparse ([true, false, true, false])), sparse ([false, false, true, true])) -%!assert (sort (sparse([true, false, true, false]), 1), sparse ([true, false, true, false])) +%!assert (sort (sparse ([true, false, true, false]), 1), sparse ([true, false, true, false])) %!assert (sort (sparse ([true, false, true, false]), 2), sparse ([false, false, true, true])) %!assert (sort (sparse ([true, false, true, false]), 3), sparse ([true, false, true, false])) -%!assert (sort (sparse ([true, false, true, false]), "ascend"), sparse([false, false, true, true])) -%!assert (sort (sparse ([true, false, true, false]), 2, "ascend"), sparse([false, false, true, true])) +%!assert (sort (sparse ([true, false, true, false]), "ascend"), sparse ([false, false, true, true])) +%!assert (sort (sparse ([true, false, true, false]), 2, "ascend"), sparse ([false, false, true, true])) %!assert (sort (sparse ([true, false, true, false]), "descend"), sparse ([true, true, false, false])) -%!assert (sort (sparse ([true, false, true, false]), 2, "descend"), sparse([true, true, false, false])) +%!assert (sort (sparse ([true, false, true, false]), 2, "descend"), sparse ([true, true, false, false])) %!test -%! [v, i] = sort (sparse([true, false, true, false])); -%! assert (v, sparse([false, false, true, true])) -%! assert (i, [2, 4, 1, 3]) - -%% Cell string array +%! [v, i] = sort (sparse ([true, false, true, false])); +%! assert (v, sparse ([false, false, true, true])); +%! assert (i, [2, 4, 1, 3]); + +## Cell string array %!shared a, b, c %! a = {"Alice", "Cecile", "Eric", "Barry", "David"}; %! b = {"Alice", "Barry", "Cecile", "David", "Eric"}; %! c = {"Eric", "David", "Cecile", "Barry", "Alice"}; -%!assert (sort (a), b); +%!assert (sort (a), b) %!assert (sort (a, 1), a) %!assert (sort (a, 2), b) %!assert (sort (a, 3), a) @@ -6173,11 +6122,10 @@ %!test %! [v, i] = sort (a); -%! assert (i, [1, 4, 2, 5, 3]) - -%!error <Invalid call to sort> sort (); -%!error <Invalid call to sort> sort (1, 2, 3, 4); - +%! assert (i, [1, 4, 2, 5, 3]); + +%!error sort () +%!error sort (1, 2, 3, 4) */ // Sort the rows of the matrix @var{a} according to the order @@ -6340,32 +6288,32 @@ %! um = [3, 1; 2, 4]; %! sv = [1, 2, 3, 4]; %! uv = [2, 1, 4, 3]; -%!assert(issorted (sm, "rows")); -%!assert(!issorted (um, "rows")); -%!assert(issorted (sv)); -%!assert(!issorted (uv)); -%!assert(issorted (sv')); -%!assert(!issorted (uv')); -%!assert(issorted (sm, "rows", "ascending")); -%!assert(!issorted (um, "rows", "ascending")); -%!assert(issorted (sv, "ascending")); -%!assert(!issorted (uv, "ascending")); -%!assert(issorted (sv', "ascending")); -%!assert(!issorted (uv', "ascending")); -%!assert(!issorted (sm, "rows", "descending")); -%!assert(issorted (flipud (sm), "rows", "descending")); -%!assert(!issorted (sv, "descending")); -%!assert(issorted (fliplr (sv), "descending")); -%!assert(!issorted (sv', "descending")); -%!assert(issorted (fliplr (sv)', "descending")); -%!assert(!issorted (um, "rows", "either")); -%!assert(!issorted (uv, "either")); -%!assert(issorted (sm, "rows", "either")); -%!assert(issorted (flipud (sm), "rows", "either")); -%!assert(issorted (sv, "either")); -%!assert(issorted (fliplr (sv), "either")); -%!assert(issorted (sv', "either")); -%!assert(issorted (fliplr (sv)', "either")); +%!assert (issorted (sm, "rows")) +%!assert (!issorted (um, "rows")) +%!assert (issorted (sv)) +%!assert (!issorted (uv)) +%!assert (issorted (sv')) +%!assert (!issorted (uv')) +%!assert (issorted (sm, "rows", "ascending")) +%!assert (!issorted (um, "rows", "ascending")) +%!assert (issorted (sv, "ascending")) +%!assert (!issorted (uv, "ascending")) +%!assert (issorted (sv', "ascending")) +%!assert (!issorted (uv', "ascending")) +%!assert (!issorted (sm, "rows", "descending")) +%!assert (issorted (flipud (sm), "rows", "descending")) +%!assert (!issorted (sv, "descending")) +%!assert (issorted (fliplr (sv), "descending")) +%!assert (!issorted (sv', "descending")) +%!assert (issorted (fliplr (sv)', "descending")) +%!assert (!issorted (um, "rows", "either")) +%!assert (!issorted (uv, "either")) +%!assert (issorted (sm, "rows", "either")) +%!assert (issorted (flipud (sm), "rows", "either")) +%!assert (issorted (sv, "either")) +%!assert (issorted (fliplr (sv), "either")) +%!assert (issorted (sv', "either")) +%!assert (issorted (fliplr (sv)', "either")) */ DEFUN (nth_element, args, , @@ -7071,21 +7019,16 @@ } /* - %!assert (diff ([1, 2, 3, 4]), [1, 1, 1]) %!assert (diff ([1, 3, 7, 19], 2), [2, 8]) %!assert (diff ([1, 2; 5, 4; 8, 7; 9, 6; 3, 1]), [4, 2; 3, 3; 1, -1; -6, -5]) %!assert (diff ([1, 2; 5, 4; 8, 7; 9, 6; 3, 1], 3), [-1, -5; -5, 0]) -%!assert (isempty (diff (1))); - -%!error diff ([1, 2; 3, 4], -1); - -%!error diff ("foo"); - -%!error diff (); - -%!error diff (1, 2, 3, 4); - +%!assert (isempty (diff (1))) + +%!error diff () +%!error diff (1, 2, 3, 4) +%!error diff ("foo") +%!error diff ([1, 2; 3, 4], -1) */ template <class T>
--- a/src/defaults.cc +++ b/src/defaults.cc @@ -425,7 +425,6 @@ } /* -%!error (EDITOR (1, 2)); %!test %! orig_val = EDITOR (); %! old_val = EDITOR ("X"); @@ -433,6 +432,8 @@ %! assert (EDITOR (), "X"); %! EDITOR (orig_val); %! assert (EDITOR (), orig_val); + +%!error (EDITOR (1, 2)) */ DEFUN (EXEC_PATH, args, nargout, @@ -460,7 +461,6 @@ } /* -%!error (EXEC_PATH (1, 2)); %!test %! orig_val = EXEC_PATH (); %! old_val = EXEC_PATH ("X"); @@ -468,6 +468,8 @@ %! assert (EXEC_PATH (), "X"); %! EXEC_PATH (orig_val); %! assert (EXEC_PATH (), orig_val); + +%!error (EXEC_PATH (1, 2)) */ DEFUN (IMAGE_PATH, args, nargout, @@ -487,7 +489,6 @@ } /* -%!error (IMAGE_PATH (1, 2)); %!test %! orig_val = IMAGE_PATH (); %! old_val = IMAGE_PATH ("X"); @@ -495,6 +496,8 @@ %! assert (IMAGE_PATH (), "X"); %! IMAGE_PATH (orig_val); %! assert (IMAGE_PATH (), orig_val); + +%!error (IMAGE_PATH (1, 2)) */ DEFUN (OCTAVE_HOME, args, , @@ -514,8 +517,8 @@ } /* -%!error OCTAVE_HOME (1); -%!assert (ischar (OCTAVE_HOME ())); +%!assert (ischar (OCTAVE_HOME ())) +%!error OCTAVE_HOME (1) */ DEFUNX ("OCTAVE_VERSION", FOCTAVE_VERSION, args, , @@ -537,6 +540,6 @@ } /* -%!error OCTAVE_VERSION (1); -%!assert (ischar (OCTAVE_VERSION ())); +%!assert (ischar (OCTAVE_VERSION ())) +%!error OCTAVE_VERSION (1) */
--- a/src/dirfns.cc +++ b/src/dirfns.cc @@ -617,35 +617,34 @@ /* %!test -%! tmpdir = tmpnam; -%! filename = {"file1", "file2", "file3", "myfile1", "myfile1b"}; -%! if (mkdir (tmpdir)) -%! cwd = pwd; -%! cd (tmpdir); -%! if strcmp (canonicalize_file_name (pwd), ... -%! canonicalize_file_name (tmpdir)) -%! a = 0; -%! for n = 1:5 -%! save (filename{n}, "a"); -%! endfor -%! else -%! rmdir (tmpdir); -%! error ("Couldn't change to temporary dir"); -%! endif -%! else -%! error ("Couldn't create temporary directory"); -%! endif -%! result1 = glob ("*file1"); -%! result2 = glob ("myfile?"); -%! result3 = glob ("file[12]"); -%! for n = 1:5 -%! delete (filename{n}); -%! endfor -%! cd (cwd); -%! rmdir (tmpdir); -%! assert (result1, {"file1"; "myfile1"}); -%! assert (result2, {"myfile1"}); -%! assert (result3, {"file1"; "file2"}); +%! tmpdir = tmpnam; +%! filename = {"file1", "file2", "file3", "myfile1", "myfile1b"}; +%! if (mkdir (tmpdir)) +%! cwd = pwd; +%! cd (tmpdir); +%! if strcmp (canonicalize_file_name (pwd), canonicalize_file_name (tmpdir)) +%! a = 0; +%! for n = 1:5 +%! save (filename{n}, "a"); +%! endfor +%! else +%! rmdir (tmpdir); +%! error ("Couldn't change to temporary dir"); +%! endif +%! else +%! error ("Couldn't create temporary directory"); +%! endif +%! result1 = glob ("*file1"); +%! result2 = glob ("myfile?"); +%! result3 = glob ("file[12]"); +%! for n = 1:5 +%! delete (filename{n}); +%! endfor +%! cd (cwd); +%! rmdir (tmpdir); +%! assert (result1, {"file1"; "myfile1"}); +%! assert (result2, {"myfile1"}); +%! assert (result3, {"file1"; "file2"}); */ DEFUNX ("fnmatch", Ffnmatch, args, ,
--- a/src/file-io.cc +++ b/src/file-io.cc @@ -1144,7 +1144,7 @@ // old val for restoring afterwards. oldloc = os.imbue (std::locale (args(2).string_value ().c_str ())); - + } catch (std::runtime_error) { @@ -1332,8 +1332,8 @@ /* %!test -%! assert(sscanf('1,2', '%f', 'C'), 1) -%! assert(sscanf('1,2', '%f', 'fr_FR'), 1.2) +%! assert (sscanf ("1,2", "%f", "C"), 1) +%! assert (sscanf ("1,2", "%f", "fr_FR"), 1.2) */ DEFUN (scanf, args, nargout,
--- a/src/graphics.cc +++ b/src/graphics.cc @@ -1967,13 +1967,13 @@ } /* -%!# test set with name, value pairs +## test set with name, value pairs %!test -%! set(gcf, "visible", "off"); -%! h = plot (1:10, 10:-1:1); -%! set (h, "linewidth", 10, "marker", "x"); -%! assert (get (h, "linewidth"), 10); -%! assert (get (h, "marker"), "x"); +%! set (gcf, "visible", "off"); +%! h = plot (1:10, 10:-1:1); +%! set (h, "linewidth", 10, "marker", "x"); +%! assert (get (h, "linewidth"), 10); +%! assert (get (h, "marker"), "x"); */ // Set properties given in two cell arrays containing names and values. @@ -2002,34 +2002,34 @@ } /* -%!# test set with cell array arguments +## test set with cell array arguments %!test -%! set (gcf, "visible", "off"); -%! h = plot (1:10, 10:-1:1); -%! set (h, {"linewidth", "marker"}, {10, "x"}); -%! assert (get(h, "linewidth"), 10); -%! assert (get(h, "marker"), "x"); - -%!# test set with multiple handles and cell array arguments +%! set (gcf, "visible", "off"); +%! h = plot (1:10, 10:-1:1); +%! set (h, {"linewidth", "marker"}, {10, "x"}); +%! assert (get (h, "linewidth"), 10); +%! assert (get (h, "marker"), "x"); + +## test set with multiple handles and cell array arguments %!test -%! set (gcf, "visible", "off"); -%! h = plot (1:10, 10:-1:1, 1:10, 1:10); -%! set (h, {"linewidth", "marker"}, {10, "x"; 5, "o"}); -%! assert (get (h, "linewidth"), {10; 5}); -%! assert (get (h, "marker"), {"x"; "o"}); -%! set (h, {"linewidth", "marker"}, {10, "x"}); -%! assert (get (h, "linewidth"), {10; 10}); -%! assert (get (h, "marker"), {"x"; "x"}); +%! set (gcf, "visible", "off"); +%! h = plot (1:10, 10:-1:1, 1:10, 1:10); +%! set (h, {"linewidth", "marker"}, {10, "x"; 5, "o"}); +%! assert (get (h, "linewidth"), {10; 5}); +%! assert (get (h, "marker"), {"x"; "o"}); +%! set (h, {"linewidth", "marker"}, {10, "x"}); +%! assert (get (h, "linewidth"), {10; 10}); +%! assert (get (h, "marker"), {"x"; "x"}); %!error <set: number of graphics handles must match number of value rows> -%! set (gcf, "visible", "off"); -%! h = plot (1:10, 10:-1:1, 1:10, 1:10); -%! set (h, {"linewidth", "marker"}, {10, "x"; 5, "o"; 7, "."}); +%! set (gcf, "visible", "off"); +%! h = plot (1:10, 10:-1:1, 1:10, 1:10); +%! set (h, {"linewidth", "marker"}, {10, "x"; 5, "o"; 7, "."}); %!error <set: number of names must match number of value columns> -%! set (gcf, "visible", "off"); -%! h = plot (1:10, 10:-1:1, 1:10, 1:10); -%! set (h, {"linewidth"}, {10, "x"; 5, "o"}); +%! set (gcf, "visible", "off"); +%! h = plot (1:10, 10:-1:1, 1:10, 1:10); +%! set (h, {"linewidth"}, {10, "x"; 5, "o"}); */ // Set properties given in a struct array @@ -2051,16 +2051,16 @@ } /* -%!# test set with struct arguments +## test set with struct arguments %!test -%! set (gcf, "visible", "off"); -%! h = plot (1:10, 10:-1:1); -%! set (h, struct ("linewidth", 10, "marker", "x")); -%! assert (get (h, "linewidth"), 10); -%! assert (get (h, "marker"), "x"); -%! h = plot (1:10, 10:-1:1, 1:10, 1:10); -%! set (h, struct ("linewidth", {5, 10})); -%! assert (get(h, "linewidth"), {10; 10}); +%! set (gcf, "visible", "off"); +%! h = plot (1:10, 10:-1:1); +%! set (h, struct ("linewidth", 10, "marker", "x")); +%! assert (get (h, "linewidth"), 10); +%! assert (get (h, "marker"), "x"); +%! h = plot (1:10, 10:-1:1, 1:10, 1:10); +%! set (h, struct ("linewidth", {5, 10})); +%! assert (get (h, "linewidth"), {10; 10}); */ // Set a property to a value or to its (factory) default value. @@ -2101,15 +2101,15 @@ } /* -%!# test setting of default values +## test setting of default values %!test -%! set (gcf, "visible", "off"); -%! h = plot (1:10, 10:-1:1); -%! set (0, "defaultlinelinewidth", 20); -%! set (h, "linewidth", "default"); -%! assert (get (h, "linewidth"), 20); -%! set (h, "linewidth", "factory"); -%! assert (get (h, "linewidth"), 0.5); +%! set (gcf, "visible", "off"); +%! h = plot (1:10, 10:-1:1); +%! set (0, "defaultlinelinewidth", 20); +%! set (h, "linewidth", "default"); +%! assert (get (h, "linewidth"), 20); +%! set (h, "linewidth", "factory"); +%! assert (get (h, "linewidth"), 0.5); */ static double @@ -3055,19 +3055,19 @@ /* %!test -%! set (0, "units", "pixels") +%! set (0, "units", "pixels"); %! sz = get (0, "screensize") - [1, 1, 0, 0]; %! dpi = get (0, "screenpixelsperinch"); -%! set (0, "units", "inches") -%! assert (get (0, "screensize"), sz / dpi, 0.5 / dpi) -%! set (0, "units", "centimeters") -%! assert (get (0, "screensize"), sz / dpi * 2.54, 0.5 / dpi * 2.54) -%! set (0, "units", "points") -%! assert (get (0, "screensize"), sz / dpi * 72, 0.5 / dpi * 72) -%! set (0, "units", "normalized") -%! assert (get (0, "screensize"), [0.0, 0.0, 1.0, 1.0]) -%! set (0, "units", "pixels") -%! assert (get (0, "screensize"), sz + [1, 1, 0, 0]) +%! set (0, "units", "inches"); +%! assert (get (0, "screensize"), sz / dpi, 0.5 / dpi); +%! set (0, "units", "centimeters"); +%! assert (get (0, "screensize"), sz / dpi * 2.54, 0.5 / dpi * 2.54); +%! set (0, "units", "points"); +%! assert (get (0, "screensize"), sz / dpi * 72, 0.5 / dpi * 72); +%! set (0, "units", "normalized"); +%! assert (get (0, "screensize"), [0.0, 0.0, 1.0, 1.0]); +%! set (0, "units", "pixels"); +%! assert (get (0, "screensize"), sz + [1, 1, 0, 0]); */ void @@ -3681,22 +3681,23 @@ %!test %! figure (1, "visible", false); %! tol = 100 * eps (); -%! set (gcf (), "paperorientation", "PORTRAIT") -%! set (gcf (), "paperunits", "inches") -%! set (gcf (), "papertype", "USletter") -%! assert (get (gcf (), "papersize"), [8.5, 11.0], tol) -%! set (gcf (), "paperorientation", "Landscape") -%! assert (get (gcf (), "papersize"), [11.0, 8.5], tol) -%! set (gcf (), "paperunits", "centimeters") -%! assert (get (gcf (), "papersize"), [11.0, 8.5] * 2.54, tol) +%! ## UPPER case and MiXed case is part of test and should not be changed. +%! set (gcf (), "paperorientation", "PORTRAIT"); +%! set (gcf (), "paperunits", "inches"); +%! set (gcf (), "papertype", "USletter"); +%! assert (get (gcf (), "papersize"), [8.5, 11.0], tol); +%! set (gcf (), "paperorientation", "Landscape"); +%! assert (get (gcf (), "papersize"), [11.0, 8.5], tol); +%! set (gcf (), "paperunits", "centimeters"); +%! assert (get (gcf (), "papersize"), [11.0, 8.5] * 2.54, tol); %! set (gcf (), "papertype", "a4"); -%! assert (get (gcf (), "papersize"), [29.7, 21.0], tol) -%! set (gcf (), "paperunits", "inches", "papersize", [8.5, 11.0]) -%! assert (get (gcf (), "papertype"), "usletter") -%! assert (get (gcf (), "paperorientation"), "portrait") -%! set (gcf (), "papersize", [11.0, 8.5]) -%! assert (get (gcf (), "papertype"), "usletter") -%! assert (get (gcf (), "paperorientation"), "landscape") +%! assert (get (gcf (), "papersize"), [29.7, 21.0], tol); +%! set (gcf (), "paperunits", "inches", "papersize", [8.5, 11.0]); +%! assert (get (gcf (), "papertype"), "usletter"); +%! assert (get (gcf (), "paperorientation"), "portrait"); +%! set (gcf (), "papersize", [11.0, 8.5]); +%! assert (get (gcf (), "papertype"), "usletter"); +%! assert (get (gcf (), "paperorientation"), "landscape"); */ void @@ -3722,13 +3723,13 @@ /* %!test -%! figure (1, "visible", false) -%! set (0, "units", "pixels") +%! figure (1, "visible", false); +%! set (0, "units", "pixels"); %! rsz = get (0, "screensize"); -%! set (gcf (), "units", "pixels") +%! set (gcf (), "units", "pixels"); %! fsz = get (gcf (), "position"); -%! set (gcf (), "units", "normalized") -%! assert (get (gcf (), "position"), (fsz - [1, 1, 0, 0]) ./ rsz([3, 4, 3, 4])) +%! set (gcf (), "units", "normalized"); +%! assert (get (gcf (), "position"), (fsz - [1, 1, 0, 0]) ./ rsz([3, 4, 3, 4])); */ std::string @@ -4968,19 +4969,21 @@ } /* +## FIXME: A demo can't be called in a C++ file. This should be made a test +## or moved to a .m file where it can be called. %!demo -%! clf -%! subplot (2, 1, 1) -%! plot (rand (3)) -%! xlabel xlabel -%! ylabel ylabel -%! title title -%! subplot (2, 1, 2) -%! plot (rand (3)) -%! set (gca, "ticklength", get (gca, "ticklength") * 2, "tickdir", "out") -%! xlabel xlabel -%! ylabel ylabel -%! title title +%! clf; +%! subplot (2,1,1); +%! plot (rand (3)); +%! xlabel xlabel; +%! ylabel ylabel; +%! title title; +%! subplot (2,1,2); +%! plot (rand (3)); +%! set (gca, "ticklength", get (gca, "ticklength") * 2, "tickdir", "out"); +%! xlabel xlabel; +%! ylabel ylabel; +%! title title; */ static bool updating_xlabel_position = false; @@ -8608,7 +8611,7 @@ } /* -%!assert (get (findobj (0, 'Tag', 'nonexistenttag'), 'nonexistentproperty'), []) +%!assert (get (findobj (0, "Tag", "nonexistenttag"), "nonexistentproperty"), []) */ // Return all properties from the graphics handle @var{h}.
--- a/src/mappers.cc +++ b/src/mappers.cc @@ -112,7 +112,7 @@ %!test %! x = single ([1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1]); %! v = single ([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]); -%! assert (acos (x), v, sqrt (eps ('single'))); +%! assert (acos (x), v, sqrt (eps ("single"))); %!error acos () %!error acos (1, 2) @@ -143,7 +143,7 @@ %!test %! x = single ([1, 0, -1, 0]); %! v = single ([0, pi/2*i, pi*i, pi/2*i]); -%! assert (acosh (x), v, sqrt (eps ('single'))); +%! assert (acosh (x), v, sqrt (eps ("single"))); %!error acosh () %!error acosh (1, 2) @@ -213,7 +213,7 @@ %! assert (arg (single (-1)), single (pi)); %! endif %!assert (arg (single (-i)), single (-pi/2)) -%!assert (arg (single ([1, i; -1, -i])), single ([0, pi/2; pi, -pi/2]), 2e1*eps ('single')) +%!assert (arg (single ([1, i; -1, -i])), single ([0, pi/2; pi, -pi/2]), 2e1*eps ("single")) %!error arg () %!error arg (1, 2) @@ -272,7 +272,7 @@ %!test %! v = single ([0, pi/2*i, 0, -pi/2*i]); %! x = single ([0, i, 0, -i]); -%! assert (asinh (x), v, sqrt (eps ('single'))); +%! assert (asinh (x), v, sqrt (eps ("single"))); %!error asinh () %!error asinh (1, 2) @@ -307,7 +307,7 @@ %!test %! v = single ([0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0]); %! x = single ([0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0]); -%! assert (atan (x), v, sqrt (eps ('single'))); +%! assert (atan (x), v, sqrt (eps ("single"))); %!error atan () %!error atan (1, 2) @@ -338,7 +338,7 @@ %!test %! v = single ([0, 0]); %! x = single ([0, 0]); -%! assert (atanh (x), v, sqrt (eps ('single'))); +%! assert (atanh (x), v, sqrt (eps ("single"))); %!error atanh () %!error atanh (1, 2) @@ -402,16 +402,16 @@ } /* -%% double precision +## double precision %!assert (ceil ([2, 1.1, -1.1, -1]), [2, 2, -1, -1]) -%% complex double precison +## complex double precison %!assert (ceil ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i]), [2+2i, 2+2i, -1-i, -1-i]) -%% single precision +## single precision %!assert (ceil (single ([2, 1.1, -1.1, -1])), single ([2, 2, -1, -1])) -%% complex single precision +## complex single precision %!assert (ceil (single ([2+2i, 1.1+1.1i, -1.1-1.1i, -1-i])), single ([2+2i, 2+2i, -1-i, -1-i])) %!error ceil () @@ -488,7 +488,7 @@ %! rt3 = sqrt (3); %! x = single ([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]); %! v = single ([1, rt3/2, rt2/2, 1/2, 0, -1/2, -rt2/2, -rt3/2, -1]); -%! assert (cos (x), v, sqrt (eps ('single'))); +%! assert (cos (x), v, sqrt (eps ("single"))); %!error cos () %!error cos (1, 2) @@ -519,7 +519,7 @@ %!test %! x = single ([0, pi/2*i, pi*i, 3*pi/2*i]); %! v = single ([1, 0, -1, 0]); -%! assert (cosh (x), v, sqrt (eps ('single'))); +%! assert (cosh (x), v, sqrt (eps ("single"))); %!error cosh () %!error cosh (1, 2) @@ -568,10 +568,10 @@ %!test %! x = [0,.5,1]; %! v = [0, .520499877813047, .842700792949715]; -%! assert (all (abs (erf (x)-v) < 1.e-10)); -%! assert (all (abs (erf (-x)+v) < 1.e-10)); -%! assert (all (abs (erfc (x)+v-1) < 1.e-10)); -%! assert (all (abs (erfinv (v)-x) < 1.e-10)); +%! assert (erf (x), v, 1.e-10); +%! assert (erf (-x), -v, 1.e-10); +%! assert (erfc (x), 1-v, 1.e-10); +%! assert (erfinv (v), x, 1.e-10); %!test %! a = -1i*sqrt (single (-1/(6.4187*6.4187))); @@ -580,10 +580,10 @@ %!test %! x = single ([0,.5,1]); %! v = single ([0, .520499877813047, .842700792949715]); -%! assert (all (abs (erf (x)-v) < 1.e-6)); -%! assert (all (abs (erf (-x)+v) < 1.e-6)); -%! assert (all (abs (erfc (x)+v-1) < 1.e-6)); -%! assert (all (abs (erfinv (v)-x) < 1.e-6)); +%! assert (erf (x), v, 1.e-6); +%! assert (erf (-x), -v, 1.e-6); +%! assert (erfc (x), 1-v, 1.e-6); +%! assert (erfinv (v), x, 1.e-6); %!error erf () %!error erf (1, 2) @@ -610,16 +610,16 @@ } /* -%% middle region +## middle region %!assert (erf (erfinv ([-0.9 -0.3 0 0.4 0.8])), [-0.9 -0.3 0 0.4 0.8], eps) %!assert (erf (erfinv (single ([-0.9 -0.3 0 0.4 0.8]))), single ([-0.9 -0.3 0 0.4 0.8]), 1e-8) -%% tail region +## tail region %!assert (erf (erfinv ([-0.999 -0.99 0.9999 0.99999])), [-0.999 -0.99 0.9999 0.99999], eps) %!assert (erf (erfinv (single ([-0.999 -0.99 0.9999 0.99999]))), single ([-0.999 -0.99 0.9999 0.99999]), 1e-8) -%% backward - loss of accuracy +## backward - loss of accuracy %!assert (erfinv (erf ([-3 -1 -0.4 0.7 1.3 2.8])), [-3 -1 -0.4 0.7 1.3 2.8], -1e-12) %!assert (erfinv (erf (single ([-3 -1 -0.4 0.7 1.3 2.8]))), single ([-3 -1 -0.4 0.7 1.3 2.8]), -1e-4) -%% exceptional +## exceptional %!assert (erfinv ([-1, 1, 1.1, -2.1]), [-Inf, Inf, NaN, NaN]) %!error erfinv (1+2i) @@ -687,7 +687,7 @@ } /* -%% FIXME: Need a test for erfcx +## FIXME: Need a test for erfcx %!error erfcx () %!error erfcx (1, 2) @@ -720,8 +720,8 @@ /* %!assert (exp ([0, 1, -1, -1000]), [1, e, 1/e, 0], sqrt (eps)) %!assert (exp (1+i), e * (cos (1) + sin (1) * i), sqrt (eps)) -%!assert (exp (single ([0, 1, -1, -1000])), single ([1, e, 1/e, 0]), sqrt (eps ('single'))) -%!assert (exp (single (1+i)), single (e * (cos (1) + sin (1) * i)), sqrt (eps ('single'))) +%!assert (exp (single ([0, 1, -1, -1000])), single ([1, e, 1/e, 0]), sqrt (eps ("single"))) +%!assert (exp (single (1+i)), single (e * (cos (1) + sin (1) * i)), sqrt (eps ("single"))) %!assert (exp ([Inf, -Inf, NaN]), [Inf 0 NaN]) %!assert (exp (single ([Inf, -Inf, NaN])), single ([Inf 0 NaN])) @@ -924,7 +924,7 @@ %!test %! x = single ([.5, 1, 1.5, 2, 3, 4, 5]); %! v = single ([sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24]); -%! assert (gamma (x), v, sqrt (eps ('single'))); +%! assert (gamma (x), v, sqrt (eps ("single"))); %!test %! x = [-1, 0, 1, Inf]; @@ -961,7 +961,7 @@ %!assert (imag (single (1)), single (0)) %!assert (imag (single (i)), single (1)) %!assert (imag (single (1+i)), single (1)) -%!assert (imag (single ([i, 1; 1, i])), full (eye (2,'single'))) +%!assert (imag (single ([i, 1; 1, i])), full (eye (2,"single"))) %!error imag () %!error imag (1, 2) @@ -992,7 +992,7 @@ %! result(toascii ("A":"Z") + 1) = true; %! result(toascii ("0":"9") + 1) = true; %! result(toascii ("a":"z") + 1) = true; -%! assert (all (isalnum (charset) == result)); +%! assert (isalnum (charset), result); %!error isalnum () %!error isalnum (1, 2) @@ -1022,7 +1022,7 @@ %! result = false (1, 128); %! result(toascii ("A":"Z") + 1) = true; %! result(toascii ("a":"z") + 1) = true; -%! assert (all (isalpha (charset) == result)); +%! assert (isalpha (charset), result); %!error isalpha () %!error isalpha (1, 2) @@ -1049,7 +1049,7 @@ %!test %! charset = char (0:127); %! result = true (1, 128); -%! assert (all (isascii (charset) == result)); +%! assert (isascii (charset), result); %!error isascii () %!error isascii (1, 2) @@ -1078,7 +1078,7 @@ %! result = false (1, 128); %! result(1:32) = true; %! result(128) = true; -%! assert (all (iscntrl (charset) == result)); +%! assert (iscntrl (charset), result); %!error iscntrl () %!error iscntrl (1, 2) @@ -1106,7 +1106,7 @@ %! charset = char (0:127); %! result = false (1, 128); %! result(toascii ("0":"9") + 1) = true; -%! assert (all (isdigit (charset) == result)); +%! assert (isdigit (charset), result); %!error isdigit () %!error isdigit (1, 2) @@ -1177,7 +1177,7 @@ %! charset = char (0:127); %! result = false (1, 128); %! result(34:127) = true; -%! assert (all (isgraph (charset) == result)); +%! assert (isgraph (charset), result); %!error isgraph () %!error isgraph (1, 2) @@ -1205,7 +1205,7 @@ %! charset = char (0:127); %! result = false (1, 128); %! result(toascii ("a":"z") + 1) = true; -%! assert (all (islower (charset) == result)); +%! assert (islower (charset), result); %!error islower () %!error islower (1, 2) @@ -1318,7 +1318,7 @@ %! charset = char (0:127); %! result = false (1, 128); %! result(33:127) = true; -%! assert (all (isprint (charset) == result)); +%! assert (isprint (charset), result); %!error isprint () %!error isprint (1, 2) @@ -1349,7 +1349,7 @@ %! result(59:65) = true; %! result(92:97) = true; %! result(124:127) = true; -%! assert (all (ispunct (charset) == result)); +%! assert (ispunct (charset), result); %!error ispunct () %!error ispunct (1, 2) @@ -1378,7 +1378,7 @@ %! charset = char (0:127); %! result = false (1, 128); %! result(toascii (" \f\n\r\t\v") + 1) = true; -%! assert (all (isspace (charset) == result)); +%! assert (isspace (charset), result); %!error isspace () %!error isspace (1, 2) @@ -1406,7 +1406,7 @@ %! charset = char (0:127); %! result = false (1, 128); %! result(toascii ("A":"Z") + 1) = true; -%! assert (all (isupper (charset) == result)); +%! assert (isupper (charset), result); %!error isupper () %!error isupper (1, 2) @@ -1436,7 +1436,7 @@ %! result(toascii ("A":"F") + 1) = true; %! result(toascii ("0":"9") + 1) = true; %! result(toascii ("a":"f") + 1) = true; -%! assert (all (isxdigit (charset) == result)); +%! assert (isxdigit (charset), result); %!error isxdigit () %!error isxdigit (1, 2) @@ -1462,30 +1462,30 @@ /* %!test %! a = -1i*sqrt (-1/(6.4187*6.4187)); -%! assert (lgamma(a), lgamma(real(a))); +%! assert (lgamma (a), lgamma (real (a))); %!test %! x = [.5, 1, 1.5, 2, 3, 4, 5]; %! v = [sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24]; -%! assert (lgamma(x), log(v), sqrt (eps)) +%! assert (lgamma (x), log (v), sqrt (eps)) %!test %! a = single (-1i*sqrt (-1/(6.4187*6.4187))); -%! assert (lgamma(a), lgamma(real(a))); +%! assert (lgamma (a), lgamma (real (a))); %!test %! x = single ([.5, 1, 1.5, 2, 3, 4, 5]); %! v = single ([sqrt(pi), 1, .5*sqrt(pi), 1, 2, 6, 24]); -%! assert (lgamma(x), log(v), sqrt (eps ('single'))) +%! assert (lgamma (x), log (v), sqrt (eps ("single"))) %!test %! x = [-1, 0, 1, Inf]; %! v = [Inf, Inf, 0, Inf]; -%! assert (lgamma(x), v); -%! assert (lgamma(single (x)), single (v)); +%! assert (lgamma (x), v); +%! assert (lgamma (single (x)), single (v)); -%!error lgamma() -%!error lgamma(1,2) +%!error lgamma () +%!error lgamma (1,2) */ DEFUN (log, args, , @@ -1514,10 +1514,10 @@ /* %!assert (log ([1, e, e^2]), [0, 1, 2], sqrt (eps)) -%!assert (log ([-0.5, -1.5, -2.5]), log([0.5, 1.5, 2.5]) + pi*1i, sqrt (eps)) +%!assert (log ([-0.5, -1.5, -2.5]), log ([0.5, 1.5, 2.5]) + pi*1i, sqrt (eps)) -%!assert (log (single ([1, e, e^2])), single ([0, 1, 2]), sqrt (eps ('single'))) -%!assert (log (single ([-0.5, -1.5, -2.5])), single (log([0.5, 1.5, 2.5]) + pi*1i), 4*eps ('single')) +%!assert (log (single ([1, e, e^2])), single ([0, 1, 2]), sqrt (eps ("single"))) +%!assert (log (single ([-0.5, -1.5, -2.5])), single (log ([0.5, 1.5, 2.5]) + pi*1i), 4*eps ("single")) %!error log () %!error log (1, 2) @@ -1541,7 +1541,7 @@ /* %!assert (log10 ([0.01, 0.1, 1, 10, 100]), [-2, -1, 0, 1, 2], sqrt (eps)) -%!assert (log10 (single ([0.01, 0.1, 1, 10, 100])), single ([-2, -1, 0, 1, 2]), sqrt (eps ('single'))) +%!assert (log10 (single ([0.01, 0.1, 1, 10, 100])), single ([-2, -1, 0, 1, 2]), sqrt (eps ("single"))) %!error log10 () %!error log10 (1, 2) @@ -1572,7 +1572,7 @@ /* %!assert (log1p ([0, 2*eps, -2*eps]), [0, 2*eps, -2*eps], 1e-29) -%!assert (log1p (single ([0, 2*eps, -2*eps])), single([0, 2*eps, -2*eps]), 1e-29) +%!assert (log1p (single ([0, 2*eps, -2*eps])), single ([0, 2*eps, -2*eps]), 1e-29) %!error log1p () %!error log1p (1, 2) @@ -1603,7 +1603,7 @@ %!assert (real (single (1)), single (1)) %!assert (real (single (i)), single (0)) %!assert (real (single (1+i)), single (1)) -%!assert (real (single ([1, i; i, 1])), full (eye (2,'single'))) +%!assert (real (single ([1, i; i, 1])), full (eye (2,"single"))) %!error real () %!error real (1, 2) @@ -1773,7 +1773,7 @@ %!test %! x = single ([0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi]); %! v = single ([0, 1/2, rt2/2, rt3/2, 1, rt3/2, rt2/2, 1/2, 0]); -%! assert (sin (x), v, sqrt (eps ('single'))); +%! assert (sin (x), v, sqrt (eps ("single"))); %!error sin () %!error sin (1, 2) @@ -1804,7 +1804,7 @@ %!test %! x = single ([0, pi/2*i, pi*i, 3*pi/2*i]); %! v = single ([0, i, 0, -i]); -%! assert (sinh (x), v, sqrt (eps ('single'))); +%! assert (sinh (x), v, sqrt (eps ("single"))); %!error sinh () %!error sinh (1, 2) @@ -1836,8 +1836,8 @@ %!assert (sqrt (single (4)), single (2)) %!assert (sqrt (single (-1)), single (i)) -%!assert (sqrt (single (1+i)), single (exp (0.5 * log (1+i))), sqrt (eps ('single'))) -%!assert (sqrt (single ([4, -4; i, 1-i])), single ([2, 2i; exp(0.5 * log (i)), exp(0.5 * log (1-i))]), sqrt (eps ('single'))) +%!assert (sqrt (single (1+i)), single (exp (0.5 * log (1+i))), sqrt (eps ("single"))) +%!assert (sqrt (single ([4, -4; i, 1-i])), single ([2, 2i; exp(0.5 * log (i)), exp(0.5 * log (1-i))]), sqrt (eps ("single"))) %!error sqrt () %!error sqrt (1, 2) @@ -1872,7 +1872,7 @@ %!test %! x = single ([0, pi/6, pi/4, pi/3, 2*pi/3, 3*pi/4, 5*pi/6, pi]); %! v = single ([0, rt3/3, 1, rt3, -rt3, -1, -rt3/3, 0]); -%! assert (tan (x), v, sqrt (eps ('single'))); +%! assert (tan (x), v, sqrt (eps ("single"))); %!error tan () %!error tan (1, 2) @@ -1903,7 +1903,7 @@ %!test %! x = single ([0, pi*i]); %! v = single ([0, 0]); -%! assert (tanh (x), v, sqrt (eps ('single'))); +%! assert (tanh (x), v, sqrt (eps ("single"))); %!error tanh () %!error tanh (1, 2) @@ -1974,25 +1974,25 @@ DEFALIAS (lower, tolower); /* -%!assert (tolower("OCTAVE"), "octave") -%!assert (tolower("123OCTave!_&"), "123octave!_&") -%!assert (tolower({"ABC", "DEF", {"GHI", {"JKL"}}}), {"abc", "def", {"ghi", {"jkl"}}}) -%!assert (tolower(["ABC"; "DEF"]), ["abc"; "def"]) -%!assert (tolower({["ABC"; "DEF"]}), {["abc";"def"]}) -%!assert (tolower(68), "d") -%!assert (tolower({[68, 68; 68, 68]}), {["dd";"dd"]}) +%!assert (tolower ("OCTAVE"), "octave") +%!assert (tolower ("123OCTave!_&"), "123octave!_&") +%!assert (tolower ({"ABC", "DEF", {"GHI", {"JKL"}}}), {"abc", "def", {"ghi", {"jkl"}}}) +%!assert (tolower (["ABC"; "DEF"]), ["abc"; "def"]) +%!assert (tolower ({["ABC"; "DEF"]}), {["abc";"def"]}) +%!assert (tolower (68), "d") +%!assert (tolower ({[68, 68; 68, 68]}), {["dd";"dd"]}) %!test -%! a(3,3,3,3) = "D"; -%! assert(tolower(a)(3,3,3,3), "d"); +%! a(3,3,3,3) = "D"; +%! assert (tolower (a)(3,3,3,3), "d"); %!test %! charset = char (0:127); %! result = charset; -%! result(toascii ("A":"Z") + 1) = result(toascii ("a":"z") + 1); -%! assert (all (tolower (charset) == result)); +%! result (toascii ("A":"Z") + 1) = result (toascii ("a":"z") + 1); +%! assert (tolower (charset), result); -%!error <Invalid call to tolower> tolower() -%!error <Invalid call to tolower> lower() +%!error <Invalid call to tolower> lower () +%!error <Invalid call to tolower> tolower () %!error tolower (1, 2) */ @@ -2033,16 +2033,16 @@ %!assert (toupper (100), "D") %!assert (toupper ({[100, 100; 100, 100]}), {["DD";"DD"]}) %!test -%! a(3,3,3,3) = "d"; -%! assert(toupper (a)(3,3,3,3), "D"); +%! a(3,3,3,3) = "d"; +%! assert (toupper (a)(3,3,3,3), "D"); %!test %! charset = char (0:127); %! result = charset; -%! result(toascii ("a":"z") + 1) = result(toascii ("A":"Z") + 1); -%! assert (all (toupper (charset) == result)); +%! result (toascii ("a":"z") + 1) = result (toascii ("A":"Z") + 1); +%! assert (toupper (charset), result); -%!error <Invalid call to toupper> toupper() -%!error <Invalid call to toupper> upper() +%!error <Invalid call to toupper> toupper () +%!error <Invalid call to toupper> upper () %!error toupper (1, 2) */
--- a/src/oct-map.cc +++ b/src/oct-map.cc @@ -448,10 +448,10 @@ } /* -%!# test preservation of xkeys by squeeze +## test preservation of xkeys by squeeze %!test -%! x(1,1,1,1).d = 10; x(3,5,1,7).a = "b"; x(2,4,1,7).f = 27; -%! assert (fieldnames (squeeze (x)), {"d"; "a"; "f"}); +%! x(1,1,1,1).d = 10; x(3,5,1,7).a = "b"; x(2,4,1,7).f = 27; +%! assert (fieldnames (squeeze (x)), {"d"; "a"; "f"}); */ octave_map @@ -482,10 +482,10 @@ } /* -%!# test preservation of key order by permute +## test preservation of key order by permute %!test -%! x(1,1,1,1).d = 10; x(3,5,1,7).a = "b"; x(2,4,1,7).f = 27; -%! assert (fieldnames (permute (x, [3, 4, 1, 2])), {"d"; "a"; "f"}); +%! x(1,1,1,1).d = 10; x(3,5,1,7).a = "b"; x(2,4,1,7).f = 27; +%! assert (fieldnames (permute (x, [3, 4, 1, 2])), {"d"; "a"; "f"}); */ octave_map @@ -507,12 +507,12 @@ } /* -%!# test preservation of key order by transpose +## test preservation of key order by transpose %!test -%! x(1,1).d = 10; x(3,5).a = "b"; x(2,4).f = 27; -%! assert (fieldnames (transpose (x)), {"d"; "a"; "f"}); -%! assert (fieldnames (x'), {"d"; "a"; "f"}); -%! assert (fieldnames (x.'), {"d"; "a"; "f"}); +%! x(1,1).d = 10; x(3,5).a = "b"; x(2,4).f = 27; +%! assert (fieldnames (transpose (x)), {"d"; "a"; "f"}); +%! assert (fieldnames (x'), {"d"; "a"; "f"}); +%! assert (fieldnames (x.'), {"d"; "a"; "f"}); */ octave_map @@ -542,10 +542,10 @@ } /* -%!# test preservation of key order by reshape +## test preservation of key order by reshape %!test -%! x(1,1).d = 10; x(4,6).a = "b"; x(2,4).f = 27; -%! assert (fieldnames (reshape (x, 3, 8)), {"d"; "a"; "f"}); +%! x(1,1).d = 10; x(4,6).a = "b"; x(2,4).f = 27; +%! assert (fieldnames (reshape (x, 3, 8)), {"d"; "a"; "f"}); */ void @@ -804,23 +804,23 @@ } /* -%!# test preservation of key order by concatenation +## test preservation of key order by concatenation %!test -%! x(1, 1).d = 10; x(4, 6).a = "b"; x(2, 4).f = 27; -%! y(1, 6).f = 11; y(1, 6).a = "c"; y(1, 6).d = 33; -%! assert (fieldnames ([x; y]), {"d"; "a"; "f"}); +%! x(1, 1).d = 10; x(4, 6).a = "b"; x(2, 4).f = 27; +%! y(1, 6).f = 11; y(1, 6).a = "c"; y(1, 6).d = 33; +%! assert (fieldnames ([x; y]), {"d"; "a"; "f"}); %!test -%! s = struct (); -%! sr = [s,s]; -%! sc = [s;s]; -%! sm = [s,s;s,s]; -%! assert (nfields (sr), 0); -%! assert (nfields (sc), 0); -%! assert (nfields (sm), 0); -%! assert (size (sr), [1, 2]); -%! assert (size (sc), [2, 1]); -%! assert (size (sm), [2, 2]); +%! s = struct (); +%! sr = [s,s]; +%! sc = [s;s]; +%! sm = [s,s;s,s]; +%! assert (nfields (sr), 0); +%! assert (nfields (sc), 0); +%! assert (nfields (sm), 0); +%! assert (size (sr), [1, 2]); +%! assert (size (sc), [2, 1]); +%! assert (size (sm), [2, 2]); */ octave_map @@ -1250,10 +1250,10 @@ } /* -%!# test preservation of key order by indexing +## test preservation of key order by indexing %!test -%! x(1, 1).d = 10; x(4, 6).a = "b"; x(2, 4).f = 27; -%! assert (fieldnames (x([1, 2], [2:5])), {"d"; "a"; "f"}); +%! x(1, 1).d = 10; x(4, 6).a = "b"; x(2, 4).f = 27; +%! assert (fieldnames (x([1, 2], [2:5])), {"d"; "a"; "f"}); */ octave_map
--- a/src/octave.cc +++ b/src/octave.cc @@ -982,8 +982,8 @@ } /* -%!error argv (1); -%!assert (iscellstr (argv ())); +%!assert (iscellstr (argv ())) +%!error argv (1) */ DEFUN (program_invocation_name, args, , @@ -1009,8 +1009,8 @@ } /* -%!error program_invocation_name (1); -%!assert (ischar (program_invocation_name ())); +%!assert (ischar (program_invocation_name ())) +%!error program_invocation_name (1) */ DEFUN (program_name, args, , @@ -1032,6 +1032,6 @@ } /* -%!error program_name (1); -%!assert (ischar (program_name ())); +%!assert (ischar (program_name ())) +%!error program_name (1) */
--- a/src/ov-base.cc +++ b/src/ov-base.cc @@ -1558,14 +1558,13 @@ } /* - %!test - s = speye(3); - sparse_auto_mutate (false); - s(:, 1) = 1; - assert (typeinfo (s), "sparse matrix"); - sparse_auto_mutate (true); - s(1, :) = 1; - assert (typeinfo (s), "matrix"); - +%! s = speye (3); +%! sparse_auto_mutate (false); +%! s(:, 1) = 1; +%! assert (typeinfo (s), "sparse matrix"); +%! sparse_auto_mutate (true); +%! s(1, :) = 1; +%! assert (typeinfo (s), "matrix"); +%! sparse_auto_mutate (false); */
--- a/src/ov-bool-mat.cc +++ b/src/ov-bool-mat.cc @@ -577,11 +577,10 @@ } /* -%!shared m, s, c +%!test %! m = eye (2) != 0; %! s = !0; %! c = {"double", "single", "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "logical"}; -%!test %! for i = 1:numel (c) %! assert (logical (eye (2, c{i})), m) %! assert (logical (eye (1, c{i})), s)
--- a/src/ov-cell.cc +++ b/src/ov-cell.cc @@ -1471,14 +1471,14 @@ /* %!test -%! keys = cellstr (char (floor (rand (11,10)*24+65)))'; -%! vals = cellfun(@(x) mat2cell(rand (19,1), ones (19,1), 1), ... -%! mat2cell([1:11]', ones(11,1), 1), "uniformoutput", false)'; -%! s = struct ([keys; vals]{:}); -%! t = cell2struct ([vals{:}], keys, 2); -%! assert (s, t); -%! assert (struct2cell (s), [vals{:}]'); -%! assert (fieldnames (s), keys'); +%! keys = cellstr (char (floor (rand (11,10)*24+65)))'; +%! vals = cellfun (@(x) mat2cell (rand (19,1), ones (19,1), 1), ... +%! mat2cell ([1:11]', ones (11,1), 1), "uniformoutput", false)'; +%! s = struct ([keys; vals]{:}); +%! t = cell2struct ([vals{:}], keys, 2); +%! assert (s, t); +%! assert (struct2cell (s), [vals{:}]'); +%! assert (fieldnames (s), keys'); */ mxArray *
--- a/src/ov-fcn-handle.cc +++ b/src/ov-fcn-handle.cc @@ -1288,7 +1288,6 @@ #endif /* - %!test %! a = 2; %! f = @(x) a + x; @@ -1302,26 +1301,25 @@ %! hdld2 = hdld; %! hbi2 = hbi; %! modes = {"-text", "-binary"}; -%! if (!isempty(findstr(octave_config_info ("DEFS"),"HAVE_HDF5"))) +%! if (!isempty (findstr (octave_config_info ("DEFS"), "HAVE_HDF5"))) %! modes(end+1) = "-hdf5"; %! endif %! for i = 1:numel (modes) %! mode = modes{i}; -%! nm = tmpnam(); +%! nm = tmpnam (); %! unwind_protect %! save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2"); %! clear f2 g2 hm2 hdld2 hbi2 %! load (nm); -%! assert (f(2),f2(2)); -%! assert (g(2),g2(2)); -%! assert (g(3),g2(3)); +%! assert (f (2), f2 (2)); +%! assert (g (2), g2 (2)); +%! assert (g (3), g2 (3)); %! unlink (nm); %! save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2"); %! unwind_protect_cleanup %! unlink (nm); %! end_unwind_protect %! endfor - */ void @@ -1592,7 +1590,7 @@ %! "&", "and"; %! "|", "or"}; %! for i = 1:rows (x) -%! assert (functions (str2func (x{i,1})).function, x{i,2}) +%! assert (functions (str2func (x{i,1})).function, x{i,2}); %! endfor */ @@ -1759,7 +1757,6 @@ } /* - %!function y = __testrecursionfunc (f, x, n) %! if (nargin < 3) %! n = 0; @@ -1768,12 +1765,11 @@ %! y = f (x); %! else %! n++; -%! y = __testrecursionfunc (@(x) f(2*x), x, n); +%! y = __testrecursionfunc (@(x) f (2*x), x, n); %! endif %!endfunction %! %!assert (__testrecursionfunc (@(x) x, 1), 8) - */ DEFUN (is_function_handle, args, , @@ -1802,12 +1798,11 @@ %!assert (is_function_handle (fh)) %!assert (! is_function_handle ({fh})) %!assert (! is_function_handle (1)) -%!error is_function_handle (); -%!error is_function_handle (1, 2); +%!error is_function_handle () +%!error is_function_handle (1, 2) */ - octave_fcn_binder::octave_fcn_binder (const octave_value& f, const octave_value& root, const octave_value_list& templ,
--- a/src/ov-fcn-inline.cc +++ b/src/ov-fcn-inline.cc @@ -825,9 +825,9 @@ %! fn = inline ("x.^2 + 1"); %!assert (feval (fn, 6), 37) %!assert (fn (6), 37) -%% FIXME: Need tests for other 2 calling forms of inline() +## FIXME: Need tests for other 2 calling forms of inline() -%% Test input validation +## Test input validation %!error inline () %!error <STR argument must be a string> inline (1) %!error <N must be an integer> inline ("2", ones (2,2)) @@ -867,7 +867,7 @@ %!assert (formula (fn), "x.^2 + 1") %!assert (formula (fn), char (fn)) -%% Test input validation +## Test input validation %!error formula () %!error formula (1, 2) %!error <FUN must be an inline function> formula (1) @@ -914,7 +914,7 @@ %!assert (argnames (inline ("1e-3*y + 2e4*z")), {"y"; "z"}) %!assert (argnames (inline ("2", 2)), {"x"; "P1"; "P2"}) -%% Test input validation +## Test input validation %!error argnames () %!error argnames (1, 2) %!error <FUN must be an inline function> argnames (1) @@ -1012,9 +1012,8 @@ %!assert (vectorize ("1e-3*y + 2e4*z"), "1e-3.*y + 2e4.*z") %!assert (vectorize ("2**x^5"), "2.**x.^5") -%% Test input validation +## Test input validation %!error vectorize () %!error vectorize (1, 2) %!error <FUN must be a string or inline function> vectorize (1) */ -
--- a/src/ov-flt-re-mat.cc +++ b/src/ov-flt-re-mat.cc @@ -841,7 +841,6 @@ } /* - %!assert (class (single(1)), "single") %!assert (class (single(1 + i)), "single") %!assert (class (single (int8 (1))), "single") @@ -865,6 +864,4 @@ %! y = single (x); %! assert (class (x), "double"); %! assert (class (y), "single"); - */ -
--- a/src/ov-int16.cc +++ b/src/ov-int16.cc @@ -84,13 +84,10 @@ } /* - %!assert (class (int16 (1)), "int16") %!assert (int16 (1.25), int16 (1)) %!assert (int16 (1.5), int16 (2)) %!assert (int16 (-1.5), int16 (-2)) %!assert (int16 (2^17), int16 (2^16-1)) %!assert (int16 (-2^17), int16 (-2^16)) - */ -
--- a/src/ov-int32.cc +++ b/src/ov-int32.cc @@ -84,13 +84,10 @@ } /* - %!assert (class (int32 (1)), "int32") %!assert (int32 (1.25), int32 (1)) %!assert (int32 (1.5), int32 (2)) %!assert (int32 (-1.5), int32 (-2)) %!assert (int32 (2^33), int32 (2^32-1)) %!assert (int32 (-2^33), int32 (-2^32)) - */ -
--- a/src/ov-int64.cc +++ b/src/ov-int64.cc @@ -84,13 +84,10 @@ } /* - %!assert (class (int64 (1)), "int64") %!assert (int64 (1.25), int64 (1)) %!assert (int64 (1.5), int64 (2)) %!assert (int64 (-1.5), int64 (-2)) %!assert (int64 (2^65), int64 (2^64-1)) %!assert (int64 (-2^65), int64 (-2^64)) - */ -
--- a/src/ov-int8.cc +++ b/src/ov-int8.cc @@ -84,12 +84,10 @@ } /* - %!assert (class (int8 (1)), "int8") %!assert (int8 (1.25), int8 (1)) %!assert (int8 (1.5), int8 (2)) %!assert (int8 (-1.5), int8 (-2)) %!assert (int8 (2^9), int8 (2^8-1)) %!assert (int8 (-2^9), int8 (-2^8)) - */
--- a/src/ov-null-mat.cc +++ b/src/ov-null-mat.cc @@ -120,7 +120,6 @@ } /* - %!assert (isnull ([]), true) %!assert (isnull ([1]), false) %!assert (isnull (zeros (0,3)), false) @@ -131,5 +130,4 @@ %!test %! x = []; %! assert (isnull (x), false); - */
--- a/src/ov-oncleanup.cc +++ b/src/ov-oncleanup.cc @@ -211,17 +211,15 @@ } /* - %!test %! old_wstate = warning ("query"); %! unwind_protect %! trigger = onCleanup (@() warning ("on", "__MY_WARNING__")); %! warning ("off", "__MY_WARNING__"); %! assert ((warning ("query", "__MY_WARNING__")).state, "off"); -%! clear trigger +%! clear trigger; %! assert ((warning ("query", "__MY_WARNING__")).state, "on"); %! unwind_protect_cleanup %! warning (old_wstate); %! end_unwind_protect - */
--- a/src/ov-range.cc +++ b/src/ov-range.cc @@ -670,7 +670,7 @@ %! warn_state = warning ("query", "Octave:noninteger-range-as-index"); %! unwind_protect %! allow_noninteger_range_as_index (false); -%! fail ('x(2.1:5)'); +%! fail ("x(2.1:5)"); %! assert (x(2:5), 1:4); %! allow_noninteger_range_as_index (true); %! warning ("off", "Octave:noninteger-range-as-index");
--- a/src/ov-re-mat.cc +++ b/src/ov-re-mat.cc @@ -981,7 +981,6 @@ } /* - %!assert (class (double (single (1))), "double") %!assert (class (double (single (1 + i))), "double") %!assert (class (double (int8 (1))), "double") @@ -1010,5 +1009,4 @@ %! y = double (x); %! assert (class (x), "single"); %! assert (class (y), "double"); - */
--- a/src/ov-struct.cc +++ b/src/ov-struct.cc @@ -249,7 +249,8 @@ /* %!test -%! x(1).a.a = 1; x(2).a.a = 2; +%! x(1).a.a = 1; +%! x(2).a.a = 2; %! assert (size (x), [1, 2]); %! assert (x(1).a.a, 1); %! assert (x(2).a.a, 2); @@ -691,25 +692,6 @@ return dims.length () == 2 && dims (0) == 1 && dims (1) == 1; } -/* -%!shared x -%! x(1).a=1; x(2).a=2; x(1).b=3; x(2).b=3; -%!assert(struct('a',1,'b',3),x(1)) -%!assert(isempty(x([]))) -%!assert(isempty(struct('a',{},'b',{}))) -%!assert(struct('a',{1,2},'b',{3,3}),x) -%!assert(struct('a',{1,2},'b',3),x) -%!assert(struct('a',{1,2},'b',{3}),x) -%!assert(struct('b',3,'a',{1,2}),x) -%!assert(struct('b',{3},'a',{1,2}),x) -%!test x=struct([]); -%!assert(size(x),[0,0]); -%!assert(isstruct(x)); -%!assert(isempty(fieldnames(x))); -%!fail("struct('a',{1,2},'b',{1,2,3})","dimensions of parameter 2 do not match those of parameter 4") -%!fail("struct(1,2,3,4)","struct: expecting alternating \"field\", VALUE pairs"); -%!fail("struct('1',2,'3')","struct: expecting alternating \"field\", VALUE pairs"); -*/ bool octave_struct::save_ascii (std::ostream& os) @@ -1189,7 +1171,8 @@ /* %!test -%! x(1).a.a = 1; x(2).a.a = 2; +%! x(1).a.a = 1; +%! x(2).a.a = 2; %! assert (size (x), [1, 2]); %! assert (x(1).a.a, 1); %! assert (x(2).a.a, 2); @@ -1712,25 +1695,6 @@ else return false; } -/* -%!shared x -%! x(1).a=1; x(2).a=2; x(1).b=3; x(2).b=3; -%!assert(struct('a',1,'b',3),x(1)) -%!assert(isempty(x([]))) -%!assert(isempty(struct('a',{},'b',{}))) -%!assert(struct('a',{1,2},'b',{3,3}),x) -%!assert(struct('a',{1,2},'b',3),x) -%!assert(struct('a',{1,2},'b',{3}),x) -%!assert(struct('b',3,'a',{1,2}),x) -%!assert(struct('b',{3},'a',{1,2}),x) -%!test x=struct([]); -%!assert(size(x),[0,0]); -%!assert(isstruct(x)); -%!assert(isempty(fieldnames(x))); -%!fail("struct('a',{1,2},'b',{1,2,3})","dimensions of parameter 2 do not match those of parameter 4") -%!fail("struct(1,2,3,4)","struct: expecting alternating \"field\", VALUE pairs"); -%!fail("struct('1',2,'3')","struct: expecting alternating \"field\", VALUE pairs"); -*/ DEFUN (struct, args, , "-*- texinfo -*-\n\ @@ -1874,6 +1838,26 @@ return octave_value (map); } +/* +%!shared x +%! x(1).a=1; x(2).a=2; x(1).b=3; x(2).b=3; +%!assert (struct ("a",1, "b",3), x(1)) +%!assert (isempty (x([]))) +%!assert (isempty (struct ("a",{}, "b",{}))) +%!assert (struct ("a",{1,2}, "b",{3,3}), x) +%!assert (struct ("a",{1,2}, "b",3), x) +%!assert (struct ("a",{1,2}, "b",{3}), x) +%!assert (struct ("b",3, "a",{1,2}), x) +%!assert (struct ("b",{3}, "a",{1,2}), x) +%!test x = struct ([]); +%!assert (size (x), [0,0]) +%!assert (isstruct (x)) +%!assert (isempty (fieldnames (x))) +%!fail ('struct ("a",{1,2},"b",{1,2,3})', 'dimensions of parameter 2 do not match those of parameter 4') +%!fail ('struct (1,2,3,4)', 'struct: expecting alternating "field", VALUE pairs') +%!fail ('struct ("1",2,"3")', 'struct: expecting alternating "field", VALUE pairs') +*/ + DEFUN (isstruct, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} isstruct (@var{x})\n\ @@ -1928,10 +1912,10 @@ } /* -%!# test preservation of fieldname order +## test preservation of fieldname order %!test -%! x(3).d=1; x(2).a=2; x(1).b=3; x(2).c=3; -%! assert(fieldnames(x), {"d"; "a"; "b"; "c"}); +%! x(3).d=1; x(2).a=2; x(1).b=3; x(2).c=3; +%! assert (fieldnames (x), {"d"; "a"; "b"; "c"}); */ DEFUN (isfield, args, , @@ -2012,15 +1996,15 @@ } /* -%!# test isfield +## test isfield %!test -%! x(3).d=1; x(2).a=2; x(1).b=3; x(2).c=3; -%! assert (isfield (x, 'b')); -%!assert (isfield (struct('a', '1'), 'a')); -%!assert (isfield ({1}, 'c'), false); -%!assert (isfield (struct('a', '1'), 10), false); -%!assert (isfield (struct('a', 'b'), "a "), false); -%!assert (isfield (struct('a', 1, 'b', 2), {'a', 'c'}), [true, false]); +%! x(3).d=1; x(2).a=2; x(1).b=3; x(2).c=3; +%! assert (isfield (x, "b")); +%!assert (isfield (struct("a", "1"), "a")) +%!assert (isfield ({1}, "c"), false) +%!assert (isfield (struct("a", "1"), 10), false) +%!assert (isfield (struct("a", "b"), "a "), false) +%!assert (isfield (struct("a", 1, "b", 2), {"a", "c"}), [true, false]) */ DEFUN (cell2struct, args, , @@ -2138,15 +2122,15 @@ } /* -%!# test cell2struct versus struct2cell +## test cell2struct versus struct2cell %!test -%! keys = cellstr (char (floor (rand (100,10)*24+65)))'; -%! vals = mat2cell(rand (100,1), ones (100,1), 1)'; -%! s = struct ([keys; vals]{:}); -%! t = cell2struct (vals, keys, 2); -%! assert (s, t); -%! assert (struct2cell (s), vals'); -%! assert (fieldnames (s), keys'); +%! keys = cellstr (char (floor (rand (100,10)*24+65)))'; +%! vals = mat2cell (rand (100,1), ones (100,1), 1)'; +%! s = struct ([keys; vals]{:}); +%! t = cell2struct (vals, keys, 2); +%! assert (s, t); +%! assert (struct2cell (s), vals'); +%! assert (fieldnames (s), keys'); %!assert (cell2struct ({1; 2}, {"a"; "b"}), struct ("a", 1, "b", 2)); */ @@ -2204,12 +2188,12 @@ } /* -%!# test rmfield +## test rmfield %!test -%! x(3).d=1; x(2).a=2; x(1).b=3; x(2).c=3; x(6).f="abc123"; -%! y = rmfield (x, {"a", "f"}); -%! assert (fieldnames (y), {"d"; "b"; "c"}); -%! assert (size (y), [1, 6]); +%! x(3).d=1; x(2).a=2; x(1).b=3; x(2).c=3; x(6).f="abc123"; +%! y = rmfield (x, {"a", "f"}); +%! assert (fieldnames (y), {"d"; "b"; "c"}); +%! assert (size (y), [1, 6]); */ DEFUN (struct_levels_to_print, args, nargout,
--- a/src/ov-typeinfo.cc +++ b/src/ov-typeinfo.cc @@ -620,72 +620,88 @@ } /* -%!error typeinfo ("foo", 1); +%!assert (iscellstr (typeinfo ())) -%!assert (iscellstr (typeinfo ())); +%!assert (typeinfo ({"cell"}), "cell") -%!assert (typeinfo (false), "bool"); -%!assert (typeinfo ([true, false]), "bool matrix"); - -%!assert (typeinfo (1:2), "range"); +%!assert (typeinfo (1), "scalar") +%!assert (typeinfo (double (1)), "scalar") +%!assert (typeinfo (i), "complex scalar") -%!assert (typeinfo ("string"), "string"); -%!assert (typeinfo ('string'), "sq_string"); - +%!assert (typeinfo ([1, 2]), "matrix") +%!assert (typeinfo (double ([1, 2])), "matrix") %!assert (typeinfo (diag ([1, 2])), "diagonal matrix") +%!assert (typeinfo ([i, 2]), "complex matrix") %!assert (typeinfo (diag ([i, 2])), "complex diagonal matrix") -%!assert (typeinfo (single (diag ([1, 2]))), "float diagonal matrix") -%!assert (typeinfo (single (diag ([i, 2]))), "float complex diagonal matrix") -%!assert (typeinfo (diag (single ([1, 2]))), "float diagonal matrix") -%!assert (typeinfo (diag (single ([i, 2]))), "float complex diagonal matrix") + +%!assert (typeinfo (1:2), "range") -%!assert (typeinfo ([]), "null_matrix"); -%!assert (typeinfo (""), "null_string"); -%!assert (typeinfo (''), "null_sq_string"); +%!assert (typeinfo (false), "bool") +%!assert (typeinfo ([true, false]), "bool matrix") + +%!assert (typeinfo ("string"), "string") +%!assert (typeinfo ('string'), "sq_string") -%!assert (typeinfo (1), "scalar"); -%!assert (typeinfo (double (1)), "scalar"); -%!assert (typeinfo ([1, 2]), "matrix"); -%!assert (typeinfo (double ([1, 2])), "matrix"); - -%!assert (typeinfo (i), "complex scalar"); -%!assert (typeinfo ([i, 2]), "complex matrix"); - -%!assert (typeinfo (single (1)), "float scalar"); -%!assert (typeinfo (single ([1, 2])), "float matrix"); +%!assert (typeinfo (int8 (1)), "int8 scalar") +%!assert (typeinfo (int16 (1)), "int16 scalar") +%!assert (typeinfo (int32 (1)), "int32 scalar") +%!assert (typeinfo (int64 (1)), "int64 scalar") +%!assert (typeinfo (uint8 (1)), "uint8 scalar") +%!assert (typeinfo (uint16 (1)), "uint16 scalar") +%!assert (typeinfo (uint32 (1)), "uint32 scalar") +%!assert (typeinfo (uint64 (1)), "uint64 scalar") -%!assert (typeinfo (single (i)), "float complex scalar"); -%!assert (typeinfo (single ([i, 2])), "float complex matrix"); - -%!assert (typeinfo (sparse (eye (10))), "sparse matrix"); -%!assert (typeinfo (sparse (i * eye (10))), "sparse complex matrix"); -%!assert (typeinfo (logical (sparse (i * eye (10)))), "sparse bool matrix"); +%!assert (typeinfo (int8 ([1,2])), "int8 matrix") +%!assert (typeinfo (int16 ([1,2])), "int16 matrix") +%!assert (typeinfo (int32 ([1,2])), "int32 matrix") +%!assert (typeinfo (int64 ([1,2])), "int64 matrix") +%!assert (typeinfo (uint8 ([1,2])), "uint8 matrix") +%!assert (typeinfo (uint16 ([1,2])), "uint16 matrix") +%!assert (typeinfo (uint32 ([1,2])), "uint32 matrix") +%!assert (typeinfo (uint64 ([1,2])), "uint64 matrix") -%!assert (typeinfo (int8 (1)), "int8 scalar"); -%!assert (typeinfo (int16 (1)), "int16 scalar"); -%!assert (typeinfo (int32 (1)), "int32 scalar"); -%!assert (typeinfo (int64 (1)), "int64 scalar"); -%!assert (typeinfo (uint8 (1)), "uint8 scalar"); -%!assert (typeinfo (uint16 (1)), "uint16 scalar"); -%!assert (typeinfo (uint32 (1)), "uint32 scalar"); -%!assert (typeinfo (uint64 (1)), "uint64 scalar"); +%!assert (typeinfo (sparse ([true, false])), "sparse bool matrix") +%!assert (typeinfo (logical (sparse (i * eye (10)))), "sparse bool matrix") +%!assert (typeinfo (sparse ([1,2])), "sparse matrix") +%!assert (typeinfo (sparse (eye (10))), "sparse matrix") +%!assert (typeinfo (sparse ([i,2])), "sparse complex matrix") +%!assert (typeinfo (sparse (i * eye (10))), "sparse complex matrix") + +%!test +%! s(2).a = 1; +%! assert (typeinfo (s), "struct"); %!test %! s.a = 1; %! assert (typeinfo (s), "scalar struct"); -%!test -%! s(2).a = 1; -%! assert (typeinfo (s), "struct"); +## FIXME: This doesn't work as a test for comma-separated list +%!#test +%! clist = {1, 2, 3}; +%! assert (typeinfo (clist{:}), "cs-list"); -%!assert (typeinfo ({"cell"}), "cell"); +%!assert (typeinfo (@sin), "function handle") +%!assert (typeinfo (@(x) x), "function handle") + +%!assert (typeinfo (inline ("x^2")), "inline function") -%!assert (typeinfo (@sin), "function handle"); -%!assert (typeinfo (@(x) x), "function handle"); +%!assert (typeinfo (single (1)), "float scalar") +%!assert (typeinfo (single (i)), "float complex scalar") +%!assert (typeinfo (single ([1, 2])), "float matrix") -%!assert (typeinfo (inline ('x^2')), "inline function"); +%!assert (typeinfo (single (diag ([1, 2]))), "float diagonal matrix") +%!assert (typeinfo (diag (single ([1, 2]))), "float diagonal matrix") +%!assert (typeinfo (single (diag ([i, 2]))), "float complex diagonal matrix") +%!assert (typeinfo (diag (single ([i, 2]))), "float complex diagonal matrix") +%!assert (typeinfo (eye(3)(:,[1 3 2])), "permutation matrix") %!test %! [l, u, p] = lu (rand (3)); %! assert (typeinfo (p), "permutation matrix"); + +%!assert (typeinfo ([]), "null_matrix") +%!assert (typeinfo (""), "null_string") +%!assert (typeinfo (''), "null_sq_string") + +%!error typeinfo ("foo", 1) */
--- a/src/ov-uint16.cc +++ b/src/ov-uint16.cc @@ -84,13 +84,10 @@ } /* - %!assert (class (uint16 (1)), "uint16") %!assert (uint16 (1.25), uint16 (1)) %!assert (uint16 (1.5), uint16 (2)) %!assert (uint16 (-1.5), uint16 (0)) %!assert (uint16 (2^17), uint16 (2^16-1)) %!assert (uint16 (-2^17), uint16 (0)) - */ -
--- a/src/ov-uint32.cc +++ b/src/ov-uint32.cc @@ -84,12 +84,10 @@ } /* - %!assert (class (uint32 (1)), "uint32") %!assert (uint32 (1.25), uint32 (1)) %!assert (uint32 (1.5), uint32 (2)) %!assert (uint32 (-1.5), uint32 (0)) %!assert (uint32 (2^33), uint32 (2^32-1)) %!assert (uint32 (-2^33), uint32 (0)) - */
--- a/src/ov-uint64.cc +++ b/src/ov-uint64.cc @@ -84,12 +84,10 @@ } /* - %!assert (class (uint64 (1)), "uint64") %!assert (uint64 (1.25), uint64 (1)) %!assert (uint64 (1.5), uint64 (2)) %!assert (uint64 (-1.5), uint64 (0)) %!assert (uint64 (2^65), uint64 (2^64-1)) %!assert (uint64 (-2^65), uint64 (0)) - */
--- a/src/ov-uint8.cc +++ b/src/ov-uint8.cc @@ -84,12 +84,10 @@ } /* - %!assert (class (uint8 (1)), "uint8") %!assert (uint8 (1.25), uint8 (1)) %!assert (uint8 (1.5), uint8 (2)) %!assert (uint8 (-1.5), uint8 (0)) %!assert (uint8 (2^9), uint8 (2^8-1)) %!assert (uint8 (-2^9), uint8 (0)) - */
--- a/src/ov.cc +++ b/src/ov.cc @@ -2944,7 +2944,7 @@ %! 0 8 0 18 0 %! 0 0 14 0 0 %! 0 10 15 20 0]; -%! assert (a,b); +%! assert (a, b); %!test %! c = num2cell (reshape ([1:25],5,5)); @@ -2989,7 +2989,6 @@ %! t.b = "There"; %! t.c = 163; %! assert (s, t); - */ DEFUN (is_sq_string, args, , @@ -3010,10 +3009,11 @@ } /* -%!assert (is_sq_string ('foo'), true); -%!assert (is_sq_string ("foo"), false); -%!assert (is_sq_string (1.0), false); -%!assert (is_sq_string ({2.0}), false); +%!assert (is_sq_string ('foo'), true) +%!assert (is_sq_string ("foo"), false) +%!assert (is_sq_string (1.0), false) +%!assert (is_sq_string ({2.0}), false) + %!error is_sq_string () %!error is_sq_string ('foo', 2) */ @@ -3036,10 +3036,11 @@ } /* -%!assert (is_dq_string ("foo"), true); -%!assert (is_dq_string ('foo'), false); -%!assert (is_dq_string (1.0), false); -%!assert (is_dq_string ({2.0}), false); +%!assert (is_dq_string ("foo"), true) +%!assert (is_dq_string ('foo'), false) +%!assert (is_dq_string (1.0), false) +%!assert (is_dq_string ({2.0}), false) + %!error is_dq_string () %!error is_dq_string ("foo", 2) */
--- a/src/pr-output.cc +++ b/src/pr-output.cc @@ -3555,12 +3555,12 @@ %! foo.cell = {foo.real, foo.complex, foo.char}; %! fields = fieldnames (foo); %! for f = 1:numel(fields) -%! format loose +%! format loose; %! loose = disp (foo.(fields{f})); -%! format compact +%! format compact; %! compact = disp (foo.(fields{f})); %! expected = strrep (loose, "\n\n", "\n"); -%! assert (expected, compact) +%! assert (expected, compact); %! endfor */
--- a/src/pt-binop.cc +++ b/src/pt-binop.cc @@ -302,7 +302,6 @@ } /* - %!test %! x = 0; %! do_braindead_shortcircuit_evaluation (0); @@ -313,6 +312,4 @@ %! if (1 | (x = 0)) %! endif %! assert (x, 1); - */ -
--- a/src/pt-eval.cc +++ b/src/pt-eval.cc @@ -1207,7 +1207,6 @@ } /* -%!error (max_recursion_depth (1, 2)); %!test %! orig_val = max_recursion_depth (); %! old_val = max_recursion_depth (2*orig_val); @@ -1215,6 +1214,8 @@ %! assert (max_recursion_depth (), 2*orig_val); %! max_recursion_depth (orig_val); %! assert (max_recursion_depth (), orig_val); + +%!error (max_recursion_depth (1, 2)) */ DEFUN (silent_functions, args, nargout, @@ -1236,7 +1237,6 @@ } /* -%!error (silent_functions (1, 2)); %!test %! orig_val = silent_functions (); %! old_val = silent_functions (! orig_val); @@ -1244,4 +1244,6 @@ %! assert (silent_functions (), ! orig_val); %! silent_functions (orig_val); %! assert (silent_functions (), orig_val); + +%!error (silent_functions (1, 2)) */
--- a/src/pt-idx.cc +++ b/src/pt-idx.cc @@ -601,13 +601,13 @@ /* %!test -%! clear x -%! clear y +%! clear x; +%! clear y; %! y = 3; %! x(y(end)) = 1; %! assert (x, [0, 0, 1]); -%! clear x -%! clear y +%! clear x; +%! clear y; %! y = {3}; %! x(y{end}) = 1; %! assert (x, [0, 0, 1]);
--- a/src/pt-mat.cc +++ b/src/pt-mat.cc @@ -1193,198 +1193,198 @@ } /* -%% test concatenation with all zero matrices -%!assert([ '' 65*ones(1,10) ], 'AAAAAAAAAA'); -%!assert([ 65*ones(1,10) '' ], 'AAAAAAAAAA'); +## test concatenation with all zero matrices +%!assert ([ "" 65*ones(1,10) ], "AAAAAAAAAA"); +%!assert ([ 65*ones(1,10) "" ], "AAAAAAAAAA"); %!test -%! c = {'foo'; 'bar'; 'bazoloa'}; -%! assert ([c; 'a'; 'bc'; 'def'], {'foo'; 'bar'; 'bazoloa'; 'a'; 'bc'; 'def'}); +%! c = {"foo"; "bar"; "bazoloa"}; +%! assert ([c; "a"; "bc"; "def"], {"foo"; "bar"; "bazoloa"; "a"; "bc"; "def"}); -%!assert (class ([int64(1), int64(1)]), 'int64') -%!assert (class ([int64(1), int32(1)]), 'int64') -%!assert (class ([int64(1), int16(1)]), 'int64') -%!assert (class ([int64(1), int8(1)]), 'int64') -%!assert (class ([int64(1), uint64(1)]), 'int64') -%!assert (class ([int64(1), uint32(1)]), 'int64') -%!assert (class ([int64(1), uint16(1)]), 'int64') -%!assert (class ([int64(1), uint8(1)]), 'int64') -%!assert (class ([int64(1), single(1)]), 'int64') -%!assert (class ([int64(1), double(1)]), 'int64') -%!assert (class ([int64(1), cell(1)]), 'cell') -%!assert (class ([int64(1), true]), 'int64') -%!assert (class ([int64(1), 'a']), 'char') +%!assert (class ([int64(1), int64(1)]), "int64") +%!assert (class ([int64(1), int32(1)]), "int64") +%!assert (class ([int64(1), int16(1)]), "int64") +%!assert (class ([int64(1), int8(1)]), "int64") +%!assert (class ([int64(1), uint64(1)]), "int64") +%!assert (class ([int64(1), uint32(1)]), "int64") +%!assert (class ([int64(1), uint16(1)]), "int64") +%!assert (class ([int64(1), uint8(1)]), "int64") +%!assert (class ([int64(1), single(1)]), "int64") +%!assert (class ([int64(1), double(1)]), "int64") +%!assert (class ([int64(1), cell(1)]), "cell") +%!assert (class ([int64(1), true]), "int64") +%!assert (class ([int64(1), "a"]), "char") -%!assert (class ([int32(1), int64(1)]), 'int32') -%!assert (class ([int32(1), int32(1)]), 'int32') -%!assert (class ([int32(1), int16(1)]), 'int32') -%!assert (class ([int32(1), int8(1)]), 'int32') -%!assert (class ([int32(1), uint64(1)]), 'int32') -%!assert (class ([int32(1), uint32(1)]), 'int32') -%!assert (class ([int32(1), uint16(1)]), 'int32') -%!assert (class ([int32(1), uint8(1)]), 'int32') -%!assert (class ([int32(1), single(1)]), 'int32') -%!assert (class ([int32(1), double(1)]), 'int32') -%!assert (class ([int32(1), cell(1)]), 'cell') -%!assert (class ([int32(1), true]), 'int32') -%!assert (class ([int32(1), 'a']), 'char') +%!assert (class ([int32(1), int64(1)]), "int32") +%!assert (class ([int32(1), int32(1)]), "int32") +%!assert (class ([int32(1), int16(1)]), "int32") +%!assert (class ([int32(1), int8(1)]), "int32") +%!assert (class ([int32(1), uint64(1)]), "int32") +%!assert (class ([int32(1), uint32(1)]), "int32") +%!assert (class ([int32(1), uint16(1)]), "int32") +%!assert (class ([int32(1), uint8(1)]), "int32") +%!assert (class ([int32(1), single(1)]), "int32") +%!assert (class ([int32(1), double(1)]), "int32") +%!assert (class ([int32(1), cell(1)]), "cell") +%!assert (class ([int32(1), true]), "int32") +%!assert (class ([int32(1), "a"]), "char") -%!assert (class ([int16(1), int64(1)]), 'int16') -%!assert (class ([int16(1), int32(1)]), 'int16') -%!assert (class ([int16(1), int16(1)]), 'int16') -%!assert (class ([int16(1), int8(1)]), 'int16') -%!assert (class ([int16(1), uint64(1)]), 'int16') -%!assert (class ([int16(1), uint32(1)]), 'int16') -%!assert (class ([int16(1), uint16(1)]), 'int16') -%!assert (class ([int16(1), uint8(1)]), 'int16') -%!assert (class ([int16(1), single(1)]), 'int16') -%!assert (class ([int16(1), double(1)]), 'int16') -%!assert (class ([int16(1), cell(1)]), 'cell') -%!assert (class ([int16(1), true]), 'int16') -%!assert (class ([int16(1), 'a']), 'char') +%!assert (class ([int16(1), int64(1)]), "int16") +%!assert (class ([int16(1), int32(1)]), "int16") +%!assert (class ([int16(1), int16(1)]), "int16") +%!assert (class ([int16(1), int8(1)]), "int16") +%!assert (class ([int16(1), uint64(1)]), "int16") +%!assert (class ([int16(1), uint32(1)]), "int16") +%!assert (class ([int16(1), uint16(1)]), "int16") +%!assert (class ([int16(1), uint8(1)]), "int16") +%!assert (class ([int16(1), single(1)]), "int16") +%!assert (class ([int16(1), double(1)]), "int16") +%!assert (class ([int16(1), cell(1)]), "cell") +%!assert (class ([int16(1), true]), "int16") +%!assert (class ([int16(1), "a"]), "char") -%!assert (class ([int8(1), int64(1)]), 'int8') -%!assert (class ([int8(1), int32(1)]), 'int8') -%!assert (class ([int8(1), int16(1)]), 'int8') -%!assert (class ([int8(1), int8(1)]), 'int8') -%!assert (class ([int8(1), uint64(1)]), 'int8') -%!assert (class ([int8(1), uint32(1)]), 'int8') -%!assert (class ([int8(1), uint16(1)]), 'int8') -%!assert (class ([int8(1), uint8(1)]), 'int8') -%!assert (class ([int8(1), single(1)]), 'int8') -%!assert (class ([int8(1), double(1)]), 'int8') -%!assert (class ([int8(1), cell(1)]), 'cell') -%!assert (class ([int8(1), true]), 'int8') -%!assert (class ([int8(1), 'a']), 'char') +%!assert (class ([int8(1), int64(1)]), "int8") +%!assert (class ([int8(1), int32(1)]), "int8") +%!assert (class ([int8(1), int16(1)]), "int8") +%!assert (class ([int8(1), int8(1)]), "int8") +%!assert (class ([int8(1), uint64(1)]), "int8") +%!assert (class ([int8(1), uint32(1)]), "int8") +%!assert (class ([int8(1), uint16(1)]), "int8") +%!assert (class ([int8(1), uint8(1)]), "int8") +%!assert (class ([int8(1), single(1)]), "int8") +%!assert (class ([int8(1), double(1)]), "int8") +%!assert (class ([int8(1), cell(1)]), "cell") +%!assert (class ([int8(1), true]), "int8") +%!assert (class ([int8(1), "a"]), "char") -%!assert (class ([uint64(1), int64(1)]), 'uint64') -%!assert (class ([uint64(1), int32(1)]), 'uint64') -%!assert (class ([uint64(1), int16(1)]), 'uint64') -%!assert (class ([uint64(1), int8(1)]), 'uint64') -%!assert (class ([uint64(1), uint64(1)]), 'uint64') -%!assert (class ([uint64(1), uint32(1)]), 'uint64') -%!assert (class ([uint64(1), uint16(1)]), 'uint64') -%!assert (class ([uint64(1), uint8(1)]), 'uint64') -%!assert (class ([uint64(1), single(1)]), 'uint64') -%!assert (class ([uint64(1), double(1)]), 'uint64') -%!assert (class ([uint64(1), cell(1)]), 'cell') -%!assert (class ([uint64(1), true]), 'uint64') -%!assert (class ([uint64(1), 'a']), 'char') +%!assert (class ([uint64(1), int64(1)]), "uint64") +%!assert (class ([uint64(1), int32(1)]), "uint64") +%!assert (class ([uint64(1), int16(1)]), "uint64") +%!assert (class ([uint64(1), int8(1)]), "uint64") +%!assert (class ([uint64(1), uint64(1)]), "uint64") +%!assert (class ([uint64(1), uint32(1)]), "uint64") +%!assert (class ([uint64(1), uint16(1)]), "uint64") +%!assert (class ([uint64(1), uint8(1)]), "uint64") +%!assert (class ([uint64(1), single(1)]), "uint64") +%!assert (class ([uint64(1), double(1)]), "uint64") +%!assert (class ([uint64(1), cell(1)]), "cell") +%!assert (class ([uint64(1), true]), "uint64") +%!assert (class ([uint64(1), "a"]), "char") -%!assert (class ([uint32(1), int64(1)]), 'uint32') -%!assert (class ([uint32(1), int32(1)]), 'uint32') -%!assert (class ([uint32(1), int16(1)]), 'uint32') -%!assert (class ([uint32(1), int8(1)]), 'uint32') -%!assert (class ([uint32(1), uint64(1)]), 'uint32') -%!assert (class ([uint32(1), uint32(1)]), 'uint32') -%!assert (class ([uint32(1), uint16(1)]), 'uint32') -%!assert (class ([uint32(1), uint8(1)]), 'uint32') -%!assert (class ([uint32(1), single(1)]), 'uint32') -%!assert (class ([uint32(1), double(1)]), 'uint32') -%!assert (class ([uint32(1), cell(1)]), 'cell') -%!assert (class ([uint32(1), true]), 'uint32') -%!assert (class ([uint32(1), 'a']), 'char') +%!assert (class ([uint32(1), int64(1)]), "uint32") +%!assert (class ([uint32(1), int32(1)]), "uint32") +%!assert (class ([uint32(1), int16(1)]), "uint32") +%!assert (class ([uint32(1), int8(1)]), "uint32") +%!assert (class ([uint32(1), uint64(1)]), "uint32") +%!assert (class ([uint32(1), uint32(1)]), "uint32") +%!assert (class ([uint32(1), uint16(1)]), "uint32") +%!assert (class ([uint32(1), uint8(1)]), "uint32") +%!assert (class ([uint32(1), single(1)]), "uint32") +%!assert (class ([uint32(1), double(1)]), "uint32") +%!assert (class ([uint32(1), cell(1)]), "cell") +%!assert (class ([uint32(1), true]), "uint32") +%!assert (class ([uint32(1), "a"]), "char") -%!assert (class ([uint16(1), int64(1)]), 'uint16') -%!assert (class ([uint16(1), int32(1)]), 'uint16') -%!assert (class ([uint16(1), int16(1)]), 'uint16') -%!assert (class ([uint16(1), int8(1)]), 'uint16') -%!assert (class ([uint16(1), uint64(1)]), 'uint16') -%!assert (class ([uint16(1), uint32(1)]), 'uint16') -%!assert (class ([uint16(1), uint16(1)]), 'uint16') -%!assert (class ([uint16(1), uint8(1)]), 'uint16') -%!assert (class ([uint16(1), single(1)]), 'uint16') -%!assert (class ([uint16(1), double(1)]), 'uint16') -%!assert (class ([uint16(1), cell(1)]), 'cell') -%!assert (class ([uint16(1), true]), 'uint16') -%!assert (class ([uint16(1), 'a']), 'char') +%!assert (class ([uint16(1), int64(1)]), "uint16") +%!assert (class ([uint16(1), int32(1)]), "uint16") +%!assert (class ([uint16(1), int16(1)]), "uint16") +%!assert (class ([uint16(1), int8(1)]), "uint16") +%!assert (class ([uint16(1), uint64(1)]), "uint16") +%!assert (class ([uint16(1), uint32(1)]), "uint16") +%!assert (class ([uint16(1), uint16(1)]), "uint16") +%!assert (class ([uint16(1), uint8(1)]), "uint16") +%!assert (class ([uint16(1), single(1)]), "uint16") +%!assert (class ([uint16(1), double(1)]), "uint16") +%!assert (class ([uint16(1), cell(1)]), "cell") +%!assert (class ([uint16(1), true]), "uint16") +%!assert (class ([uint16(1), "a"]), "char") -%!assert (class ([uint8(1), int64(1)]), 'uint8') -%!assert (class ([uint8(1), int32(1)]), 'uint8') -%!assert (class ([uint8(1), int16(1)]), 'uint8') -%!assert (class ([uint8(1), int8(1)]), 'uint8') -%!assert (class ([uint8(1), uint64(1)]), 'uint8') -%!assert (class ([uint8(1), uint32(1)]), 'uint8') -%!assert (class ([uint8(1), uint16(1)]), 'uint8') -%!assert (class ([uint8(1), uint8(1)]), 'uint8') -%!assert (class ([uint8(1), single(1)]), 'uint8') -%!assert (class ([uint8(1), double(1)]), 'uint8') -%!assert (class ([uint8(1), cell(1)]), 'cell') -%!assert (class ([uint8(1), true]), 'uint8') -%!assert (class ([uint8(1), 'a']), 'char') +%!assert (class ([uint8(1), int64(1)]), "uint8") +%!assert (class ([uint8(1), int32(1)]), "uint8") +%!assert (class ([uint8(1), int16(1)]), "uint8") +%!assert (class ([uint8(1), int8(1)]), "uint8") +%!assert (class ([uint8(1), uint64(1)]), "uint8") +%!assert (class ([uint8(1), uint32(1)]), "uint8") +%!assert (class ([uint8(1), uint16(1)]), "uint8") +%!assert (class ([uint8(1), uint8(1)]), "uint8") +%!assert (class ([uint8(1), single(1)]), "uint8") +%!assert (class ([uint8(1), double(1)]), "uint8") +%!assert (class ([uint8(1), cell(1)]), "cell") +%!assert (class ([uint8(1), true]), "uint8") +%!assert (class ([uint8(1), "a"]), "char") -%!assert (class ([single(1), int64(1)]), 'int64') -%!assert (class ([single(1), int32(1)]), 'int32') -%!assert (class ([single(1), int16(1)]), 'int16') -%!assert (class ([single(1), int8(1)]), 'int8') -%!assert (class ([single(1), uint64(1)]), 'uint64') -%!assert (class ([single(1), uint32(1)]), 'uint32') -%!assert (class ([single(1), uint16(1)]), 'uint16') -%!assert (class ([single(1), uint8(1)]), 'uint8') -%!assert (class ([single(1), single(1)]), 'single') -%!assert (class ([single(1), double(1)]), 'single') -%!assert (class ([single(1), cell(1)]), 'cell') -%!assert (class ([single(1), true]), 'single') -%!assert (class ([single(1), 'a']), 'char') +%!assert (class ([single(1), int64(1)]), "int64") +%!assert (class ([single(1), int32(1)]), "int32") +%!assert (class ([single(1), int16(1)]), "int16") +%!assert (class ([single(1), int8(1)]), "int8") +%!assert (class ([single(1), uint64(1)]), "uint64") +%!assert (class ([single(1), uint32(1)]), "uint32") +%!assert (class ([single(1), uint16(1)]), "uint16") +%!assert (class ([single(1), uint8(1)]), "uint8") +%!assert (class ([single(1), single(1)]), "single") +%!assert (class ([single(1), double(1)]), "single") +%!assert (class ([single(1), cell(1)]), "cell") +%!assert (class ([single(1), true]), "single") +%!assert (class ([single(1), "a"]), "char") -%!assert (class ([double(1), int64(1)]), 'int64') -%!assert (class ([double(1), int32(1)]), 'int32') -%!assert (class ([double(1), int16(1)]), 'int16') -%!assert (class ([double(1), int8(1)]), 'int8') -%!assert (class ([double(1), uint64(1)]), 'uint64') -%!assert (class ([double(1), uint32(1)]), 'uint32') -%!assert (class ([double(1), uint16(1)]), 'uint16') -%!assert (class ([double(1), uint8(1)]), 'uint8') -%!assert (class ([double(1), single(1)]), 'single') -%!assert (class ([double(1), double(1)]), 'double') -%!assert (class ([double(1), cell(1)]), 'cell') -%!assert (class ([double(1), true]), 'double') -%!assert (class ([double(1), 'a']), 'char') +%!assert (class ([double(1), int64(1)]), "int64") +%!assert (class ([double(1), int32(1)]), "int32") +%!assert (class ([double(1), int16(1)]), "int16") +%!assert (class ([double(1), int8(1)]), "int8") +%!assert (class ([double(1), uint64(1)]), "uint64") +%!assert (class ([double(1), uint32(1)]), "uint32") +%!assert (class ([double(1), uint16(1)]), "uint16") +%!assert (class ([double(1), uint8(1)]), "uint8") +%!assert (class ([double(1), single(1)]), "single") +%!assert (class ([double(1), double(1)]), "double") +%!assert (class ([double(1), cell(1)]), "cell") +%!assert (class ([double(1), true]), "double") +%!assert (class ([double(1), "a"]), "char") -%!assert (class ([cell(1), int64(1)]), 'cell') -%!assert (class ([cell(1), int32(1)]), 'cell') -%!assert (class ([cell(1), int16(1)]), 'cell') -%!assert (class ([cell(1), int8(1)]), 'cell') -%!assert (class ([cell(1), uint64(1)]), 'cell') -%!assert (class ([cell(1), uint32(1)]), 'cell') -%!assert (class ([cell(1), uint16(1)]), 'cell') -%!assert (class ([cell(1), uint8(1)]), 'cell') -%!assert (class ([cell(1), single(1)]), 'cell') -%!assert (class ([cell(1), double(1)]), 'cell') -%!assert (class ([cell(1), cell(1)]), 'cell') -%!assert (class ([cell(1), true]), 'cell') -%!assert (class ([cell(1), 'a']), 'cell') +%!assert (class ([cell(1), int64(1)]), "cell") +%!assert (class ([cell(1), int32(1)]), "cell") +%!assert (class ([cell(1), int16(1)]), "cell") +%!assert (class ([cell(1), int8(1)]), "cell") +%!assert (class ([cell(1), uint64(1)]), "cell") +%!assert (class ([cell(1), uint32(1)]), "cell") +%!assert (class ([cell(1), uint16(1)]), "cell") +%!assert (class ([cell(1), uint8(1)]), "cell") +%!assert (class ([cell(1), single(1)]), "cell") +%!assert (class ([cell(1), double(1)]), "cell") +%!assert (class ([cell(1), cell(1)]), "cell") +%!assert (class ([cell(1), true]), "cell") +%!assert (class ([cell(1), "a"]), "cell") -%!assert (class ([true, int64(1)]), 'int64') -%!assert (class ([true, int32(1)]), 'int32') -%!assert (class ([true, int16(1)]), 'int16') -%!assert (class ([true, int8(1)]), 'int8') -%!assert (class ([true, uint64(1)]), 'uint64') -%!assert (class ([true, uint32(1)]), 'uint32') -%!assert (class ([true, uint16(1)]), 'uint16') -%!assert (class ([true, uint8(1)]), 'uint8') -%!assert (class ([true, single(1)]), 'single') -%!assert (class ([true, double(1)]), 'double') -%!assert (class ([true, cell(1)]), 'cell') -%!assert (class ([true, true]), 'logical') -%!assert (class ([true, 'a']), 'char') +%!assert (class ([true, int64(1)]), "int64") +%!assert (class ([true, int32(1)]), "int32") +%!assert (class ([true, int16(1)]), "int16") +%!assert (class ([true, int8(1)]), "int8") +%!assert (class ([true, uint64(1)]), "uint64") +%!assert (class ([true, uint32(1)]), "uint32") +%!assert (class ([true, uint16(1)]), "uint16") +%!assert (class ([true, uint8(1)]), "uint8") +%!assert (class ([true, single(1)]), "single") +%!assert (class ([true, double(1)]), "double") +%!assert (class ([true, cell(1)]), "cell") +%!assert (class ([true, true]), "logical") +%!assert (class ([true, "a"]), "char") -%!assert (class (['a', int64(1)]), 'char') -%!assert (class (['a', int32(1)]), 'char') -%!assert (class (['a', int16(1)]), 'char') -%!assert (class (['a', int8(1)]), 'char') -%!assert (class (['a', int64(1)]), 'char') -%!assert (class (['a', int32(1)]), 'char') -%!assert (class (['a', int16(1)]), 'char') -%!assert (class (['a', int8(1)]), 'char') -%!assert (class (['a', single(1)]), 'char') -%!assert (class (['a', double(1)]), 'char') -%!assert (class (['a', cell(1)]), 'cell') -%!assert (class (['a', true]), 'char') -%!assert (class (['a', 'a']), 'char') +%!assert (class (["a", int64(1)]), "char") +%!assert (class (["a", int32(1)]), "char") +%!assert (class (["a", int16(1)]), "char") +%!assert (class (["a", int8(1)]), "char") +%!assert (class (["a", int64(1)]), "char") +%!assert (class (["a", int32(1)]), "char") +%!assert (class (["a", int16(1)]), "char") +%!assert (class (["a", int8(1)]), "char") +%!assert (class (["a", single(1)]), "char") +%!assert (class (["a", double(1)]), "char") +%!assert (class (["a", cell(1)]), "cell") +%!assert (class (["a", true]), "char") +%!assert (class (["a", "a"]), "char") -%!assert (class ([cell(1), struct('foo', 'bar')]), 'cell') -%!error [struct('foo', 'bar'), cell(1)]; +%!assert (class ([cell(1), struct("foo", "bar")]), "cell") +%!error [struct("foo", "bar"), cell(1)] */ DEFUN (string_fill_char, args, nargout, @@ -1415,9 +1415,8 @@ } /* -%!error (string_fill_char (1, 2)); -%% string_fill_char() function call must be outside of %!test block -%% due to the way a %!test block is wrapped inside a function +## string_fill_char() function call must be outside of %!test block +## due to the way a %!test block is wrapped inside a function %!shared orig_val, old_val %! orig_val = string_fill_char (); %! old_val = string_fill_char ("X"); @@ -1427,4 +1426,6 @@ %! assert (["these"; "are"; "strings"], ["theseXX"; "areXXXX"; "strings"]); %! string_fill_char (orig_val); %! assert (string_fill_char (), orig_val); + +%!error (string_fill_char (1, 2)) */
--- a/src/sighandlers.cc +++ b/src/sighandlers.cc @@ -957,9 +957,10 @@ } /* -%!error SIG (1); -%!assert (isstruct (SIG ())); -%!assert (! isempty (SIG ())); +%!assert (isstruct (SIG ())) +%!assert (! isempty (SIG ())) + +%!error SIG (1) */ DEFUN (debug_on_interrupt, args, nargout, @@ -981,7 +982,6 @@ } /* -%!error (debug_on_interrupt (1, 2)); %!test %! orig_val = debug_on_interrupt (); %! old_val = debug_on_interrupt (! orig_val); @@ -989,6 +989,8 @@ %! assert (debug_on_interrupt (), ! orig_val); %! debug_on_interrupt (orig_val); %! assert (debug_on_interrupt (), orig_val); + +%!error (debug_on_interrupt (1, 2)) */ DEFUN (sighup_dumps_octave_core, args, nargout, @@ -1009,7 +1011,6 @@ } /* -%!error (sighup_dumps_octave_core (1, 2)); %!test %! orig_val = sighup_dumps_octave_core (); %! old_val = sighup_dumps_octave_core (! orig_val); @@ -1017,6 +1018,8 @@ %! assert (sighup_dumps_octave_core (), ! orig_val); %! sighup_dumps_octave_core (orig_val); %! assert (sighup_dumps_octave_core (), orig_val); + +%!error (sighup_dumps_octave_core (1, 2)) */ DEFUN (sigterm_dumps_octave_core, args, nargout, @@ -1037,7 +1040,6 @@ } /* -%!error (sigterm_dumps_octave_core (1, 2)); %!test %! orig_val = sigterm_dumps_octave_core (); %! old_val = sigterm_dumps_octave_core (! orig_val); @@ -1045,4 +1047,6 @@ %! assert (sigterm_dumps_octave_core (), ! orig_val); %! sigterm_dumps_octave_core (orig_val); %! assert (sigterm_dumps_octave_core (), orig_val); + +%!error (sigterm_dumps_octave_core (1, 2)) */
--- a/src/strfns.cc +++ b/src/strfns.cc @@ -152,23 +152,23 @@ /* %!assert (char (), ''); -%!assert (char (100) == "d"); -%!assert (all(char (100,100) == ["d";"d"])); -%!assert (all(char ({100,100}) == ["d";"d"])); -%!assert (all(char ([100,100]) == ["dd"])); -%!assert (all(char ({100,{100}}) == ["d";"d"])); -%!assert (all(char (100, [], 100) == ["d";" ";"d"])) -%!assert (all(char ({100, [], 100}) == ["d";" ";"d"])) -%!assert (all(char ({100,{100, {""}}}) == ["d";"d";" "])) -%!assert (all(char (["a";"be"], {"c", 100}) == ["a";"be";"c";"d"])) -%!assert(strcmp (char ("a", "bb", "ccc"), ["a "; "bb "; "ccc"])); -%!assert(strcmp (char ([65, 83, 67, 73, 73]), "ASCII")); +%!assert (char (100), "d"); +%!assert (char (100,100), ["d";"d"]) +%!assert (char ({100,100}), ["d";"d"]) +%!assert (char ([100,100]), ["dd"]) +%!assert (char ({100,{100}}), ["d";"d"]) +%!assert (char (100, [], 100), ["d";" ";"d"]) +%!assert (char ({100, [], 100}), ["d";" ";"d"]) +%!assert (char ({100,{100, {""}}}), ["d";"d";" "]) +%!assert (char (["a";"be"], {"c", 100}), ["a";"be";"c";"d"]) +%!assert (char ("a", "bb", "ccc"), ["a "; "bb "; "ccc"]) +%!assert (char ([65, 83, 67, 73, 73]), "ASCII") %!test %! x = char ("foo", "bar", "foobar"); -%! assert((strcmp (x(1,:), "foo ") -%! && strcmp (x(2,:), "bar ") -%! && strcmp (x(3,:), "foobar"))); +%! assert (x(1,:), "foo "); +%! assert (x(2,:), "bar "); +%! assert (x(3,:), "foobar"); */ DEFUN (strvcat, args, , @@ -286,18 +286,19 @@ } /* -%!error <Invalid call to strvcat> strvcat() %!assert (strvcat (""), ""); %!assert (strvcat (100) == "d"); -%!assert (all(strvcat (100,100) == ["d";"d"])); -%!assert (all(strvcat ({100,100}) == ["d";"d"])); -%!assert (all(strvcat ([100,100]) == ["dd"])); -%!assert (all(strvcat ({100,{100}}) == ["d";"d"])); -%!assert (all(strvcat (100, [], 100) == ["d";"d"])) -%!assert (all(strvcat ({100, [], 100}) == ["d";"d"])) -%!assert (all(strvcat ({100,{100, {""}}}) == ["d";"d"])) -%!assert (all(strvcat (["a";"be"], {"c", 100}) == ["a";"be";"c";"d"])) -%!assert(strcmp (strvcat ("a", "bb", "ccc"), ["a "; "bb "; "ccc"])); +%!assert (strvcat (100,100), ["d";"d"]) +%!assert (strvcat ({100,100}), ["d";"d"]) +%!assert (strvcat ([100,100]), ["dd"]) +%!assert (strvcat ({100,{100}}), ["d";"d"]) +%!assert (strvcat (100, [], 100), ["d";"d"]) +%!assert (strvcat ({100, [], 100}), ["d";"d"]) +%!assert (strvcat ({100,{100, {""}}}), ["d";"d"]) +%!assert (strvcat (["a";"be"], {"c", 100}), ["a";"be";"c";"d"]) +%!assert (strvcat ("a", "bb", "ccc"), ["a "; "bb "; "ccc"]) + +%!error strvcat () */ @@ -321,19 +322,20 @@ } /* -%!assert (ischar ("a"), logical (1)); -%!assert (ischar (["ab";"cd"]), logical (1)); -%!assert (ischar ({"ab"}), logical (0)); -%!assert (ischar (1), logical (0)); -%!assert(ischar ([1, 2]), logical (0)); -%!assert(ischar ([]), logical (0)); -%!assert(ischar ([1, 2; 3, 4]), logical (0)); -%!assert(ischar (""), logical (1)); -%!assert(ischar ("test"), logical (1)); -%!assert(ischar (["test"; "ing"]), logical (1)); -%!assert(ischar (struct ("foo", "bar")), logical (0)); -%!error <Invalid call to ischar> ischar (); -%!error <Invalid call to ischar> ischar ("test", 1); +%!assert (ischar ("a"), true) +%!assert (ischar (["ab";"cd"]), true) +%!assert (ischar ({"ab"}), false) +%!assert (ischar (1), false) +%!assert (ischar ([1, 2]), false) +%!assert (ischar ([]), false) +%!assert (ischar ([1, 2; 3, 4]), false) +%!assert (ischar (""), true) +%!assert (ischar ("test"), true) +%!assert (ischar (["test"; "ing"]), true) +%!assert (ischar (struct ("foo", "bar")), false) + +%!error ischar () +%!error ischar ("test", 1) */ static octave_value @@ -589,51 +591,51 @@ } /* -%!error <Invalid call to strcmp> strcmp (); -%!error <Invalid call to strcmp> strcmp ("foo", "bar", 3); -%! %!shared x -%! x = char (zeros (0, 2)); -%!assert (strcmp ('', x) == false); -%!assert (strcmp (x, '') == false); -%!assert (strcmp (x, x) == true); -## %!assert (strcmp ({''}, x) == true); -## %!assert (strcmp ({x}, '') == false); -## %!assert (strcmp ({x}, x) == true); -## %!assert (strcmp ('', {x}) == false); -## %!assert (strcmp (x, {''}) == false); -## %!assert (strcmp (x, {x}) == true); -## %!assert (all (strcmp ({x; x}, '') == [false; false])); -## %!assert (all (strcmp ({x; x}, {''}) == [false; false])); -## %!assert (all (strcmp ('', {x; x}) == [false; false])); -## %!assert (all (strcmp ({''}, {x; x}) == [false; false])); -%!assert (strcmp ({'foo'}, x) == false); -%!assert (strcmp ({'foo'}, 'foo') == true); -%!assert (strcmp ({'foo'}, x) == false); -%!assert (strcmp (x, {'foo'}) == false); -%!assert (strcmp ('foo', {'foo'}) == true); -%!assert (strcmp (x, {'foo'}) == false); +%! x = char (zeros (0, 2)); +%!assert (strcmp ("", x), false) +%!assert (strcmp (x, ""), false) +%!assert (strcmp (x, x), true) +## %!assert (strcmp ({""}, x), true) +## %!assert (strcmp ({x}, ""), false) +## %!assert (strcmp ({x}, x), true) +## %!assert (strcmp ("", {x}), false) +## %!assert (strcmp (x, {""}), false) +## %!assert (strcmp (x, {x}), true) +## %!assert (strcmp ({x; x}, ""), [false; false]) +## %!assert (strcmp ({x; x}, {""}), [false; false]) +## %!assert (strcmp ("", {x; x}), [false; false]) +## %!assert (strcmp ({""}, {x; x}), [false; false]) +%!assert (strcmp ({"foo"}, x), false) +%!assert (strcmp ({"foo"}, "foo"), true) +%!assert (strcmp ({"foo"}, x), false) +%!assert (strcmp (x, {"foo"}), false) +%!assert (strcmp ("foo", {"foo"}), true) +%!assert (strcmp (x, {"foo"}), false) %!shared y -%! y = char (zeros (2, 0)); -%!assert (strcmp ('', y) == false); -%!assert (strcmp (y, '') == false); -%!assert (strcmp (y, y) == true); -%!assert (all (strcmp ({''}, y) == [true; true])); -%!assert (strcmp ({y}, '') == true); -%!assert (all (strcmp ({y}, y) == [true; true])); -%!assert (all (strcmp ('', {y}) == [true; true])); -%!assert (all (strcmp (y, {''}) == [true; true])); -%!assert (all (strcmp (y, {y}) == [true; true])); -%!assert (all (strcmp ({y; y}, '') == [true; true])); -%!assert (all (strcmp ({y; y}, {''}) == [true; true])); -%!assert (all (strcmp ('', {y; y}) == [true; true])); -%!assert (all (strcmp ({''}, {y; y}) == [true; true])); -%!assert (all (strcmp ({'foo'}, y) == [false; false])); -%!assert (all (strcmp ({'foo'}, y) == [false; false])); -%!assert (all (strcmp (y, {'foo'}) == [false; false])); -%!assert (all (strcmp (y, {'foo'}) == [false; false])); -%!assert (strcmp ("foobar", "foobar"), true); -%!assert (strcmp ("fooba", "foobar"), false); +%! y = char (zeros (2, 0)); +%!assert (strcmp ("", y), false) +%!assert (strcmp (y, ""), false) +%!assert (strcmp (y, y), true) +%!assert (strcmp ({""}, y), [true; true]) +%!assert (strcmp ({y}, ""), true) +%!assert (strcmp ({y}, y), [true; true]) +%!assert (strcmp ("", {y}), true) +%!assert (strcmp (y, {""}), [true; true]) +%!assert (strcmp (y, {y}), [true; true]) +%!assert (strcmp ({y; y}, ""), [true; true]) +%!assert (strcmp ({y; y}, {""}), [true; true]) +%!assert (strcmp ("", {y; y}), [true; true]) +%!assert (strcmp ({""}, {y; y}), [true; true]) +%!assert (strcmp ({"foo"}, y), [false; false]) +%!assert (strcmp ({"foo"}, y), [false; false]) +%!assert (strcmp (y, {"foo"}), [false; false]) +%!assert (strcmp (y, {"foo"}), [false; false]) +%!assert (strcmp ("foobar", "foobar"), true) +%!assert (strcmp ("fooba", "foobar"), false) + +%!error strcmp () +%!error strcmp ("foo", "bar", 3) */ // Apparently, Matlab ignores the dims with strncmp. It also @@ -712,15 +714,16 @@ } /* -%!error <Invalid call to strncmp> strncmp (); -%!error <Invalid call to strncmp> strncmp ("abc", "def"); -%!assert (strncmp ("abce", "abc", 3) == 1) -%!assert (strncmp (100, 100, 1) == 0) -%!assert (all (strncmp ("abce", {"abcd", "bca", "abc"}, 3) == [1, 0, 1])) -%!assert (all (strncmp ("abc", {"abcd", "bca", "abc"}, 4) == [0, 0, 0])) -%!assert (all (strncmp ({"abcd", "bca", "abc"},"abce", 3) == [1, 0, 1])) -%!assert (all (strncmp ({"abcd", "bca", "abc"},{"abcd", "bca", "abe"}, 3) == [1, 1, 0])) -%!assert (all (strncmp("abc", {"abcd", 10}, 2) == [1, 0])) +%!assert (strncmp ("abce", "abc", 3), true) +%!assert (strncmp (100, 100, 1), false) +%!assert (strncmp ("abce", {"abcd", "bca", "abc"}, 3), logical ([1, 0, 1])) +%!assert (strncmp ("abc", {"abcd", "bca", "abc"}, 4), logical ([0, 0, 0])) +%!assert (strncmp ({"abcd", "bca", "abc"},"abce", 3), logical ([1, 0, 1])) +%!assert (strncmp ({"abcd", "bca", "abc"},{"abcd", "bca", "abe"}, 3), logical ([1, 1, 0])) +%!assert (strncmp ("abc", {"abcd", 10}, 2), logical ([1, 0])) + +%!error strncmp () +%!error strncmp ("abc", "def") */ // case-insensitive character equality functor @@ -783,7 +786,7 @@ } /* -%!assert (strcmpi("abc123", "ABC123"), logical(1)); +%!assert (strcmpi ("abc123", "ABC123"), true) */ // Like strncmp. @@ -850,7 +853,7 @@ } /* -%!assert (strncmpi("abc123", "ABC456", 3), logical(1)); +%!assert (strncmpi ("abc123", "ABC456", 3), true) */ DEFUN (list_in_columns, args, , @@ -923,15 +926,16 @@ } /* -%!error <Invalid call to list_in_columns> list_in_columns (); -%!error <Invalid call to list_in_columns> list_in_columns (["abc", "def"], 20, 2); -%!error <invalid conversion from string to real scalar> list_in_columns (["abc", "def"], "a"); +%!test +%! input = {"abc", "def", "ghijkl", "mnop", "qrs", "tuv"}; +%! result = "abc mnop\ndef qrs\nghijkl tuv\n"; +%! assert (list_in_columns (input, 20), result); %!test -%! input = {"abc", "def", "ghijkl", "mnop", "qrs", "tuv"}; -%! result = "abc mnop\ndef qrs\nghijkl tuv\n"; -%! assert (list_in_columns (input, 20) == result); -%!test -%! input = ["abc"; "def"; "ghijkl"; "mnop"; "qrs"; "tuv"]; -%! result = "abc mnop \ndef qrs \nghijkl tuv \n"; -%! assert (list_in_columns (input, 20) == result); +%! input = ["abc"; "def"; "ghijkl"; "mnop"; "qrs"; "tuv"]; +%! result = "abc mnop \ndef qrs \nghijkl tuv \n"; +%! assert (list_in_columns (input, 20), result); + +%!error list_in_columns () +%!error list_in_columns (["abc", "def"], 20, 2) +%!error <invalid conversion from string to real scalar> list_in_columns (["abc", "def"], "a") */
--- a/src/symtab.cc +++ b/src/symtab.cc @@ -1531,11 +1531,10 @@ %! assert (ignore_function_time_stamp (), "system"); %! ignore_function_time_stamp (old_state); -%% Test input validation +## Test input validation %!error (ignore_function_time_stamp ("all", "all")) %!error (ignore_function_time_stamp ("UNKNOWN_VALUE")) %!error (ignore_function_time_stamp (42)) - */ DEFUN (__current_scope__, , ,
--- a/src/syscalls.cc +++ b/src/syscalls.cc @@ -369,46 +369,44 @@ } /* - %!test -%! if (isunix()) -%! [in, out, pid] = popen2 ("sort", "-r"); -%! EAGAIN = errno ("EAGAIN"); -%! else -%! [in, out, pid] = popen2 ("sort", "/R"); -%! EAGAIN = errno ("EINVAL"); -%! endif -%! fputs (in, "these\nare\nsome\nstrings\n"); -%! fclose (in); -%! done = false; -%! str = {}; -%! idx = 0; -%! errs = 0; -%! do -%! if (!isunix()) -%! errno (0); -%! endif -%! s = fgets (out); -%! if (ischar (s)) -%! idx++; -%! str{idx} = s; -%! elseif (errno () == EAGAIN) -%! fclear (out); -%! sleep (0.1); -%! if (++errs == 100) -%! done = true; -%! endif -%! else +%! if (isunix ()) +%! [in, out, pid] = popen2 ("sort", "-r"); +%! EAGAIN = errno ("EAGAIN"); +%! else +%! [in, out, pid] = popen2 ("sort", "/R"); +%! EAGAIN = errno ("EINVAL"); +%! endif +%! fputs (in, "these\nare\nsome\nstrings\n"); +%! fclose (in); +%! done = false; +%! str = {}; +%! idx = 0; +%! errs = 0; +%! do +%! if (!isunix ()) +%! errno (0); +%! endif +%! s = fgets (out); +%! if (ischar (s)) +%! idx++; +%! str{idx} = s; +%! elseif (errno () == EAGAIN) +%! fclear (out); +%! sleep (0.1); +%! if (++errs == 100) %! done = true; %! endif -%! until (done) -%! fclose (out); -%! if (isunix()) -%! assert(str,{"these\n","strings\n","some\n","are\n"}) -%! else -%! assert(str,{"these\r\n","strings\r\n","some\r\n","are\r\n"}) -%! end - +%! else +%! done = true; +%! endif +%! until (done) +%! fclose (out); +%! if (isunix ()) +%! assert(str, {"these\n","strings\n","some\n","are\n"}); +%! else +%! assert(str, {"these\r\n","strings\r\n","some\r\n","are\r\n"}); +%! endif */ DEFUNX ("fcntl", Ffcntl, args, ,
--- a/src/sysdep.cc +++ b/src/sysdep.cc @@ -608,7 +608,7 @@ DEFALIAS (setenv, putenv); /* -%!assert (ischar (getenv ("OCTAVE_HOME"))); +%!assert (ischar (getenv ("OCTAVE_HOME"))) %!test %! setenv ("dummy_variable_that_cannot_matter", "foobar"); %! assert (getenv ("dummy_variable_that_cannot_matter"), "foobar"); @@ -722,9 +722,10 @@ } /* -%!error (pause (1, 2)); %!test %! pause (1); + +%!error (pause (1, 2)) */ DEFUN (sleep, args, , @@ -757,10 +758,11 @@ } /* -%!error (sleep ()); -%!error (sleep (1, 2)); %!test %! sleep (1); + +%!error (sleep ()) +%!error (sleep (1, 2)) */ DEFUN (usleep, args, , @@ -800,10 +802,11 @@ } /* -%!error (usleep ()); -%!error (usleep (1, 2)); %!test %! usleep (1000); + +%!error (usleep ()) +%!error (usleep (1, 2)) */ // FIXME -- maybe this should only return 1 if IEEE floating @@ -823,7 +826,7 @@ } /* -%!assert (islogical (isieee ())); +%!assert (islogical (isieee ())) */ DEFUN (native_float_format, , , @@ -838,7 +841,7 @@ } /* -%!assert (ischar (native_float_format ())); +%!assert (ischar (native_float_format ())) */ DEFUN (tilde_expand, args, ,
--- a/src/toplev.cc +++ b/src/toplev.cc @@ -1484,12 +1484,13 @@ } /* -%!error octave_config_info (1, 2); -%!assert (ischar (octave_config_info ("version"))); +%!assert (ischar (octave_config_info ("version"))) %!test %! x = octave_config_info (); %! assert (isstruct (x)); %! assert (! isempty (x)); + +%!error octave_config_info (1, 2) */ #if defined (__GNUG__) && defined (DEBUG_NEW_DELETE)
--- a/src/utils.cc +++ b/src/utils.cc @@ -117,14 +117,14 @@ } /* -%!error isvarname (); -%!error isvarname ("foo", "bar"); +%!assert (isvarname ("foo"), true) +%!assert (isvarname ("_foo"), true) +%!assert (isvarname ("_1"), true) +%!assert (isvarname ("1foo"), false) +%!assert (isvarname (""), false) -%!assert (isvarname ("foo"), true); -%!assert (isvarname ("_foo"), true); -%!assert (isvarname ("_1"), true); -%!assert (isvarname ("1foo"), false); -%!assert (isvarname (""), false); +%!error isvarname () +%!error isvarname ("foo", "bar"); */ // Return TRUE if F and G are both names for the same file. @@ -339,9 +339,6 @@ } /* -%!error file_in_loadpath (); -%!error file_in_loadpath ("foo", "bar", 1); - %!test %! f = file_in_loadpath ("plot.m"); %! assert (ischar (f)); @@ -354,6 +351,9 @@ %!test %! lst = file_in_loadpath ("$$probably_!!_not_&&_a_!!_file$$", "all"); %! assert (lst, {}); + +%!error file_in_loadpath () +%!error file_in_loadpath ("foo", "bar", 1) */ DEFUN (file_in_path, args, , @@ -422,10 +422,6 @@ } /* -%!error file_in_path (); -%!error file_in_path ("foo"); -%!error file_in_path ("foo", "bar", "baz", 1); - %!test %! f = file_in_path (path (), "plot.m"); %! assert (ischar (f)); @@ -438,6 +434,10 @@ %!test %! lst = file_in_path (path (), "$$probably_!!_not_&&_a_!!_file$$", "all"); %! assert (lst, {}); + +%!error file_in_path () +%!error file_in_path ("foo") +%!error file_in_path ("foo", "bar", "baz", 1) */ std::string @@ -674,19 +674,19 @@ } /* -%!error do_string_escapes (); -%!error do_string_escapes ("foo", "bar"); +%!assert (do_string_escapes ('foo\nbar'), "foo\nbar") +%!assert (do_string_escapes ("foo\\nbar"), "foo\nbar") +%!assert (do_string_escapes ("foo\\nbar"), ["foo", char(10), "bar"]) +%!assert ("foo\nbar", ["foo", char(10), "bar"]) -%!assert (do_string_escapes ('foo\nbar'), "foo\nbar"); -%!assert (do_string_escapes ("foo\\nbar"), "foo\nbar"); -%!assert (do_string_escapes ("foo\\nbar"), ["foo", char(10), "bar"]); -%!assert ("foo\nbar", ["foo", char(10), "bar"]); +%!assert (do_string_escapes ('\a\b\f\n\r\t\v'), "\a\b\f\n\r\t\v") +%!assert (do_string_escapes ("\\a\\b\\f\\n\\r\\t\\v"), "\a\b\f\n\r\t\v") +%!assert (do_string_escapes ("\\a\\b\\f\\n\\r\\t\\v"), +%! char ([7, 8, 12, 10, 13, 9, 11])) +%!assert ("\a\b\f\n\r\t\v", char ([7, 8, 12, 10, 13, 9, 11])) -%!assert (do_string_escapes ('\a\b\f\n\r\t\v'), "\a\b\f\n\r\t\v"); -%!assert (do_string_escapes ("\\a\\b\\f\\n\\r\\t\\v"), "\a\b\f\n\r\t\v"); -%!assert (do_string_escapes ("\\a\\b\\f\\n\\r\\t\\v"), -%! char ([7, 8, 12, 10, 13, 9, 11])); -%!assert ("\a\b\f\n\r\t\v", char ([7, 8, 12, 10, 13, 9, 11])); +%!error do_string_escapes () +%!error do_string_escapes ("foo", "bar") */ const char * @@ -796,17 +796,17 @@ } /* -%!error undo_string_escapes (); -%!error undo_string_escapes ("foo", "bar"); +%!assert (undo_string_escapes ("foo\nbar"), 'foo\nbar') +%!assert (undo_string_escapes ("foo\nbar"), "foo\\nbar") +%!assert (undo_string_escapes (["foo", char(10), "bar"]), "foo\\nbar") -%!assert (undo_string_escapes ("foo\nbar"), 'foo\nbar'); -%!assert (undo_string_escapes ("foo\nbar"), "foo\\nbar"); -%!assert (undo_string_escapes (["foo", char(10), "bar"]), "foo\\nbar"); +%!assert (undo_string_escapes ("\a\b\f\n\r\t\v"), '\a\b\f\n\r\t\v') +%!assert (undo_string_escapes ("\a\b\f\n\r\t\v"), "\\a\\b\\f\\n\\r\\t\\v") +%!assert (undo_string_escapes (char ([7, 8, 12, 10, 13, 9, 11])), +%! "\\a\\b\\f\\n\\r\\t\\v") -%!assert (undo_string_escapes ("\a\b\f\n\r\t\v"), '\a\b\f\n\r\t\v'); -%!assert (undo_string_escapes ("\a\b\f\n\r\t\v"), "\\a\\b\\f\\n\\r\\t\\v"); -%!assert (undo_string_escapes (char ([7, 8, 12, 10, 13, 9, 11])), -%! "\\a\\b\\f\\n\\r\\t\\v"); +%!error undo_string_escapes () +%!error undo_string_escapes ("foo", "bar") */ DEFUN (is_absolute_filename, args, , @@ -828,10 +828,10 @@ } /* -%!error is_absolute_filename (); -%!error is_absolute_filename ("foo", "bar"); +## FIXME: We need system-dependent tests here. -FIXME -- we need system-dependent tests here. +%!error is_absolute_filename () +%!error is_absolute_filename ("foo", "bar") */ DEFUN (is_rooted_relative_filename, args, , @@ -853,10 +853,10 @@ } /* -%!error is_rooted_relative_filename (); -%!error is_rooted_relative_filename ("foo", "bar"); +## FIXME: We need system-dependent tests here. -FIXME -- we need system-dependent tests here. +%!error is_rooted_relative_filename () +%!error is_rooted_relative_filename ("foo", "bar") */ DEFUN (make_absolute_filename, args, , @@ -884,10 +884,10 @@ } /* -%!error make_absolute_filename (); -%!error make_absolute_filename ("foo", "bar"); +## FIXME: We need system-dependent tests here. -FIXME -- we need system-dependent tests here. +%!error make_absolute_filename () +%!error make_absolute_filename ("foo", "bar") */ DEFUN (find_dir_in_path, args, , @@ -931,10 +931,10 @@ } /* -%!error find_dir_in_path (); -%!error find_dir_in_path ("foo", "bar", 1); +## FIXME: We need system-dependent tests here. -FIXME -- need to create tests using current path, pathsep, and dirsep. +%!error find_dir_in_path () +%!error find_dir_in_path ("foo", "bar", 1) */ DEFUNX ("errno", Ferrno, args, , @@ -982,9 +982,7 @@ } /* -%!error errno ("foo", 1); - -%!assert (isnumeric (errno ())); +%!assert (isnumeric (errno ())) %!test %! lst = errno_list (); @@ -994,6 +992,8 @@ %! errno (oldval); %! newval = errno (); %! assert (oldval, newval); + +%!error errno ("foo", 1) */ DEFUN (errno_list, args, , @@ -1013,9 +1013,9 @@ } /* -%!error errno_list ("foo"); +%!assert (isstruct (errno_list ())) -%!assert (isstruct (errno_list ())); +%!error errno_list ("foo") */ static void @@ -1331,11 +1331,11 @@ } /* -%!error isindex (); +%!assert (isindex ([1, 2, 3])) +%!assert (isindex (1:3)) +%!assert (isindex ([1, 2, -3]), false) -%!assert (isindex ([1, 2, 3])); -%!assert (isindex (1:3)); -%!assert (isindex ([1, 2, -3]), false); +%!error isindex () */ octave_value_list
--- a/src/variables.cc +++ b/src/variables.cc @@ -580,17 +580,17 @@ /* %!test -%! if (isunix ()) -%! assert (exist ("/tmp") == 7); -%! assert (exist ("/tmp", "file") == 7); -%! assert (exist ("/tmp", "dir") == 7); -%! assert (exist ("/bin/sh") == 2); -%! assert (exist ("/bin/sh", "file") == 2); -%! assert (exist ("/bin/sh", "dir") == 0); -%! assert (exist ("/dev/null") == 2); -%! assert (exist ("/dev/null", "file") == 2); -%! assert (exist ("/dev/null", "dir") == 0); -%! endif +%! if (isunix ()) +%! assert (exist ("/tmp") == 7); +%! assert (exist ("/tmp", "file") == 7); +%! assert (exist ("/tmp", "dir") == 7); +%! assert (exist ("/bin/sh") == 2); +%! assert (exist ("/bin/sh", "file") == 2); +%! assert (exist ("/bin/sh", "dir") == 0); +%! assert (exist ("/dev/null") == 2); +%! assert (exist ("/dev/null", "file") == 2); +%! assert (exist ("/dev/null", "dir") == 0); +%! endif */ octave_value