Mercurial > hg > octave-nkf
changeset 19855:107ec5195a47
prepad.m: Fix str-to-num warnings (bug #44162)
* prepad.m: Use indexing rather than multiplication to expand constant value.
Fix adapted from cset c8e1b0213e34. Add %!tests.
* postpad.m: Add %!tests.
author | Mike Miller <mtmiller@ieee.org> |
---|---|
date | Mon, 02 Feb 2015 19:58:17 -0500 |
parents | b95aab49b6be |
children | af4ad21a82fc |
files | scripts/general/postpad.m scripts/general/prepad.m |
diffstat | 2 files changed, 9 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/general/postpad.m +++ b/scripts/general/postpad.m @@ -94,6 +94,10 @@ %!assert (postpad ([1;2], 2, 2, 3), reshape ([1;2;2;2], 2, 1, 2)) %!assert (postpad ([1,2], 2, 2, 3), reshape ([1,2,2,2], 1, 2, 2)) +%! ## Test with string concatenation (bug #44162) +%!assert (postpad ("Octave", 16, "x"), "Octavexxxxxxxxxx") +%!assert (postpad ("Octave", 4), "Octa") + %!error postpad () %!error postpad (1) %!error postpad (1,2,3,4,5)
--- a/scripts/general/prepad.m +++ b/scripts/general/prepad.m @@ -80,7 +80,7 @@ y = x(idx{:}); else sz (dim) = l - d; - y = cat (dim, c * ones (sz), x); + y = cat (dim, c(ones (sz)), x); endif endfunction @@ -97,6 +97,10 @@ %!assert (prepad ([1,2], 2, 2, 3), reshape ([2,2,1,2], 1, 2, 2)) %!assert (prepad ([1;2], 2, 2, 3), reshape ([2;2;1;2], 2, 1, 2)) +%! ## Test with string concatenation (bug #44162) +%!assert (prepad ("Octave", 16, "x"), "xxxxxxxxxxOctave") +%!assert (prepad ("Octave", 4), "tave") + ## FIXME: We need tests for multidimensional arrays. %!error prepad ()