missing tests

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

missing tests

msander
i chose a function from http://wiki.octave.org/FilesMissingTests: 
miscellaneous/cast.m

the following is what i have so far.   Looking for some feedback before
i continue.  Do the tests look sensible?  Is there a class of testing
related to cast to int8 (& other types) that i am missing?  I have tried
to follow formatting/style from other tests.

Thanks in advance for any comments/suggestions.


<code>
%% Test input validation
%!error cast (1)
%!error <cast: expecting TYPE name as second argument> cast (1,1)
%!error <cast: type name 'int' is not a built-in type> cast (1,"int")

## Test int8 cast.  input values will be limited to int8 range -128 to
127 after cast.  input values within range unchanged.
%!assert (cast (int8 (-128), "int8"), int8 (-128))
%!assert (cast (int8 (0), "int8"), int8 (0))
%!assert (cast (int8 (127), "int8"), int8 (127))
%!assert (cast (uint8 (0), "int8"), int8 (0))
%!assert (cast (uint8 (255), "int8"), int8 (127))
%!assert (cast (int16 (-1000), "int8"), int8 (-128))
%!assert (cast (int16 (0), "int8"), int8 (0))
%!assert (cast (int16 (1000), "int8"), int8 (127))
%!assert (cast (uint16 (0), "int8"), int8 (0))
%!assert (cast (uint16 (1000), "int8"), int8 (127))
%!assert (cast (int32 (-1000), "int8"), int8 (-128))
%!assert (cast (int32 (0), "int8"), int8 (0))
%!assert (cast (int32 (1000), "int8"), int8 (127))
%!assert (cast (uint32 (0), "int8"), int8 (0))
%!assert (cast (uint32 (1000), "int8"), int8 (127))
%!assert (cast (int64 (-1000), "int8"), int8 (-128))
%!assert (cast (int64 (0), "int8"), int8 (0))
%!assert (cast (int64 (1000), "int8"), int8 (127))
%!assert (cast (uint64 (0), "int8"), int8 (0))
%!assert (cast (uint64 (1000), "int8"), int8 (127))
%!assert (cast (double (-1000), "int8"), int8 (-128))
%!assert (cast (double (0), "int8"), int8 (0))
%!assert (cast (double (1000), "int8"), int8 (127))
%!assert (cast (single (-1000), "int8"), int8 (-128))
%!assert (cast (single (0), "int8"), int8 (0))
%!assert (cast (single (1000), "int8"), int8 (127))
%!assert (cast (logical (true), "int8"), int8 (1))
%!assert (cast (logical (false), "int8"), int8 (0))
%!assert (cast (char ("A"), "int8"), int8 (65))

## Test int16 cast.  values will be limited to range -32,768 to 32,767
## more to come ...
</code>
Reply | Threaded
Open this post in threaded view
|

Re: missing tests

Carnë Draug
On 16 January 2014 03:31, mike sander <[hidden email]> wrote:

> i chose a function from http://wiki.octave.org/FilesMissingTests:
> miscellaneous/cast.m
>
> the following is what i have so far.   Looking for some feedback before i
> continue.  Do the tests look sensible?  Is there a class of testing related
> to cast to int8 (& other types) that i am missing?  I have tried to follow
> formatting/style from other tests.
>
> Thanks in advance for any comments/suggestions.
>
> [...]

The tests look good to me, and quite extensive. I would add some to
matrices as well, not only scalars. Example:

%!test
%! a = b = randi ([-1000 1000], 10, 15, 14, 78);
%! b(b>255) = 255;
%! b(b<0) = 0;
%! assert (cast (a, "uint8"), uint8 (b));

Similarly, you could test that scalars works fine with one example,
and then all the other possibilities (complex numbers, above and below
the range, etc) in a matrix with a single test.

Carnë
Reply | Threaded
Open this post in threaded view
|

Re: missing tests

John W. Eaton
Administrator
In reply to this post by msander
On 01/15/2014 10:31 PM, mike sander wrote:

