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

2014-07-30 Thread Peter Bex
On Mon, Jul 28, 2014 at 09:46:57PM +0900, Alex Shinn wrote:
 Regardless, I'll add a utility to make defining tests with your
 own comparator easier, and explicitly export test-approx-equal?
 so you don't have to capture the initial test comparator.

While you're looking at that, could you also take a look at this ticket?
https://bugs.call-cc.org/ticket/935

Thanks!

Cheers,
Peter
-- 
http://www.more-magic.net

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


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

2014-07-30 Thread John Cowan
Peter Bex scripsit:

 While you're looking at that, could you also take a look at this ticket?
 https://bugs.call-cc.org/ticket/935

In addition, the page on comparing floats that you pointed to now has a
replacement: 
http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/.

-- 
John Cowan  http://www.ccil.org/~cowanco...@ccil.org
After fixing the Y2K bug in an application:
WELCOME TO censored
DATE: MONDAK, JANUARK 1, 1900

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


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

2014-07-30 Thread Alex Shinn
On Wed, Jul 30, 2014 at 9:33 PM, John Cowan co...@mercury.ccil.org wrote:

 Peter Bex scripsit:

  While you're looking at that, could you also take a look at this ticket?
  https://bugs.call-cc.org/ticket/935


That was from 22 months ago... I don't remember
exactly when it was fixed but it works now.  Closed
the bug.

In addition, the page on comparing floats that you pointed to now has a
 replacement: 
 http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
 .


Heh, I was actually reading that page, linked from
the previous page, but it gets put inside a frame so
copying the location failed...

-- 
Alex
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


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

2014-07-30 Thread Peter Bex
On Wed, Jul 30, 2014 at 10:00:00PM +0900, Alex Shinn wrote:
 On Wed, Jul 30, 2014 at 9:33 PM, John Cowan co...@mercury.ccil.org wrote:
 
  Peter Bex scripsit:
 
   While you're looking at that, could you also take a look at this ticket?
   https://bugs.call-cc.org/ticket/935
 
 
 That was from 22 months ago...

Yeah, I just happened to stumble across it while performing
maintenance duties on the bugtracker, and saw this thread.

 I don't remember exactly when it was fixed but it works now.
 Closed the bug.

Thanks!  A maintained bugtracker is a useful bugtracker :)

Cheers,
Peter
-- 
http://www.more-magic.net

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


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

2014-07-30 Thread Alaric Snell-Pym
On 29/07/14 04:58, Alex Shinn wrote:
 On Mon, Jul 28, 2014 at 10:09 PM, John Cowan co...@mercury.ccil.org
 mailto:co...@mercury.ccil.org wrote:

 Alex Shinn scripsit:

  If people think it's useful I'd consider walking pairs and vectors.

 They are the most important cases, because the expected value is
 expressed as a literal value, and that can only be a list or vector.


 Actually, the expected value can be anything.  Literals
 may be the more common case though.

