comparison scripts/image/autumn.m @ 32737:d8e5e55c3cf5

Tighten input validation for all colormaps (bug #65011). * autumn.m, bone.m, colorcube.m, cool.m, copper.m, cubehelix.m, flag.m, gray.m, hot.m, hsv.m, jet.m, lines.m, movie.m, ocean.m, pink.m, prism.m, rainbow.m, spring.m, summer.m, turbo.m, viridis.m, white.m, winter.m: Check input N is scalar, real, and integer. Update BIST tests.
author Rik <rik@octave.org>
date Thu, 11 Jan 2024 22:06:54 -0800
parents 8dfe116fb0fe
children
comparison
equal deleted inserted replaced
32736:4214da1916cd 32737:d8e5e55c3cf5
36 ## @end deftypefn 36 ## @end deftypefn
37 37
38 function map = autumn (n) 38 function map = autumn (n)
39 39
40 if (nargin == 1) 40 if (nargin == 1)
41 if (! isscalar (n)) 41 if (! (isscalar (n) && isreal (n) && n == fix (n)))
42 error ("autumn: N must be a scalar"); 42 error ("autumn: N must be a scalar integer");
43 endif 43 endif
44 n = double (n); 44 n = double (n);
45 else 45 else
46 hf = get (0, "currentfigure"); 46 hf = get (0, "currentfigure");
47 if (! isempty (hf)) 47 if (! isempty (hf))
86 %!assert (autumn (-1), zeros (0, 3)) 86 %!assert (autumn (-1), zeros (0, 3))
87 87
88 %!assert (autumn (11), [ones(1,11); [0:0.1:1]; zeros(1,11)]', eps) 88 %!assert (autumn (11), [ones(1,11); [0:0.1:1]; zeros(1,11)]', eps)
89 89
90 ## Input validation 90 ## Input validation
91 %!error <N must be a scalar> autumn ("foo") 91 %!error <N must be a scalar integer> autumn ("foo")
92 %!error <N must be a scalar> autumn ([1, 2, 3]) 92 %!error <N must be a scalar integer> autumn ([1, 2, 3])
93 %!error <N must be a scalar> autumn ({1, 2, 3}) 93 %!error <N must be a scalar integer> autumn ({1, 2, 3})