> i chose a function from http://wiki.octave.org/FilesMissingTests:
> miscellaneous/cast.m
>
> the following is what i have so far.   Looking for some feedback before
> i continue.  Do the tests look sensible?  Is there a class of testing
> related to cast to int8 (& other types) that i am missing?  I have tried
> to follow formatting/style from other tests.
>
> Thanks in advance for any comments/suggestions.
>
>
> <code>
> %% Test input validation
> %!error cast (1)
> %!error <cast: expecting TYPE name as second argument> cast (1,1)
> %!error <cast: type name 'int' is not a built-in type> cast (1,"int")
>
> ## Test int8 cast.  input values will be limited to int8 range -128 to
> 127 after cast.  input values within range unchanged.
> %!assert (cast (int8 (-128), "int8"), int8 (-128))
> %!assert (cast (int8 (0), "int8"), int8 (0))
> %!assert (cast (int8 (127), "int8"), int8 (127))
> %!assert (cast (uint8 (0), "int8"), int8 (0))
> %!assert (cast (uint8 (255), "int8"), int8 (127))
> %!assert (cast (int16 (-1000), "int8"), int8 (-128))
> %!assert (cast (int16 (0), "int8"), int8 (0))
> %!assert (cast (int16 (1000), "int8"), int8 (127))
> %!assert (cast (uint16 (0), "int8"), int8 (0))
> %!assert (cast (uint16 (1000), "int8"), int8 (127))
> %!assert (cast (int32 (-1000), "int8"), int8 (-128))
> %!assert (cast (int32 (0), "int8"), int8 (0))
> %!assert (cast (int32 (1000), "int8"), int8 (127))
> %!assert (cast (uint32 (0), "int8"), int8 (0))
> %!assert (cast (uint32 (1000), "int8"), int8 (127))
> %!assert (cast (int64 (-1000), "int8"), int8 (-128))
> %!assert (cast (int64 (0), "int8"), int8 (0))
> %!assert (cast (int64 (1000), "int8"), int8 (127))
> %!assert (cast (uint64 (0), "int8"), int8 (0))
> %!assert (cast (uint64 (1000), "int8"), int8 (127))
> %!assert (cast (double (-1000), "int8"), int8 (-128))
> %!assert (cast (double (0), "int8"), int8 (0))
> %!assert (cast (double (1000), "int8"), int8 (127))
> %!assert (cast (single (-1000), "int8"), int8 (-128))
> %!assert (cast (single (0), "int8"), int8 (0))
> %!assert (cast (single (1000), "int8"), int8 (127))
> %!assert (cast (logical (true), "int8"), int8 (1))
> %!assert (cast (logical (false), "int8"), int8 (0))
> %!assert (cast (char ("A"), "int8"), int8 (65))
>
> ## Test int16 cast.  values will be limited to range -32,768 to 32,767
> ## more to come ...
> </code>

For repetitive tests like this, it makes sense to me that they would be
generated instead of written by hand.

jwe

Reply | Threaded
Open this post in threaded view
|

Re: missing tests

Markus Appel
In reply to this post by Carnë Draug
On 01/16/2014 12:46 PM, Carnë Draug wrote:

>
> The tests look good to me, and quite extensive. I would add some to
> matrices as well, not only scalars. Example:
>
> %!test
> %! a = b = randi ([-1000 1000], 10, 15, 14, 78);
> %! b(b>255) = 255;
> %! b(b<0) = 0;
> %! assert (cast (a, "uint8"), uint8 (b));
>
> Similarly, you could test that scalars works fine with one example,
> and then all the other possibilities (complex numbers, above and below
> the range, etc) in a matrix with a single test.
>
> Carnë
Do you think that it is (in general) a good idea to use anything
randomized in tests?
If a check fails and needs to be examined, I would expect that exactly
the same stuff gets tested every time I run it.

Markus
Reply | Threaded
Open this post in threaded view
|

Re: missing tests

msander
In reply to this post by Carnë Draug
On 14-01-16 06:46 AM, Carnë Draug wrote:
>
> The tests look good to me, and quite extensive. I would add some to
> matrices as well, not only scalars. Example:
>
> %!test
> %! a = b = randi ([-1000 1000], 10, 15, 14, 78);
> %! b(b>255) = 255;
> %! b(b<0) = 0;
> %! assert (cast (a, "uint8"), uint8 (b));
makes sense.  was there any particular reason for 4 dimensions with
those values?
> Similarly, you could test that scalars works fine with one example,
> and then all the other possibilities (complex numbers, above and below
> the range, etc) in a matrix with a single test.
any chance you could provide a simple example?

thanks
>
> Carnë
>

Reply | Threaded
Open this post in threaded view
|

Re: missing tests

msander
In reply to this post by John W. Eaton
On 14-01-16 10:54 AM, John W. Eaton wrote:
[...]
>
> For repetitive tests like this, it makes sense to me that they would
> be generated instead of written by hand.
>
> jwe
>
>

could you point me to an example of a generated test(s)?

thanks for your help.
Reply | Threaded
Open this post in threaded view
|

Re: missing tests

Carnë Draug
In reply to this post by Markus Appel
On 16 January 2014 16:17, Markus Appel <[hidden email]> wrote:

> On 01/16/2014 12:46 PM, Carnė Draug wrote:
>>
>> The tests look good to me, and quite extensive. I would add some to
>> matrices as well, not only scalars. Example:
>>
>> %!test
>> %! a = b = randi ([-1000 1000], 10, 15, 14, 78);
>> %! b(b>255) = 255;
>> %! b(b<0) = 0;
>> %! assert (cast (a, "uint8"), uint8 (b));
>>
>> Similarly, you could test that scalars works fine with one example,
>> and then all the other possibilities (complex numbers, above and below
>> the range, etc) in a matrix with a single test.
>>
>> Carnė
> Do you think that it is (in general) a good idea to use anything
> randomized in tests?
> If a check fails and needs to be examined, I would expect that exactly
> the same stuff gets tested every time I run it.

It is just a very convenient way to generate a matrix with multiple
different values. I guess one could set rand ("seed", X) before the
test to always get the same result. You probably right about it but
this has never been a problem.


On 17 January 2014 02:32, mike sander <[hidden email]> wrote:
> makes sense.  was there any particular reason for 4 dimensions with those
> values?

Just testing that will work correctly, no matter how many dimensions
has the input.

>> Similarly, you could test that scalars works fine with one example,
>> and then all the other possibilities (complex numbers, above and below
>> the range, etc) in a matrix with a single test.
>
> any chance you could provide a simple example?

The example I shown you would test values below and above the range of
the class. Just thrown an i into the matrix to test for it as well. In
some classes that will generate an error.

Carnë