Subject: | bug in test #13 -- 2 extra digits in floating point number = bad compare; example patch included |
Date: | Sat, 15 Apr 2017 07:26:29 -0700 |
To: | bug-Lingua-EN-Bigram [...] rt.cpan.org |
From: | L A Walsh <perl-diddler [...] tlinx.org> |
Test 13 does a patch of a floating point number
(1.7248916005935306) against a fixed value (1.72489160059353).
This will happen on any platform that has a different number of
digits in its floating point format.
Including a sample patch that should handle short as well as
longer floating point numbers (only longer ones tested though).
--- ngram.t 2010-08-23 18:37:34.000000000 -0700
+++ ngram.t 2017-04-15 07:23:24.554183391 -0700
@@ -1,6 +1,8 @@
use strict;
use Test::Exception;
use Test::More tests => 28;
+use P;
+use Math::Simple qw(- min);
# ngram.t - regression texts for Lingua::EN::Bigram
@@ -47,7 +49,11 @@
# tscore
my $tscore = $ngrams->tscore;
is( ref( $tscore ), 'HASH', 'tscore is a hash' );
-is( $$tscore{ 'something else' }, 1.72489160059353, '"something else:
has a tscore of 1.72489160059353' );
+my $score = $tscore->{'something else'};
+my $ans = 1.72489160059353;
+my $len = min(length($ans), length($score))-1;
+my $fmt = P("%%%s.%sf", $len, $len-2);
+is( P( $fmt, $score), P($fmt,1.72489160059353), '"something else: has a
tscore of 1.72489160059353' );
# trigrams
my @trigrams = $ngrams->trigrams;