ifigueroap / racket-quickcheck

Quickcheck Clone implemented in Racket
Other
32 stars 16 forks source link

Examples #1

Open greghendershott opened 10 years ago

greghendershott commented 10 years ago

First, thanks for putting this up. Looks neat!

On the Racket mailing list Michael Sperber had posted some examples. I pasted them below.

Do they still work with the current version of this package?

If so, then perhaps these could be copied into the README.md as a start on documentation, and/or into a new examples.rkt file?

(I'm sorry to submit this as an Issue instead of giving you a pull request for it. I don't have time right now to fork, test the examples, and submit a PR. I'm hoping you could do it quicker? But if you can't, I will try to loop back and do this later.)


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=3D? ch (integer->char (char->integer ch)))))

(define string->list/
  (property ((str arbitrary-string))
        (string=3D? 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 arb=
itrary-integer)))
        (write (list 'aaa a)) (newline)
        #t))

(define max-le/
  (property ((x arbitrary-integer)
         (y arbitrary-integer))
    (=3D=3D> (<=3D x y)
     (=3D (max x y) y))))

(define insert1/
  (property ((x arbitrary-integer)
         (xs (arbitrary-list arbitrary-integer)))
        (=3D=3D> (list-sorted? xs <)
         (trivial (null? xs) =

              (list-sorted? (insert < x xs) <)))))

(define insert2/
  (property ((x arbitrary-integer)
         (xs (arbitrary-list arbitrary-integer)))
        (=3D=3D> (list-sorted? xs <)
         (collect (length xs) =

              (list-sorted? (insert < x xs) <)))))

(define (insert <=3D x xs)
  (cond
   ((null? xs) (list x))
   ((<=3D x (car xs))
    (cons x xs))
   (else
    (cons (car xs) (insert <=3D 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))
        (=3D (+ (+ a b) c)
           (+ a (+ b c)))))
ifigueroap commented 10 years ago

Do they still work with the current version of this package?

If so, then perhaps these could be copied into the README.md as a start on documentation, and/or into a new examples.rkt file?

I'd prefer to write the examples and documentation using Scribble, but indeed having some examples in the README would be useful. I think the examples should still work, because I haven't changed (much) the code. Anyways I will check and update accordingly.

(I'm sorry to submit this as an Issue instead of giving you a pull request for it. I don't have time right now to fork, test the examples, and submit a PR. I'm hoping you could do it quicker? But if you can't, I will try to loop back and do this later.)

No problem, thanks for your interest!