From c0364a60a46ef847cf4f960fe2b24e078f3ad944 Mon Sep 17 00:00:00 2001 From: Andreas Koenig Date: Sat, 27 Jul 2013 09:05:01 +0200 Subject: [PATCH] introduce tolerance on floating point numbers by using Test::Number::Delta::delta_ok instead of string equality --- Makefile.PL | 1 + t/basic.t | 3 ++- t/types.t | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 4eb19c7..0bc3c02 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -19,6 +19,7 @@ my %mm = ( VERSION_FROM => 'lib/JavaScript/V8.pm', # finds $VERSION PREREQ_PM => { 'ExtUtils::XSpp' => '0.11', + 'Test::Number::Delta' => 0, }, # e.g., Module::Name => 1.1 ABSTRACT_FROM => 'lib/JavaScript/V8.pm', # retrieve abstract from module AUTHOR => 'Pawel Murias ', diff --git a/t/basic.t b/t/basic.t index aabbed8..8028fa4 100644 --- a/t/basic.t +++ b/t/basic.t @@ -1,5 +1,6 @@ #!/usr/bin/perl use Test::More; +use Test::Number::Delta within => 1e-9; use JavaScript::V8; use strict; use warnings; @@ -16,7 +17,7 @@ is $val,777,"integers"; is($context->eval("'\x{a3}'"), "\x{a3}", 'latin-1 strings'); -is($context->eval("1.34"), 1.34, 'numbers'); +delta_ok($context->eval("1.34"), 1.34, 'numbers'); ok(!defined $context->eval('undefined'), 'undefined'); ok(!defined $context->eval('null'), 'null'); diff --git a/t/types.t b/t/types.t index e7b3984..90ef67a 100644 --- a/t/types.t +++ b/t/types.t @@ -1,6 +1,7 @@ #!/usr/bin/perl use Test::More; +use Test::Number::Delta within => 1e-9; use JavaScript::V8; use utf8; @@ -14,7 +15,7 @@ is $context->eval('(function(v) { return v })')->(2174652970), 2174652970, '32-b is $context->eval('(function(v) { return v })')->(-2174652970), -2174652970, '32-bit numbers are ok'; is $context->eval('(function(v) { return v })')->(-2170), -2170, '32-bit numbers are ok'; is $context->eval('(function(v) { return v })')->(2170), 2170, '32-bit numbers are ok'; -is $context->eval('(function(v) { return v })')->(2.34234), 2.34234, 'real numbers are ok'; +delta_ok $context->eval('(function(v) { return v })')->(2.34234), 2.34234, 'real numbers are ok'; is $context->eval('(function(v) { return v + 2; })')->(2), 4; is $context->eval('(function(v) { return v + 2; })')->('2'), '22', 'string converts into a string'; -- 1.8.1.6