On Wed, 8 Aug 2018 18:00:51 GMT, ETHER wrote:
Show quoted text> On 2018-08-08 08:03:54, PERLANCAR wrote:
>
> > Is there a way to do that with Test::Deep?
>
> Sure:
>
> sub mynum { within_tolerance($_[0], <your tolerance criteria>) }
> or you could even `local *num = \&mynum;`.
>
I'm dense, could you show the full example? Here's how I used it in one of App::cryp::arbit's tests.
#!/usr/bin/env perl
use strict;
use Test::More;
use Test::Deeply::Float;
my $got = [
{
base_size => 0.2,
buy => {
exchange => "gdax",
gross_price => 491.1,
gross_price_orig => 491.1,
net_price => 491.9,
net_price_orig => 491.9,
pair => "ETH/USD",
},
forex_spread => 0,
gross_profit => 1.8,
gross_profit_margin => 1.83262064752596,
net_profit => 1.6,
net_profit_margin => 1.62634681845904,
sell => {
exchange => "indodax",
gross_price => 500.1,
gross_price_orig => 5001000,
net_price => 499.9,
net_price_orig => 4999000,
pair => "ETH/IDR",
},
trading_profit => 1.6,
trading_profit_margin => 1.62634681845904,
},
];
my $expected = [
{
base_size => 0.2,
buy => {
exchange => "gdax",
gross_price => 491.10000001, # TEST DIFF
gross_price_orig => 491.1,
net_price => 491.9,
net_price_orig => 491.9,
pair => "ETH/USD",
},
gross_profit_margin => 1.832620641752596, #TEST DIFF
gross_profit => 1.8,
trading_profit_margin => 1.62634681845904,
trading_profit => 1.6,
forex_spread => 0,
net_profit_margin => 1.62634681845904,
net_profit => 1.6,
sell => {
exchange => "indodax",
gross_price => 500.1,
gross_price_orig => 5001000,
net_price => 499.9000001, # TEST DIFF
net_price_orig => 4999000,
pair => "ETH/IDR",
},
},
];
is_deeply_float($got, $expected);
done_testing;