[plt-scheme] Scheme-Check: Randomized Unit Testing for PLT Scheme
Hello folks.
I am sending this message to announce the release of a library I put
together that may be useful to some of you. Scheme-Check is basically a
PLT Scheme port of the Haskell QuickCheck module [1], by Koen Classen
and John Hughes.
Scheme-Check, like QuickCheck, allows specification-based testing of
programs and functions. Instead of defining individual test cases to
massage the functions, the programmer defines properties that must be
satisfied by the code, and Scheme-Check generates a large amount of test
data, hopefully performing a more thorough verification of the code.
QuickCheck has been found to work extremely well, and my experiences
with Scheme-Check are similar.
Scheme-Check is available for download at
http://www.inf.ufrgs.br/~carlossch/scheme-check/
Some info about the design/implementation:
I have tried to stay very close to the original library in this first
release. I had no idea if the lack of a type and class system would help
me or hinder me, and so I decided to walk the traveled roads first.
Since we do not have a class system like Haskell's to help with the
definition of the random data generators, Scheme-Check reimplements a
part of the type-based dispatch system to achieve the same effect. One
disadvantage of this approach is that Scheme-Check must be given the
types of the parameters that are expected by the property.
Scheme-Check comes with generators for the following types: Boolean,
Integer, Char, Real, Rational, Complex, String, Symbol, lists of other
types, functions of other types of arbitrary arity, and a generator that
chooses randomly between values of arbitrary types ("choice").
Scheme-Check uses a monad exactly like QuickCheck's to generate the
random data. In Haskell, complex monads find easy expression because of
the "'do' notation". Scheme-Check also provides syntax extensions that
reproduce the Haskell syntactic sugar.
Scheme-Check, like QuickCheck, can generate random functions.
QuickCheck was able to do this because the default Haskell random number
generator is purely functional, and the technique to generate the random
function depends critically on being able to store the state of the
generator. This functionaly could perhaps be implemented using the
current-pseudo-random-number-generator function and friends but, on the
other hand, the Haskell library has another major advantage: it provides
the ability to split a random generator into two independent ones. This
is useful to store a specific RNG to be used by a random function. So,
Scheme-Check also includes a port of the Haskell RNG library.
Current limitations:
- QuickCheck did not have to deal with impure functions, as Haskell is
purely functional. Scheme, on the other side, is not, and so we need a
way to test impure functions. There is currently no "official" way to do
this, but a possible workaround is to set the global variables on which
the functions depend inside the property, and then testing the property
itself. (Maybe I should do nothing and leave a warning to the
set!-addicted folks :)
- The random data generation DSL has a distinctly Haskellish feel
(obviously). This can be a turn-off to some users. However, I am not
quite sure how to do better.
I tested Scheme-Check with PLT Scheme 204 and 205. Don't know about
earlier versions, but I see no reason not to work.
Suggestions, comments, critiques and contributions are all largely
welcome.
Thank you,
Carlos Eduardo Scheidegger
[1] QuickCheck: Automatic Specification-based Testing.
http://www.math.chalmers.se/~rjmh/QuickCheck/
--
I just think that the (...) flight from and hatred of technology is
self-defeating. The Buddha, the Godhead, resides quite as comfortably
in the circuits of a digital computer or the gears of a cycle
transmission as he does at the top of a mountain or in the petals of a
flower.
- Robert M. Pirsig, Zen and the Art of Motorcycle Maintenance
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.racket-lang.org/users/archive/attachments/20030817/5d8a2195/attachment.sig>