As an interesting case in point, I have written a bunch of tests for
procedures that have side-effects (where all I'm testing is that they
don't raise any conditions or whatever) of the form:

(test Do foo (void) (do-foo! ...))

...which works, because I make sure I return (void) rather than some
arbitrary expression from my side-effecting procedures!

I've also thrown together a few macros for a common case - I have a
constructor that makes an (opaque) object, and I want to test that the
construction doesn't raise conditions, while keeping the value for later
use. I do it with:

(define-syntax test-define
  (syntax-rules ()
((_ var expr)
 (test-define (-string '(define var expr)) var expr))
((_ name var expr)
 (begin
   (define var (void))
   (test-no-errors name (set! var expr))

(define-syntax test-define-values
  (syntax-rules ()
((_ (var ...) expr)
 (test-define-values (-string '(define-values (var ...) expr)) (var
...) expr))
((_ name (var ...) expr)
 (begin
   (define var (void)) ...
   (test-no-errors name (set!-values (var ...) expr))

Then I can do the likes of:

(test-define Create key-stream writer ksw (make-key-stream-writer* a
'test-ks))
(test-define-values Close key-stream writer (ks-hash ks-reused?)
((key-stream-writer-finish! ksw)))

ABS

--
Alaric Snell-Pym
http://www.snell-pym.org.uk/alaric/

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


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

2014-07-28 Thread John Cowan
Alex Shinn scripsit:

 The solution is definitely not to write your own comparison function,
 and trust that the test egg is doing the right thing.

It isn't, though, not quite.  What it needs to do is not a dichotomy of
if inexact, use epsilon, otherwise use `equal?` but rather to have
a version of `equal?` that uses epsilon when it comes to a float.
That way comparisons against list or vector structure that contains
floats (as in the OP's case) will work correctly.

-- 
John Cowan  http://www.ccil.org/~cowanco...@ccil.org
What has four pairs of pants, lives in Philadelphia,
and it never rains but it pours?
--Rufus T. Firefly

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


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

2014-07-28 Thread Alex Shinn
On Mon, Jul 28, 2014 at 9:30 PM, John Cowan co...@mercury.ccil.org wrote:

 Alex Shinn scripsit:

  The solution is definitely not to write your own comparison function,
  and trust that the test egg is doing the right thing.

 It isn't, though, not quite.  What it needs to do is not a dichotomy of
 if inexact, use epsilon, otherwise use `equal?` but rather to have
 a version of `equal?` that uses epsilon when it comes to a float.
 That way comparisons against list or vector structure that contains
 floats (as in the OP's case) will work correctly.


I meant the right thing wrt comparing two inexacts, as
opposed to trying to come up with your own inexact=? logic.

It's easy to make it handle nested pairs and vectors correctly,
would require lolevel hackery to handle records, and in general
can't support ffi struct types.  So at some point you need to
provide your own structure comparison, and I chose to make
the rule simple:

  If you explicitly expect a single inexact value, assume
  the result should also be inexact and approximately equal.
  Otherwise use equal?.

If people think it's useful I'd consider walking pairs and vectors.

Regardless, I'll add a utility to make defining tests with your
own comparator easier, and explicitly export test-approx-equal?
so you don't have to capture the initial test comparator.

-- 
Alex
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


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

2014-07-28 Thread John Cowan
Alex Shinn scripsit:

 If people think it's useful I'd consider walking pairs and vectors.

They are the most important cases, because the expected value is
expressed as a literal value, and that can only be a list or vector.  If
you are using `test-assert`, you can specify your own function directly.

 Regardless, I'll add a utility to make defining tests with your own
 comparator easier, and explicitly export test-approx-equal? so you
 don't have to capture the initial test comparator.

+1

-- 
John Cowan  http://www.ccil.org/~cowanco...@ccil.org
La mayyitan ma qadirun yatabaqqa sarmadi
Fa idha yaji' al-shudhdhadh fa-l-maut qad yantahi.
--Abdullah al-Hazred, Al-`Azif

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


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

2014-07-28 Thread Alex Shinn
On Mon, Jul 28, 2014 at 10:09 PM, John Cowan co...@mercury.ccil.org wrote:

 Alex Shinn scripsit:

  If people think it's useful I'd consider walking pairs and vectors.

 They are the most important cases, because the expected value is
 expressed as a literal value, and that can only be a list or vector.


Actually, the expected value can be anything.  Literals
may be the more common case though.

-- 
Alex
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


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

2014-07-27 Thread Alex Shinn
On Sun, Jul 27, 2014 at 10:03 AM, Matt Gushee m...@gushee.net wrote:

 Hmm, just realized something. The test egg documentation also says:

   Percentage difference allowed ...

 So if the expected value is 0, then no variance is allowed? If that's
 true, then epsilon isn't what I want anyway. I need to allow an
 absolute amount of variance that is independent of the values being
 tested.


By the way, in general you do _not_ want absolute differences.
The test egg is doing the right thing for general comparisons.
Arguably it may be better to use ULPs (Units in the Last Place),
but they're harder to get at in portable Scheme and not clearly
better.  For more than you ever wanted to know about the subject
see:

http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm

The solution is definitely not to write your own comparison function,
and trust that the test egg is doing the right thing.

-- 
Alex


 Anyway, I'd appreciate help in understanding how this is supposed to work
 ...

 On Sat, Jul 26, 2014 at 6:42 PM, Matt Gushee m...@gushee.net wrote:
  Hi, folks--
 
  I am working on an application that does a lot of floating-point
  calculations, and I'm having trouble with the test suite. The program
  is based on the imlib2 egg, and it does some fairly simple image
  processing for web applications, so the numbers in question are RGBA
  color values. Internally I am handling all the numbers as floats in
  the range 0-1, because the blending and compositing formulas are much
  more straightforward that way compared to using integers 0-255.
 
  So I have a number of functions that produce lists of numbers like these:
 
'(0.323 0.788834 0.12 0.4)
'(0 0 0 1.0)
'(0.67 0.4 0.562 0.0)
 
  And given the above, a moderate degree of imprecision in the results
  is perfectly acceptable - I haven't yet confirmed this with actual
  images, but I'm thinking as much as 0.5% variance should work fine
  (basically, as long as the colors in the generated images look as
  expected to a casual observer, the result should be acceptable). So of
  course I want the test results to reflect this.
 
  I am using the following procedure to compare number lists:
 
(define (list= l1 l2)
(and (= (length l1) (length l2))
 (let loop ((l1* l1) (l2* l2))
   (cond
 ((null? l1*) #t)
 ((= (car l1*) (car l2*)) (loop (cdr l1*) (cdr l2*)))
 (else #f)
 
  And for the tests that use this predicate, I set
 
(current-test-epsilon 0.005)
 
  [or 0.002 or 0.001 - it doesn't seem to make any difference]
 
  But I'm finding that certain tests still fail unexpectedly, e.g.
 
   2.03.10: (parse-color 167,215,51 #f) = '(0.655 0.843 0.200 1.0)  [
 FAIL]
expected (0.655 0.843 0.2 1.0)
but got (0.654901960784314   0.843137254901961 0.2 1.0)
 
  But:
 
(/ 0.654901960784314 0.655) = 0.999850321808113
(/ 0.843137254901961 0.843) = 1.0001628172028
 
  So it would appear that the epsilon value does not apply to these tests.
 
  I can certainly define a custom equality predicate that will do what I
  need, but this is bugging me. I guess I don't really understand how
  epsilon is supposed to work. The test egg documentation says that
  applies to 'inexact comparisons', but I can't find a definition of
  'inexact comparison'. I have also read that '=' may be unreliable for
  inexact numbers, but I don't know what else to use. Perhaps 'fp=' from
  the Chicken library? Then I would have to ensure that all numbers are
  expressed as floats, whereas currently my code has a number of cases
  where 1 and 0 are expressed as integers.
 
  So ... do I understand the problem correctly? Any recommendations?
 
  Matt Gushee

 ___
 Chicken-users mailing list
 Chicken-users@nongnu.org
 https://lists.nongnu.org/mailman/listinfo/chicken-users

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


[Chicken-users] Using epsilon in test egg

2014-07-26 Thread Matt Gushee
Hi, folks--

I am working on an application that does a lot of floating-point
calculations, and I'm having trouble with the test suite. The program
is based on the imlib2 egg, and it does some fairly simple image
processing for web applications, so the numbers in question are RGBA
color values. Internally I am handling all the numbers as floats in
the range 0-1, because the blending and compositing formulas are much
more straightforward that way compared to using integers 0-255.

So I have a number of functions that produce lists of numbers like these:

  '(0.323 0.788834 0.12 0.4)
  '(0 0 0 1.0)
  '(0.67 0.4 0.562 0.0)

And given the above, a moderate degree of imprecision in the results
is perfectly acceptable - I haven't yet confirmed this with actual
images, but I'm thinking as much as 0.5% variance should work fine
(basically, as long as the colors in the generated images look as
expected to a casual observer, the result should be acceptable). So of
course I want the test results to reflect this.

I am using the following procedure to compare number lists:

  (define (list= l1 l2)
  (and (= (length l1) (length l2))
   (let loop ((l1* l1) (l2* l2))
 (cond
   ((null? l1*) #t)
   ((= (car l1*) (car l2*)) (loop (cdr l1*) (cdr l2*)))
   (else #f)

And for the tests that use this predicate, I set

  (current-test-epsilon 0.005)

[or 0.002 or 0.001 - it doesn't seem to make any difference]

But I'm finding that certain tests still fail unexpectedly, e.g.

 2.03.10: (parse-color 167,215,51 #f) = '(0.655 0.843 0.200 1.0)  [ FAIL]
  expected (0.655 0.843 0.2 1.0)
  but got (0.654901960784314   0.843137254901961 0.2 1.0)

But:

  (/ 0.654901960784314 0.655) = 0.999850321808113
  (/ 0.843137254901961 0.843) = 1.0001628172028

So it would appear that the epsilon value does not apply to these tests.

I can certainly define a custom equality predicate that will do what I
need, but this is bugging me. I guess I don't really understand how
epsilon is supposed to work. The test egg documentation says that
applies to 'inexact comparisons', but I can't find a definition of
'inexact comparison'. I have also read that '=' may be unreliable for
inexact numbers, but I don't know what else to use. Perhaps 'fp=' from
the Chicken library? Then I would have to ensure that all numbers are
expressed as floats, whereas currently my code has a number of cases
where 1 and 0 are expressed as integers.

So ... do I understand the problem correctly? Any recommendations?

Matt Gushee

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


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

2014-07-26 Thread Alaric Snell-Pym
On 27/07/14 01:42, Matt Gushee wrote:

 I can certainly define a custom equality predicate that will do what I
 need, but this is bugging me. I guess I don't really understand how
 epsilon is supposed to work. The test egg documentation says that
 applies to 'inexact comparisons', but I can't find a definition of
 'inexact comparison'. I have also read that '=' may be unreliable for
 inexact numbers, but I don't know what else to use. Perhaps 'fp=' from
 the Chicken library? Then I would have to ensure that all numbers are
 expressed as floats, whereas currently my code has a number of cases
 where 1 and 0 are expressed as integers.

As I understand it, the test egg epsilon won't change the behaviour of =
- it's used purely internally by the test egg when you say the likes of:

(test 1.0 (+ 0.5 0.5))

It's probably best to define your own equality predicate, I think!

ABS

-- 
Alaric Snell-Pym
http://www.snell-pym.org.uk/alaric/



signature.asc
Description: OpenPGP digital signature
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


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

2014-07-26 Thread Matt Gushee
Hmm, just realized something. The test egg documentation also says:

  Percentage difference allowed ...

So if the expected value is 0, then no variance is allowed? If that's
true, then epsilon isn't what I want anyway. I need to allow an
absolute amount of variance that is independent of the values being
tested.

Anyway, I'd appreciate help in understanding how this is supposed to work ...

On Sat, Jul 26, 2014 at 6:42 PM, Matt Gushee m...@gushee.net wrote:
 Hi, folks--

 I am working on an application that does a lot of floating-point
 calculations, and I'm having trouble with the test suite. The program
 is based on the imlib2 egg, and it does some fairly simple image
 processing for web applications, so the numbers in question are RGBA
 color values. Internally I am handling all the numbers as floats in
 the range 0-1, because the blending and compositing formulas are much
 more straightforward that way compared to using integers 0-255.

 So I have a number of functions that produce lists of numbers like these:

   '(0.323 0.788834 0.12 0.4)
   '(0 0 0 1.0)
   '(0.67 0.4 0.562 0.0)

 And given the above, a moderate degree of imprecision in the results
 is perfectly acceptable - I haven't yet confirmed this with actual
 images, but I'm thinking as much as 0.5% variance should work fine
 (basically, as long as the colors in the generated images look as
 expected to a casual observer, the result should be acceptable). So of
 course I want the test results to reflect this.

 I am using the following procedure to compare number lists:

   (define (list= l1 l2)
   (and (= (length l1) (length l2))
(let loop ((l1* l1) (l2* l2))
  (cond
((null? l1*) #t)
((= (car l1*) (car l2*)) (loop (cdr l1*) (cdr l2*)))
(else #f)

 And for the tests that use this predicate, I set

   (current-test-epsilon 0.005)

 [or 0.002 or 0.001 - it doesn't seem to make any difference]

 But I'm finding that certain tests still fail unexpectedly, e.g.

  2.03.10: (parse-color 167,215,51 #f) = '(0.655 0.843 0.200 1.0)  [ FAIL]
   expected (0.655 0.843 0.2 1.0)
   but got (0.654901960784314   0.843137254901961 0.2 1.0)

 But:

   (/ 0.654901960784314 0.655) = 0.999850321808113
   (/ 0.843137254901961 0.843) = 1.0001628172028

 So it would appear that the epsilon value does not apply to these tests.

 I can certainly define a custom equality predicate that will do what I
 need, but this is bugging me. I guess I don't really understand how
 epsilon is supposed to work. The test egg documentation says that
 applies to 'inexact comparisons', but I can't find a definition of
 'inexact comparison'. I have also read that '=' may be unreliable for
 inexact numbers, but I don't know what else to use. Perhaps 'fp=' from
 the Chicken library? Then I would have to ensure that all numbers are
 expressed as floats, whereas currently my code has a number of cases
 where 1 and 0 are expressed as integers.

 So ... do I understand the problem correctly? Any recommendations?

 Matt Gushee

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


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

2014-07-26 Thread Alex Charlton

Hi Matt,

The problem you’re having is because test only uses the approximate comparison 
(using current-test-epsilon) when the _expected_ value is inexact: 
http://api.call-cc.org/doc/scheme/inexact%3F

Since your expected value is a list (i.e. inexact? will result in #f given a 
list), test is testing using equal? which, as you noted, will likely fail for 
floating point values.

All you’ll need to do to properly test your lists is to break the test down so 
that you are testing the floats one at a time. You could also set 
current-test-comparator to a function that will work given your requirements. 
This is the default current-test-comparator:

(define (test-equal? expect res)
  (or (equal? expect res)
  (and (number? expect)
   (inexact? expect)
   (inexact? res)
   (approx-equal? expect res (current-test-epsilon)

You could change it to something like:

(define (rgb-test-equal? expect res)
  (or (equal? expect res)
 (and (rgb? expect)
(rgb-equal? expect res))
 (and (number? expect)
(inexact? expect)
(inexact? res)
(approx-equal? expect res (current-test-epsilon)

With appropriate definitions for rgb? and rgb-equal?


Matt Gushee writes:

 Hi, folks--


 I am working on an application that does a lot of floating-point
 calculations, and I'm having trouble with the test suite. The program
 is based on the imlib2 egg, and it does some fairly simple image
 processing for web applications, so the numbers in question are RGBA
 color values. Internally I am handling all the numbers as floats in
 the range 0-1, because the blending and compositing formulas are much
 more straightforward that way compared to using integers 0-255.

 So I have a number of functions that produce lists of numbers like these:

   '(0.323 0.788834 0.12 0.4)
   '(0 0 0 1.0)
   '(0.67 0.4 0.562 0.0)

 And given the above, a moderate degree of imprecision in the results
 is perfectly acceptable - I haven't yet confirmed this with actual
 images, but I'm thinking as much as 0.5% variance should work fine
 (basically, as long as the colors in the generated images look as
 expected to a casual observer, the result should be acceptable). So of
 course I want the test results to reflect this.

 I am using the following procedure to compare number lists:

   (define (list= l1 l2)
   (and (= (length l1) (length l2))
(let loop ((l1* l1) (l2* l2))
  (cond
((null? l1*) #t)
((= (car l1*) (car l2*)) (loop (cdr l1*) (cdr l2*)))
(else #f)

 And for the tests that use this predicate, I set

   (current-test-epsilon 0.005)

 [or 0.002 or 0.001 - it doesn't seem to make any difference]

 But I'm finding that certain tests still fail unexpectedly, e.g.

  2.03.10: (parse-color 167,215,51 #f) = '(0.655 0.843 0.200 1.0)  [ FAIL]
   expected (0.655 0.843 0.2 1.0)
   but got (0.654901960784314   0.843137254901961 0.2 1.0)

 But:

   (/ 0.654901960784314 0.655) = 0.999850321808113
   (/ 0.843137254901961 0.843) = 1.0001628172028

 So it would appear that the epsilon value does not apply to these tests.

 I can certainly define a custom equality predicate that will do what I
 need, but this is bugging me. I guess I don't really understand how
 epsilon is supposed to work. The test egg documentation says that
 applies to 'inexact comparisons', but I can't find a definition of
 'inexact comparison'. I have also read that '=' may be unreliable for
 inexact numbers, but I don't know what else to use. Perhaps 'fp=' from
 the Chicken library? Then I would have to ensure that all numbers are
 expressed as floats, whereas currently my code has a number of cases
 where 1 and 0 are expressed as integers.

 So ... do I understand the problem correctly? Any recommendations?

 Matt Gushee

 ___
 Chicken-users mailing list
 Chicken-users@nongnu.org
 https://lists.nongnu.org/mailman/listinfo/chicken-users


-- 
Alex


___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


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

2014-07-26 Thread Matt Gushee
On Sat, Jul 26, 2014 at 6:57 PM, Alaric Snell-Pym
ala...@snell-pym.org.uk wrote:

 It's probably best to define your own equality predicate, I think!

Yes, I think you're right. Thanks!

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


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

2014-07-26 Thread Matt Gushee
Hi, John--

On Sat, Jul 26, 2014 at 7:47 PM, John Cowan co...@mercury.ccil.org wrote:
 Matt Gushee scripsit:

 Other posters have addressed the main issues, but I'll just point out
 that inexact comparison means comparison for equality of inexact
 numbers.  Epsilon is applied only by the default predicate: it's
 assumed that if you write your own equality predicate, you know what
 you want.

I was coming to that conclusion myself, but it's good to have an
authoritative answer.

 = also works correctly for all floats.  It's computation itself that
 isn't always mathematically correct,

Indeed. I know that much, at least. Though I can still remember the
time (around 2001?) when I saw that a calculation that was supposed to
produce 1 actually produced 0.962734 or something like that, and I
went WTFFF?

Thanks.

--
Matt

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


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

2014-07-26 Thread Alex Charlton

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


___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


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

2014-07-26 Thread Alex Shinn
On Sun, Jul 27, 2014 at 10:03 AM, Matt Gushee m...@gushee.net wrote:

 Hmm, just realized something. The test egg documentation also says:

   Percentage difference allowed ...

 So if the expected value is 0, then no variance is allowed?


Naturally we handle this case correctly and check the
absolute difference in one value is zero.  I've added a
clarification to the docs.

-- 
Alex
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


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

2014-07-26 Thread Alex Shinn
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