|
From: | Alex Shinn |
Subject: | Re: [Chicken-users] Using epsilon in test egg |
Date: | Sun, 27 Jul 2014 13:34:40 +0900 |
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:
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.
(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:
((approx-equal? (car l1*) (car l2*) (current-test-epsilon))
(define (list= l1 l2)
(and (= (length l1) (length l2))
(let loop ((l1* l1) (l2* l2))
(cond
((null? l1*) #t)
(loop (cdr l1*) (cdr l2*)))
(else #f)))))
[Prev in Thread] | Current Thread | [Next in Thread] |