Skip Menu |

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

Report information
The Basics
Id: 100761
Status: open
Priority: 0/
Queue: Test-Approximate

People
Owner: Nobody in particular
Requestors: ether [...] cpan.org
Cc:
AdminCc:

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



Subject: See also: Test::Deep::NumberTolerant
"I wrote this one because Test::Approx can't do a deeply test, and I have not found a module do the same thing." --> have you seen Test::Deep::NumberTolerant?
Subject: Re: [rt.cpan.org #100761] See also: Test::Deep::NumberTolerant
Date: Mon, 8 Dec 2014 00:18:36 +0800
To: bug-Test-Approximate [...] rt.cpan.org
From: Genban Tade <tadegenban [...] gmail.com>
Hi, thanks for mention . I had found Test::Deep::NumberTolerant before, but I don't know how to use this module to do this quickly cmp_deeply( [1, { a => 2 } , { b => 3} ], approx([1.0001, { a => 2.001} , { b => 3.003} ], '1%'), 'approximate equal two array of hash' ); 2014-12-07 11:39 GMT+08:00 Karen Etheridge via RT < bug-Test-Approximate@rt.cpan.org>: Show quoted text
> Sat Dec 06 22:39:00 2014: Request 100761 was acted upon. > Transaction: Ticket created by ETHER > Queue: Test-Approximate > Subject: See also: Test::Deep::NumberTolerant > Broken in: (no value) > Severity: (no value) > Owner: Nobody > Requestors: ether@cpan.org > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=100761 > > > > "I wrote this one because Test::Approx can't do a deeply test, and I have > not found a module do the same thing." --> have you seen > Test::Deep::NumberTolerant? >
RT-Send-CC: tadegenban [...] gmail.com
On 2014-12-07 08:18:45, tadegenban@gmail.com wrote: Show quoted text
> Hi, > > thanks for mention . I had found Test::Deep::NumberTolerant before, but > I don't know how to use this module to do this quickly > > cmp_deeply( [1, { a => 2 } , { b => 3} ], approx([1.0001, { a => 2.001} , { > b => 3.003} ], '1%'), 'approximate equal two array of hash' );
If by "approximate" you mean "within 0.01%", I think it would be: cmp_deeply( [ 1, { a => 2 }, { b => 3 }, ], [ within_tolerance(1, plus_or_minus_pct => 1e-2), { a => within_tolerance(2, plus_or_minus_pct => 1e-2) }, { b => within_tolerance(3, plus_or_minus_pct => 1e-2) }, ], 'approximate equal two array of hash', ); if you're doing this a lot, you could use a local wrapper in the test: sub approx { within_tolerance(shift, plus_or_minus_pct => 1e-2) } cmp_deeply( [ 1, { a => 2 }, { b => 3 }, ], [ approx(1), { a => approx(2) }, { b => approx(3) }, ], 'approximate equal two array of hash', );