Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Test-Deep CPAN distribution.

Report information
The Basics
Id: 28651
Status: resolved
Priority: 0/
Queue: Test-Deep

People
Owner: Nobody in particular
Requestors: anonymous [...] remailer.metacolo.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: possible to use num() with array_each/hash_each?
Date: Fri, 3 Aug 2007 17:52:13 +0000 (UTC)
To: bug-Test-Deep [...] rt.cpan.org
From: Anonymous Sender <anonymous [...] remailer.metacolo.com>
if i have a hash or array, is it possible to test with an expected data structure using num()? i've tried and it doesn't appear so.
Subject: Re: [rt.cpan.org #28651] possible to use num() with array_each/hash_each?
Date: Fri, 3 Aug 2007 23:11:48 +0100
To: bug-Test-Deep [...] rt.cpan.org
From: "Fergal Daly" <fergal [...] esatclear.ie>
On 03/08/07, Anonymous Sender via RT <bug-Test-Deep@rt.cpan.org> wrote: Show quoted text
> if i have a hash or array, is it possible to test with an expected > data structure using num()? i've tried and it doesn't appear so.
All of the different comparators should work with each other, so I don't really know what you mean. Could you give me an example of what you tried and what you expected to happen? F
From: colossus.forbin [...] gmail.com
On Fri Aug 03 18:12:00 2007, fergal@esatclear.ie wrote: Show quoted text
> On 03/08/07, Anonymous Sender via RT <bug-Test-Deep@rt.cpan.org> wrote:
> > if i have a hash or array, is it possible to test with an expected > > data structure using num()? i've tried and it doesn't appear so.
> > All of the different comparators should work with each other, so I > don't really know what you mean. Could you give me an example of what > you tried and what you expected to happen?
my $output = { a => .5283, b => .2213 }; the number of significant places may vary so i want to compare to: my $expected = { a => .5, b => .2 } the pod doesn't event mention hash_each, but looking at the test file hash_each.t it looks like it only operates on the hash values. i want to compare each key/val of $output with each key/num(val) of $expected.
Subject: Re: [rt.cpan.org #28651] possible to use num() with array_each/hash_each?
Date: Sun, 5 Aug 2007 10:47:11 +0100
To: bug-Test-Deep [...] rt.cpan.org
From: "Fergal Daly" <fergal [...] esatclear.ie>
On 05/08/07, forbin via RT <bug-Test-Deep@rt.cpan.org> wrote: Show quoted text
> > Queue: Test-Deep > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=28651 > > > On Fri Aug 03 18:12:00 2007, fergal@esatclear.ie wrote:
> > On 03/08/07, Anonymous Sender via RT <bug-Test-Deep@rt.cpan.org> wrote:
> > > if i have a hash or array, is it possible to test with an expected > > > data structure using num()? i've tried and it doesn't appear so.
> > > > All of the different comparators should work with each other, so I > > don't really know what you mean. Could you give me an example of what > > you tried and what you expected to happen?
> > my $output = { a => .5283, b => .2213 }; > > the number of significant places may vary so i want to compare to: > my $expected = { a => .5, b => .2 } > > the pod doesn't event mention hash_each, but looking at the test file > hash_each.t it looks like it only operates on the hash values. > > i want to compare each key/val of $output with each key/num(val) of > $expected.
Here are 2 examples fergal@lap ~> /usr/bin/perl -MTest::More=no_plan -MTest::Deep -e 'print cmp_deeply({ a => .5283, b => .2213 }, {a => num(.5, .02), b => num(.2, .3)})' not ok 1 # Failed test in -e at line 1. # Comparing $data->{"a"} as a number # got : 0.5283 # expect : 0.5 +/- 0.02 01..1 # Looks like you failed 1 test of 1. fergal@lap ~> /usr/bin/perl -MTest::More=no_plan -MTest::Deep -e 'print cmp_deeply({ a => .5283, b => .2213 }, {a => num(.5, .03), b => num(.2, .03)})' ok 1 11..1 is that what you're looking for? F
From: colossus.forbin [...] gmail.com
On Sun Aug 05 05:47:26 2007, fergal@esatclear.ie wrote: Show quoted text
> > my $output = { a => .5283, b => .2213 }; > > > > the number of significant places may vary so i want to compare to: > > my $expected = { a => .5, b => .2 } > > > > the pod doesn't event mention hash_each, but looking at the test file > > hash_each.t it looks like it only operates on the hash values. > > > > i want to compare each key/val of $output with each key/num(val) of > > $expected.
> > Here are 2 examples > > fergal@lap ~> /usr/bin/perl -MTest::More=no_plan -MTest::Deep -e > 'print cmp_deeply({ a => .5283, b => .2213 }, {a => num(.5, .02), b => > num(.2, .3)})' > not ok 1 > # Failed test in -e at line 1. > # Comparing $data->{"a"} as a number > # got : 0.5283 > # expect : 0.5 +/- 0.02 > 01..1 > # Looks like you failed 1 test of 1. > fergal@lap ~> /usr/bin/perl -MTest::More=no_plan -MTest::Deep -e > 'print cmp_deeply({ a => .5283, b => .2213 }, {a => num(.5, .03), b => > num(.2, .03)})' > ok 1 > 11..1 > > is that what you're looking for?
if only my tests were that simple :) i need to test arbitrarily large hashes or arrays. so how would i do that with hash_each so i don't have to enumerate each value by hand?
Subject: Re: [rt.cpan.org #28651] possible to use num() with array_each/hash_each?
Date: Sun, 5 Aug 2007 17:53:32 +0100
To: bug-Test-Deep [...] rt.cpan.org
From: "Fergal Daly" <fergal [...] esatclear.ie>
On 05/08/07, forbin via RT <bug-Test-Deep@rt.cpan.org> wrote: Show quoted text
> if only my tests were that simple :) i need to test arbitrarily large > hashes or arrays. so how would i do that with hash_each so i don't have > to enumerate each value by hand?
So, if all of your hash elements are supposed to be approximately equal then it would be something like hash_each(num($target, $delta)) I see that hash_each is not documented, that's a bug. If the hash values are not all approximately equal then there's no easy way to do it and I'm not sure there could be an easy way. If the key somehow determines an approximate value for the value then you might have some hope but there's nothing built in that'll do the work. You can use Test::Deep::code() to perform arbitrary comparisons at a point in your structure. Inside that comparison you can use further Test::Deep comparisons safely, F
From: colossus.forbin [...] gmail.com
thanks On Sun Aug 05 12:53:45 2007, fergal@esatclear.ie wrote: Show quoted text
> On 05/08/07, forbin via RT <bug-Test-Deep@rt.cpan.org> wrote:
> > if only my tests were that simple :) i need to test arbitrarily large > > hashes or arrays. so how would i do that with hash_each so i don't have > > to enumerate each value by hand?
> > So, if all of your hash elements are supposed to be approximately > equal then it would be something like > > hash_each(num($target, $delta)) > > I see that hash_each is not documented, that's a bug. > > If the hash values are not all approximately equal then there's no > easy way to do it and I'm not sure there could be an easy way. If the > key somehow determines an approximate value for the value then you > might have some hope but there's nothing built in that'll do the work. > > You can use Test::Deep::code() to perform arbitrary comparisons at a > point in your structure. Inside that comparison you can use further > Test::Deep comparisons safely, > > F
Closing, not a bug.