test-generative

  1. test-generative
    1. Requirements
    2. Repository
    3. Authors
    4. Introduction
    5. Examples
    6. API
    7. See also
    8. License

Requirements

test

Repository

https://bitbucket.org/certainty/test-generative/overview

Authors

David Krentzlin

Introduction

This egg integrates quickcheck-like testing on top of our very excellent test egg.

It allows you to throw a bunch of random inputs at your pure code and use the well known test macros to verify its behavior. This way you don't have to learn a new testing API but still get the benefits of random testing for your pure code.

This library is not meant to replace traditional manual unit tests but shall serve as an additional way to test your code.

Examples

(use test test-generative)

(test-generative ((the-number (lambda () (random 100))))
   (test-assert "it's numeric"  (number? the-number))
   (test-assert "it's positive" (positive? the-number))
   (test-assert "it's smaller than 50" (< the-number 50)))

Which outputs something like:

it's numeric ......................................................... [ PASS]
it's positive ........................................................ [ PASS]
it's smaller than 50 ................................................. [ FAIL]
    assertion failed
    (< the-number 50)
    iteration: 4
    seeds: ((the-number 68))

As you can see, the last assertion failed after the 4th iteration with the value 68 which is obviously not smaller than 50.

API

[parameter] current-test-generative-iterations

The number of iterations each test shall use. This means that this amout of random inputs will be chosen to exercise your test code. This also means that your test code will be run at least that amount of times. That's why you probably want to avoid side-effecting code with these kinds of tests. The current default is '100.

[syntax] (test-generative ((binding gen) ...) body ...)

This allows you to declare a set of generators specified by gen and refer to them by names that are specified as bindings in your test code. It will exercise the code at most current-test-generative-iterations + 1 amount of times with your random data and stop as soon as one of your tests fails. If a test has failed it shows the iteration in which it failed and the seed-values that have been used in that iteration.

What is a generator?: A generator is just a thunk that is expected to return the data upon invokation.

See also

If you want to use predefined generators for a lot of common types, have a look at data-generators

License

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.
A full copy of the GPL license can be found at
<http://www.gnu.org/licenses/>.