[plt-scheme] parameterized test-suites with units?

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Tue May 11 13:07:51 EDT 2010

define-unit-binding just makes the binding available inside the scope
in the same way define-unit does. You still need to invoke it as
before:

(define-values/invoke-unit/infer
 (export foo^)
 (link [email protected] [email protected]))

Jay

On Tue, May 11, 2010 at 11:06 AM, Todd O'Bryan <toddobryan at gmail.com> wrote:
> I already thanked Jay, but his help was not sufficient for my ignorance.
>
> Here's my latest attempt:
>
> #lang scheme
> (require schemeunit)
>
> (define-signature blah^
>  ((contracted
>    [get-value (-> any/c)])))
>
> (define-signature foo^
>  ((contracted
>    [to-string (-> string?)])))
>
> (define-unit [email protected]
>  (import)
>  (export blah^)
>
>  (define (get-value)
>    3))
>
> (define-unit [email protected]
>  (import)
>  (export blah^)
>
>  (define (get-value)
>    'x))
>
> (define-unit [email protected]
>  (import blah^)
>  (export foo^)
>
>  (define (to-string)
>    (format "~a" (get-value))))
>
> (define-unit [email protected]
>  (import blah^)
>  (export foo^)
>
>  (define (to-string)
>    (format "~s" (get-value))))
>
> (define (make-blah-test-suite [email protected] [email protected] expected)
>  (define-unit-binding [email protected]
>    [email protected]
>    (import (tag [email protected] blah^))
>    (export (tag [email protected] foo^)))
>
>  (check-equal? (to-string) expected))
>
> The problem is that to-string isn't recognized, so I need to invoke
> the unit and have the function inside it be available.
>
> I think I'm close...
>
> Todd
>
> On Tue, May 11, 2010 at 9:16 AM, Jay McCarthy <jay.mccarthy at gmail.com> wrote:
>> You want "define-unit-binding". That takes a unit expr, like [email protected],
>> and gives it a static unit binding inside a new scope.
>>
>> Jay
>>
>> On Tue, May 11, 2010 at 7:13 AM, Todd O'Bryan <toddobryan at gmail.com> wrote:
>>> The example below is illustrative:
>>>
>>> Basically, I have two signatures with units that satisfy them. To test
>>> the units, I link them and use standard Scheme Unit tests.
>>>
>>> #lang scheme
>>> (require schemeunit)
>>>
>>> (define-signature blah^
>>>  ((contracted
>>>    [get-value (-> any/c)])))
>>>
>>> (define-signature foo^
>>>  ((contracted
>>>    [to-string (-> string?)])))
>>>
>>> (define-unit [email protected]
>>>  (import)
>>>  (export blah^)
>>>
>>>  (define (get-value)
>>>    3))
>>>
>>> (define-unit [email protected]
>>>  (import blah^)
>>>  (export foo^)
>>>
>>>  (define (to-string)
>>>    (format "~a" (get-value))))
>>>
>>> (define-values/invoke-unit/infer
>>>  (export foo^)
>>>  (link [email protected] [email protected]))
>>>
>>> (check-equal? (as-string) "3")
>>>
>>> Unfortunately, I have multiple implementations of the same signature
>>> and want to test all of them.
>>>
>>> (define-unit [email protected]
>>>  (import)
>>>  (export blah^)
>>>
>>>  (define (get-value)
>>>    'x))
>>>
>>> What I'd like to do is something like
>>>
>>> (define (make-foo-test-suite [email protected] expected-value)
>>>   ...)
>>>
>>> so I could do
>>>
>>> (define blah1 at -test (make-foo-test-suite [email protected] "3")
>>> (define blah2 at -test (make-foo-test-suite [email protected] "x")
>>>
>>> Unfortunately, I can't replace the ... in make-foo-test-suite with
>>>
>>> (define-values/invoke-unit/infer
>>>  (export foo^)
>>>  (link [email protected] [email protected]))
>>>
>>> because the (link ...) part expects [email protected] not to be a formal
>>> parameter. Clearly I want to use something other than
>>> (define-values/invoke-unit/infer ...). Unfortunately, I can't figure
>>> out what it is that I want to use. :-)
>>>
>>> Any help?
>>>
>>> Thanks,
>>> Todd
>>> _________________________________________________
>>>  For list-related administrative tasks:
>>>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>>
>>
>>
>>
>> --
>> Jay McCarthy <jay at cs.byu.edu>
>> Assistant Professor / Brigham Young University
>> http://teammccarthy.org/jay
>>
>> "The glory of God is Intelligence" - D&C 93
>>
>



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://teammccarthy.org/jay

"The glory of God is Intelligence" - D&C 93


Posted on the users mailing list.