[racket] How to test a function which return multiple values?

From: Laurent (laurent.orseau at gmail.com)
Date: Sun Oct 6 06:08:36 EDT 2013

You can use `call-with-values' and wrap it in a helper:

#lang racket
(require rackunit)

(define (call-with-values->list p . args)
  (call-with-values (λ()(apply p args)) list))

(define (some-proc x y)
  (values y x))

(check-equal? (call-with-values->list some-proc 2 1)
              (list 1 2))


(Usually I abbreviate `call-with-values->list' to `cvl'.)
I wonder why there is not something similar in the main distribution though.

Laurent


On Sun, Oct 6, 2013 at 5:51 PM, Manfred Lotz <manfred.lotz at arcor.de> wrote:

> Hi there,
> Assume a function which returns values. I couldn't find anything in
> rackunit to test such a function out of the box.
>
> Simple example:
>
> (define (mval)
>   (values 1 2 3))
>
>
> Now I like to test it using rackunit. The only idea I have is:
>
>   (let-values ([(x y z) (mval)])
>     (check-equal? (list x y z) (list 1 2 3)))
>
> Works fine. However, I can imagine this could be done better and/or
> easier.
>
>
> --
> Manfred
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20131006/4dc1d90f/attachment.html>

Posted on the users mailing list.