# HG changeset patch # User Rik # Date 1316560694 25200 # Node ID 8c4a2c2cc2b0ca683ac390e012cd1b8f5f73a848 # Parent 89fb0e668825e2dbcec29eb75b9fa3e4b7a38965 blanks.m: Validate input is non-negative. * blanks.m: Validate input is non-negative. diff -r 89fb0e668825 -r 8c4a2c2cc2b0 scripts/strings/blanks.m --- a/scripts/strings/blanks.m Tue Sep 20 16:08:53 2011 -0700 +++ b/scripts/strings/blanks.m Tue Sep 20 16:18:14 2011 -0700 @@ -22,7 +22,7 @@ ## ## @example ## @group -## blanks(10); +## blanks (10); ## whos ans; ## @result{} ## Attr Name Size Bytes Class @@ -40,7 +40,7 @@ if (nargin != 1) print_usage (); - elseif (! (isscalar (n) && n == round (n))) + elseif (! (isscalar (n) && n == fix (n) && n >= 0)) error ("blanks: N must be a non-negative integer"); endif @@ -50,14 +50,16 @@ endfunction + ## There really isn't that much to test here %!assert(blanks (0), "") %!assert(blanks (5), " ") %!assert(blanks (10), " ") -%!assert(strcmp (blanks (3), " ")); +%% Test input validation +%!error blanks () +%!error blanks (1, 2) +%!error blanks (ones (2)) +%!error blanks (2.1) +%!error blanks (-2) -%!error blanks (); - -%!error blanks (1, 2); -