chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Using epsilon in test egg


From: Alex Charlton
Subject: Re: [Chicken-users] Using epsilon in test egg
Date: Sat, 26 Jul 2014 22:02:52 -0400
User-agent: mu4e 0.9.9.5; emacs 24.4.50.1

Matt Gushee writes:

> I guess my explanation wasn't entirely clear, but that's pretty much
> what I was already doing. I showed the equality predicate I was using,
> which tests individual values in the list with = . I think my mistake
> was in assuming that (current-test-epsilon) would apply to = in the
> test environment. I'm guessing now that that is not the case.

Ah, yes, I hadn’t understood how you were testing. You’re right that = does not 
get redefined to use current-test-epsilon. Instead you would have to use your 
own equality predicate that incorporates it. test defines its approx-equal? as:

    (define (approx-equal? a b epsilon)
      (cond
       ((> (abs a) (abs b))
        (approx-equal? b a epsilon))
       ((zero? b)
        (< (abs a) epsilon))
       (else
        (< (abs (/ (- a b) b)) epsilon))))

Which you could then add to your predicate like so:

    (define (list= l1 l2)
      (and (= (length l1) (length l2))
           (let loop ((l1* l1) (l2* l2))
             (cond
               ((null? l1*) #t)
               ((approx-equal? (car l1*) (car l2*) (current-test-epsilon))
                (loop (cdr l1*) (cdr l2*)))
               (else #f)))))

-- 
Alex




reply via email to

[Prev in Thread] Current Thread [Next in Thread]