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