[BULK] [plt-scheme] An order insensitive check-expect

From: Stephen Bloch (sbloch at adelphi.edu)
Date: Fri Feb 19 12:19:42 EST 2010

On Feb 19, 2010, at 11:50 AM, wooks wrote:

> If your expected result is a list where order is irrelevant is it
> possible to have check-expect not fail solely on account of the
> ordering of the result.?

That would certainly be useful, but it opens a Pandora's box of other  
"things to ignore": for example, suppose it were a list of lists, and  
I wanted to ignore order at both levels of nesting, or only the  
higher level, or only the lower level....

It would be nice to say

(define (check-same-set actual desired)
    (if (set=? actual desired)
        (check-expect actual actual) ; does nothing but records a  
passed test case
        (check-expect actual desired) ; records a failed test case as  

Unfortunately, BSL doesn't allow check-expect to appear other than at  
the top level (and it's not clear what it would mean if it could).

I've been wrestling with a similar problem in class this week.  My  
students are writing a lot of functions that return images.  In the  
current version, check-expect on images compares their pinholes too  
-- even though I'm trying very hard not to mention pinholes anywhere  
in the course.  In the short run, I've told the students that if they  
have a test

(check-expect (my-func arg arg) (my-answer blah blah))

that fails, but they can't see any visible difference between the  
answers, they should rewrite the test as

(check-expect (scenify (my-func arg arg)) (scenify (my-answer blah  

where "scenify" is a function provided by my teachpack that moves the  
pinhole of an image to (0,0).

This is obviously not a good long-term solution.

One way to solve both wooks's problem and mine would be to define a  
"check-same" taking in a comparison operator as its third parameter:

; check-same : X X (X X -> boolean) -> records a passed or failed test

(check-same this-set that-set set=?)

(check-same this-pic that-pic same-image-ignoring-pinhole?)

Stephen Bloch
sbloch at adelphi.edu

Posted on the users mailing list.