[racket] How to test a function which return multiple values?
On Sun, 6 Oct 2013 18:08:36 +0800
Laurent <laurent.orseau at gmail.com> wrote:
> 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.
>
Thanks for your reply. Good to see that my solution wasn't totally
stupid. However, your way is far better.
--
Manfred
> 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
> >
>