Subject: | result can depend on order of numbers in list |
The find(1) result can depend on the order of numbers in the list.
For example, if the number is 6, and the list contains 5 and 7, the result is 5.
But, if the list contains 7 and 5 in that order, the result is 7.
I included a patch to eliminate that inconsistency. I also included a new test.
Subject: | 02-order.t |
use Test::More tests => 3;
BEGIN {
use_ok( 'Number::Closest' );
}
my $num = 6;
my $closest;
$closest = Number::Closest->new(number => $num, numbers => [qw(5 7)], amount => 1) ;
is($closest->find(1), 5, '5 before 7');
$closest = Number::Closest->new(number => $num, numbers => [qw(7 5)], amount => 1) ;
is($closest->find(1), 5, '7 before 5');
Subject: | diff-u.txt |
--- ../Number-Closest-0.05.orig/lib/Number/Closest.pm 2015-09-01 11:06:27.000000000 -0400
+++ lib/Number/Closest.pm 2015-09-01 12:00:07.811697000 -0400
@@ -10,7 +10,7 @@
sub analyze {
my($self)=@_;
- my @dist = sort { $a->[1] <=> $b->[1] } map { [$_, abs($_ - $self->number)] } @{$self->numbers} ;
+ my @dist = sort { $a->[1] <=> $b->[1] } map { [$_, abs($_ - $self->number)] } sort {$a <=> $b} @{$self->numbers} ;
\@dist
}