octave-maintainers
[Top][All Lists]
Advanced

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

Re: missing tests for cast()


From: Rik
Subject: Re: missing tests for cast()
Date: Thu, 16 Jan 2014 09:54:34 -0800

On 01/15/2014 07:31 PM, address@hidden wrote:
> Message: 3
> Date: Wed, 15 Jan 2014 22:31:27 -0500
> From: mike sander <address@hidden>
> To: address@hidden
> Subject: missing tests
> Message-ID: <address@hidden>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> 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")
The name of the function and the colon are automatically inserted by the
error function so they don't really need to be checked.  I just use the
actual warning message itself so I think this could be written as:

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

The input validation tests are also of secondary importance when compared
to the functional tests.  I usually put the functional tests first and the
input validation is always the last set of tests in the file.  As you might
have seen in the m-files, there are always 2 blank lines after the last
line of actual code (usually the keyword "endfunction") and the start of
the %!tests.

> ## 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))
This strategy will work just fine, although you will end up with pages and
pages of tests.  You could explore using a for loop and 'eval' to compact
things, or you might just use a script to generate all the required
combinations and paste that in to cast.m.

Cheers,
Rik



reply via email to

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