[racket] QuickCheck-like testing library?
Thanks for the examples!!
I was able to construct arbitrary lists, which is what I needed.
Some feedback you might find useful:
I wanted to create a list with fixed length and arbitrary integers, and I
think it can't be done with the public API.
My idea was to use (choose-list arbitrary-integer 100), but
arbitrary-integer is not a generator. My solution was to export
arbitrary-generator and create the list using
(choose-list (arbitrary-generator arbitrary-integer) 100).
Is there a recommended way for user-defined generators?
I have a language grammar defined with PLAI's define-type, and was
wondering how to create a generator for random programs (even if they are
ill-typed).
Nevertheless I think your quickcheck library is cool, and would love to see
it as part of the Racket distribution. (so much that I offer to help
writing docs :)
Thanks
2012/8/17 Michael Sperber <sperber at deinprogramm.de>
>
> Ismael Figueroa Palet <ifigueroap at gmail.com> writes:
>
> > I copied the quickcheck folder to my project, but I don't know how to use
> > it :-(
> > do you have any examples of how to use it? do I need to copy other
> > collects, or do I have to use the full deinprogramm language?
>
> No, you don't. It can be used as a library.
>
> Here's a few examples I use for testing (which can be run using
> `(quickcheck <property>)'):
>
> (define rev-app/
> (property ((xs (arbitrary-list arbitrary-integer))
> (ys (arbitrary-list arbitrary-integer)))
> (equal? (reverse (append xs ys)) (append (reverse ys) (reverse
> xs)))))
>
> (define broken-rev-app/
> (property ((xs (arbitrary-list arbitrary-integer))
> (ys (arbitrary-list arbitrary-integer)))
> (equal? (reverse (append ys xs)) (append (reverse ys) (reverse
> xs)))))
>
> (define char->integer/
> (property ((ch arbitrary-char))
> (char=? ch (integer->char (char->integer ch)))))
>
> (define string->list/
> (property ((str arbitrary-string))
> (string=? str (list->string (string->list str)))))
>
> (define vector->list/
> (property ((vec (arbitrary-vector arbitrary-integer)))
> (equal? vec (list->vector (vector->list vec)))))
>
> (define map-append/
> (property ((proc (arbitrary-procedure arbitrary-integer arbitrary-char))
> (xs (arbitrary-list arbitrary-char))
> (ys (arbitrary-list arbitrary-char)))
> (equal? (map proc (append xs ys))
> (append (map proc xs) (map proc ys)))))
>
> (define ttt/
> (property ((a (arbitrary-record cons (list car cdr) arbitrary-integer
> arbitrary-integer)))
> (write (list 'aaa a)) (newline)
> #t))
>
> (define max-le/
> (property ((x arbitrary-integer)
> (y arbitrary-integer))
> (==> (<= x y)
> (= (max x y) y))))
>
> (define insert1/
> (property ((x arbitrary-integer)
> (xs (arbitrary-list arbitrary-integer)))
> (==> (list-sorted? xs <)
> (trivial (null? xs)
> (list-sorted? (insert < x xs) <)))))
>
> (define insert2/
> (property ((x arbitrary-integer)
> (xs (arbitrary-list arbitrary-integer)))
> (==> (list-sorted? xs <)
> (collect (length xs)
> (list-sorted? (insert < x xs) <)))))
>
> (define (insert <= x xs)
> (cond
> ((null? xs) (list x))
> ((<= x (car xs))
> (cons x xs))
> (else
> (cons (car xs) (insert <= x (cdr xs))))))
>
> ; This only tests whether the coarbitrary of arbitrary-real works in
> ; acceptable time.
> (define xxx/
> (property ((x arbitrary-real)
> (p (arbitrary-procedure arbitrary-boolean arbitrary-real)))
> (or (p x)
> (not (p x)))))
>
> (define non-assoc/
> (property ((a arbitrary-real)
> (b arbitrary-real)
> (c arbitrary-real))
> (= (+ (+ a b) c)
> (+ a (+ b c)))))
>
> --
> Cheers =8-} Mike
> Friede, Völkerverständigung und überhaupt blabla
>
--
Ismael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120817/1d075ef9/attachment.html>