Rackcheck question: How to name a property?

I've just started using @bogdan's nice property-testing package rackcheck (includes shrinking!), and I can't figure out the syntax for adding a name to a property.

I'd like to give a name to my property ahead of adding more properties.

How do I do that?

Really liking the package:

  • I TDD-ed some tricky code, and wanted more checking to find uncovered cases, which it did
  • Suggestion: some examples in the Scribble documentation

Dan

 (define gen:segment
    (gen:let ([x (gen:integer-in -9999 9999)]
              [w (gen:integer-in 0 9999)])
      (segment x (+ x w))))

  (check-property
   (make-config #:tests 10000)
   (property ([s1 gen:segment]
              [s2 gen:segment])
     (check-equal? (segment-split s1 s2)
                   (reverse (segment-split s2 s1)))))
3 Likes

The property form takes an optional name in the first position, so you can change your code to:

  (check-property
   (make-config #:tests 10000)
   (property example-prop
     ([s1 gen:segment]
      [s2 gen:segment])
     (check-equal? (segment-split s1 s2)
                   (reverse (segment-split s2 s1)))))

Alternatively, you can use define-property, which binds the property to a variable and names it:

(define-property example-prop
  ([s1 gen:segment]
   [s2 gen:segment])
  (check-equal? (segment-split s1 s2)
                (reverse (segment-split s2 s1)))

(check-property (make-config #:tests 10000) example-prop)
1 Like

Thanks Bogdan

I also figured out how to use the #:name option to give a string description:

   (property #:name "argument symmetry"
             ([s1 gen:segment]
              [s2 gen:segment]) 
             (check-equal? (segment-split s1 s2)
                           (reverse (segment-split s2 s1))))

Thanks for making this!

One other question, with the shrink behaviour for gen:integer-in, would it be preferable to have it shrink towards 0 rather than the lower bound when 0 is within the range?

Dan

It's been a while since I've looked at the implementation, but I think the individual shrink trees for gen:integer-in already shrink toward zero. The error reporting code doesn't walk all the trees to avoid spending a lot of time shrinking, so it might sometimes choose a path that doesn't have 0 in it. I'll see about improving the ordering to make a hit on 0 more likely.

1 Like

Here's a minimal example:

  (define (F n) #f)

  (check-property
   (property ([n (gen:integer-in -9999 9999)])
             (check-equal? (F n) #t)))



--------------------
FAILURE
name:       unnamed
seed:       1389238784
actual:     #f
expected:   #t

Failed after 1 tests:

  n = -6979

Shrunk:

  n = -9999

--------------------
1 Like

I've pushed a fix. It should show up on the package server in a few hours.

2 Likes

Nice - works for me!

Thanks for the enhancement and happy new year.

1 Like