[gambit-list] Proposed patch

Marc Feeley feeley at iro.umontreal.ca
Tue Dec 10 22:27:51 EST 2013


OK, I have now added (and pushed to the repo) a unit testing framework in the tests subdirectory.  It is mostly compatible with the unit testing framework of Racket.  You can execute it with:

   cd tests
   ./run-unit-tests.scm

The unit tests are in the unit-tests directory.  I took your trigtests.scm file and chopped it up into smaller unit tests in the unit-tests/03-number directory.  What I notice is that the functions are not tested to the same level of detail:

% wc tests/unit-tests/03-number/*
      26      96     606 tests/unit-tests/03-number/#.scm
      14      44     338 tests/unit-tests/03-number/acos.scm
      11      29     212 tests/unit-tests/03-number/acosh.scm
      18      54     415 tests/unit-tests/03-number/asin.scm
      18      54     432 tests/unit-tests/03-number/asinh.scm
      18      54     418 tests/unit-tests/03-number/atan.scm
      18      54     429 tests/unit-tests/03-number/atanh.scm
       5      10      67 tests/unit-tests/03-number/cos.scm
       5      10      68 tests/unit-tests/03-number/cosh.scm
      11      26     219 tests/unit-tests/03-number/log.scm
       9      20     143 tests/unit-tests/03-number/sin.scm
       9      20     145 tests/unit-tests/03-number/sinh.scm
      13      35     232 tests/unit-tests/03-number/sqrt.scm
       9      20     143 tests/unit-tests/03-number/tan.scm
       9      20     145 tests/unit-tests/03-number/tanh.scm
     193     546    4012 total

For example cos and cosh have a single test for the special value 0, whereas there are 8 tests for asin.  That is not very thorough testing.

Moreover, it is important to check that the primitive functions raise exceptions correctly.  To give you an idea I have added unit tests for fx+ and fl+.  Here's the unit test for fx+:

(check-eqv? (fx+ 11 33)   44)
(check-eqv? (fx+ 11 -11)   0)
(check-eqv? (fx+ 11 -33) -22)
(check-eqv? (fx+ -11 33)  22)

(check-eqv? (fx+) 0)
(check-eqv? (fx+ 11) 11)
(check-eqv? (fx+ 11 22) 33)
(check-eqv? (fx+ 11 22 33) 66)
(check-eqv? (fx+ 11 22 33 44) 110)

(check-exn type-exception? (lambda () (fx+ 1/2)))
(check-exn type-exception? (lambda () (fx+ 1/2 9)))
(check-exn type-exception? (lambda () (fx+ 9 1/2)))
(check-exn type-exception? (lambda () (fx+ 1/2 3 9)))
(check-exn type-exception? (lambda () (fx+ 3 1/2 9)))
(check-exn type-exception? (lambda () (fx+ 3 9 1/2)))

(check-exn fixnum-overflow-exception? (lambda () (fx+ ##max-fixnum 1)))
(check-exn fixnum-overflow-exception? (lambda () (fx+ ##min-fixnum -1)))

Do you think you could expand your unit tests to cover more cases?

Marc


On Dec 10, 2013, at 4:10 PM, Bradley Lucier <lucier at math.purdue.edu> wrote:

> On 12/10/2013 12:10 PM, Marc Feeley wrote:
>> 
>> On Dec 10, 2013, at 11:45 AM, Bradley Lucier <lucier at math.purdue.edu> wrote:
>> 
>>> Thanks for the comments.
>>> 
>>> On 12/10/2013 09:38 AM, Marc Feeley wrote:
>>> What is missing for this patch is a bunch of unit tests.  Each of the new inlined primitives should be tested for precision (after all, that is why they were added, so unit tests should verify this).
>>> Later.  I promise. :-)
>> Not good enough!  If I don't take a hard line on this one, things will slip.  But I can help you!
>> 
>> >From now on, patches for new functionality will have to come with appropriate unit tests.  Unit tests for existing features will have to be added too.
> 
> Oh great and powerful Oz, I bring you the broom of the Wicked Witch of the East ... No, no, that can't be right, let's see ...
> 
> I offer you 63 unit tests (including all branch cuts and special values) in supplication that you might accept my good patch.
> 
> Brad
> <trigtests.scm>




More information about the Gambit-list mailing list