octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: missing tests for cast()


From: mike sander
Subject: Re: missing tests for cast()
Date: Tue, 21 Jan 2014 20:20:03 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

On 14-01-16 01:06 PM, John W. Eaton wrote:
On 01/16/2014 12:54 PM, Rik wrote:


If we are using a script to generate the tests, then it might as well be part of the build process, similar to the way we generate a large number of tests for sparse.

jwe



I have taken feedback from earlier in this thread. Thanks for your ideas. I think i have come up with a concise set of tests for cast() using loops & cell arrays. See below.

The tests basically consist of casting each type specific min & max value to all output types & comparing the value using built in type conversion.

The tests do not include some of the suggestions, specifically:
o random values. I believe testing the extreme of each input should be sufficient.
o complex numbers.  As far a i could tell, cast() does not support complex.
o does not handle "char" type yet.


I am open to further comments / suggestions.

cheers.

<code>

## for each input type, get the type appropriate min & max (val).
## cast val to each output type & verify equivalence to built in type conversion.
## for example convert max int32 to uint8 would look like:
## val = intmax("int32")
## assert (cast (val, "uint8"), uint8(val))
%!test
%! in = { "logical", "int8", "uint8", "int16", "uint16", "int32", "uint32", "int64", "uint64", "double", "single"};
%! for i = 1:numel(in)
%! if (any (strcmp (in{i}, {"int8"; "uint8"; "int16"; "uint16"; "int32"; "uint32"; "int64"; "uint64";})))
%!          val = intmin(in{i});
%!       elseif (any (strcmp (in{i}, {"double"; "single"})))
%!          val = realmin(in{i});
%!       elseif (any (strcmp (in{i}, {"logical"})))
%!       val = false;
%!       else
%!          error ("unhandled type");
%!      endif
%! out = { {"logical",logical(val)}, {"int8",int8(val)}, {"uint8",uint8(val)}, {"int16",int16(val)}, {"uint16",uint16(val)}, \ %! {"int32",int32(val)}, {"uint32",uint32(val)}, {"int64",int64(val)}, {"uint64",uint64(val)}, {"double",double(val)}, \
%!           {"single",single(val)} };
%!   for o = 1:numel(out)
%!     assert (cast (out{i}{2}, out{o}{1}), out{o}{2})
%!   end
%! end
%! for i = 1:numel(in)
%! if (any (strcmp (in{i}, {"int8"; "uint8"; "int16"; "uint16"; "int32"; "uint32"; "int64"; "uint64";})))
%!          val = intmax(in{i});
%!       elseif (any (strcmp (in{i}, {"double"; "single"})))
%!          val = realmax(in{i});
%!       elseif (any (strcmp (in{i}, {"logical"})))
%!       val = true;
%!       else
%!          error ("unhandled type");
%!      endif
%! out = { {"logical",logical(val)}, {"int8",int8(val)}, {"uint8",uint8(val)}, {"int16",int16(val)}, {"uint16",uint16(val)}, \ %! {"int32",int32(val)}, {"uint32",uint32(val)}, {"int64",int64(val)}, {"uint64",uint64(val)}, {"double",double(val)}, \
%!           {"single",single(val)} };
%!   for o = 1:numel(out)
%!     assert (cast (out{i}{2}, out{o}{1}), out{o}{2})
%!   end
%! end

</code>





reply via email to

[Prev in Thread] Current Thread [Next in Thread]