Mercurial > octave
comparison scripts/image/hot.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 = hot (n) | 38 function map = hot (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 ("hot: N must be a scalar"); | 42 error ("hot: 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)) |
114 %! 1, 1, 2/3; | 114 %! 1, 1, 2/3; |
115 %! 1, 1, 1]; | 115 %! 1, 1, 1]; |
116 %! assert (hot (11), a, eps); | 116 %! assert (hot (11), a, eps); |
117 | 117 |
118 ## Input validation | 118 ## Input validation |
119 %!error <N must be a scalar> hot ("foo") | 119 %!error <N must be a scalar integer> hot ("foo") |
120 %!error <N must be a scalar> hot ([1, 2, 3]) | 120 %!error <N must be a scalar integer> hot ([1, 2, 3]) |
121 %!error <N must be a scalar> hot ({1, 2, 3}) | 121 %!error <N must be a scalar integer> hot ({1, 2, 3}) |