[plt-scheme] An order insensitive check-expect

From: Anthony Cowley (acowley at seas.upenn.edu)
Date: Sun Feb 21 13:16:44 EST 2010

On Fri, Feb 19, 2010 at 11:53 AM, Robby Findler
<robby at eecs.northwestern.edu> wrote:
> You can sort both lists before using check-expect.
>
> Or you can use schemeunit and define your own check:
>
> #lang scheme
> (require schemeunit)
>
> (define-simple-check (check-same-elements l1 l2)
>  (and (list? l1)
>       (list? l2)
>       (andmap (λ (l1-ele) (member l1-ele l2)) l1)
>       (andmap (λ (l2-ele) (member l2-ele l1)) l2)))
>
> (check-same-elements (list 1 2 3)
>                     (list 2 3 1))
> (check-same-elements (list 1 2 4)
>                     (list 1 2 3))
>

An alternative:
(define-simple-check (check-multiset-equality l1 l2)
  (and (list? l1)
       (list? l2)
       (= (length l1) (length l2))
       (null? (foldl remove l2 l1))))

(check-multiset-equality (list 1 1 2 3)
                         (list 1 2 2 3))


Anthony


Posted on the users mailing list.