CC: | srezic [...] iconmobile.com |
Subject: | Wrong sorting of negative or float numbers |
See the attached test script. It seems that negative integers are not
compared correctly, and some float numbers also not.
Maybe it would help here if instead of using regexps to check if a value
is a number the function Scalar::Util::looks_like_number is used instead?
Regards,
Slaven
Subject: | num_ncmp.t |
#!/usr/bin/perl
use strict;
use warnings;
use Test::More 'no_plan';
use Sort::Naturally 'ncmp';
diag "Sort::Natually $Sort::Naturally::VERSION";
sub testcmp ($$$) {
my($got, $expected, $testname) = @_;
local $Test::Builder::Level = $Test::Builder::Level + 1;
is ncmp($got,$expected), ($got <=> $expected), $testname;
}
testcmp 1, 2, 'ncmp with positive integers';
testcmp -1, 2, 'ncmp with mixed integers';
testcmp 1, -2, 'ncmp with mixed integers';
testcmp -1, -2, 'ncmp with negative integers';
testcmp 0.8, 0.085, 'ncmp with positive floats';
testcmp 0.085, 0.8, 'ncmp with positive floats';
testcmp -0.8, 0.085, 'ncmp with mixed floats';
testcmp 0.085, -0.8, 'ncmp with mixed floats';
testcmp -0.8, -0.085, 'ncmp with negative floats';
testcmp -0.085, -0.8, 'ncmp with negative floats';
__END__