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',
);