[plt-scheme] Check for function equality?

From: Carl Eastlund (carl.eastlund at gmail.com)
Date: Thu Feb 19 17:37:25 EST 2009

On Thu, Feb 19, 2009 at 5:24 PM, Matthias Felleisen
<matthias at ccs.neu.edu> wrote:
>
>
> So your conjecture is
>
>   forall (x natural-number?) (equal? (g-fives-closed-test x) (g-fives-closed
> x))
>
> Look for the QuickCheck package on planet, require it, and translate the
> above into a formal conjecture for QuickCheck.

Minor correction: you want FastTest (look for fasttest.plt).
QuickCheck is the Haskell library from which FastTest derives.

> Then try another conjecture for which you know it is false. See what happens
> there.
>
> Otherwise, do look at Matthew's reply
>
> On Feb 19, 2009, at 4:43 PM, dave yrueta wrote:
>
>> Hi All --
>>
>> Is there a Scheme function similar to "check-expect" that tests for
>> equality between functions?
>>
>> Example:
>>
>> ;23.3.2
>> ;g-fives-closed : N -> number
>> ;non-recursive version of g-fives
>> ;(check-expect (g-fives-closed 3) 375)
>> (define (g-fives-closed n)
>>  (* 3 (expt 5 n)))
>>
>> ;23.3.4
>> ;geometric-series : number number -> (number -> number)
>> ;consumes two numbers start and s, produces a function representing
>> the geometric series whose starting point is start and whose factor is
>> s
>> (define (geometric-series start s)
>>  (local ((define (local-g-series n)
>>            (* start (expt s n))))
>>    local-g-series))
>>
>> (define g-fives-closed-test (geometric-series 3 5))
>>
>> ;test 1 = test passes
>> (check-expect (g-fives-closed-test 3) (g-fives-closed 3))
>>
>> ;test 2 = test fails
>> (check-expect g-fives-closed-test g-fives-closed)
>>
>> As far as I can tell, "g-fives-closed-test" and "g-fives-closed"
>> differ in name only. I ran the same test with eq? and equal? and
>> received the same results.  Any way to test for this kind of equality?
>>
>> Thanks,
>> Dave Yrueta


Posted on the users mailing list.