On Sun, Jul 27, 2014 at 11:02 AM, Alex Charlton <alex.n.charl...@gmail.com> wrote:
> > 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))))) > Easier: (define list= (let ((approx=? (current-test-comparator))) (lambda (ls1 ls2) (and (= (length ls1) (length ls2)) (every approx=? ls1 ls2))))) then (test-assert (list= '(0.655 0.843 0.200 1.0) (parse-color "167,215,51" #f))) or (define-syntax test-rgb (syntax-rules () ((test-rgb expected expr) (test-rgb #f expected expr)) ((test-rgb name expected expr) (parameterize ((current-test-comparator list=)) (test name expected expr))))) (test-rgb '(0.655 0.843 0.200 1.0) (parse-color "167,215,51" #f)) -- Alex
_______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users