Skip Menu |

This queue is for tickets about the Lingua-EN-SimilarNames-Levenshtein CPAN distribution.

Report information
The Basics
Id: 70466
Status: resolved
Priority: 0/
Queue: Lingua-EN-SimilarNames-Levenshtein

People
Owner: Nobody in particular
Requestors: vpit [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.09
Fixed in: (no value)



Subject: A fix for the random failure of the last test
Hello, The last test of t/basic.t fails randomly because the second sort you're applying does not describe a total order. Both what you expect : my @expected = ( [ [ "Jose", "Wales" ], [ "John", "Wall" ] ], [ [ "Jose", "Wales" ], [ "John", "Wayne" ] ], [ [ "John", "Wall" ], [ "John", "Wayne" ] ] ); and what you get after the second sort (on my machine) my @got = ( [ [ 'Jose', 'Wales' ], [ 'John', 'Wayne' ] ], [ [ 'Jose', 'Wales' ], [ 'John', 'Wall' ] ], [ [ 'John', 'Wall' ], [ 'John', 'Wayne' ] ] ); are sorted according to sort { ($a->[0][1] cmp $b->[0][1]) || ($a->[0][0] cmp $b->[0][0]) } @array but that's because your criterion considers that [ [ 'Jose', 'Wales' ], [ 'John', 'Wayne' ] ] and [ 'Jose', 'Wales' ], [ 'John', 'Wall' ] ] are equal. The fix is just to also look at the second element. Patch attached. I think the order may differ on different machines because Math::Combinatorics make no guarantee on the order on which it iterates on the pairs, and that using Test::More instead of Test::Leaner may magically change that order. Vincent.
Subject: lingua_en_similarnames_levenshtein_sort.patch
--- t/basic.t 2011-08-24 19:26:02.000000000 +0200 +++ t/basic.t 2011-08-24 19:27:53.000000000 +0200 @@ -47,10 +47,8 @@ my @person_pair = sort { ($a->[1] cmp $b->[1]) || ($a->[0] cmp $b->[0]) } @{$person_pair}; push @people_sorted, \@person_pair; } -@people_sorted = sort { ($a->[0][1] cmp $b->[0][1]) || ($a->[0][0] cmp $b->[0][0]) } @people_sorted; -# cpantest is regularly choking on this test and I don't now why -# The sort above works reliably for me to get the results to match up with what's expected. -#is_deeply($expected_list, \@people_sorted, 'People with Similar Names'); +@people_sorted = sort { ($a->[0][1] cmp $b->[0][1]) || ($a->[0][0] cmp $b->[0][0]) || ($a->[1][1] cmp $b->[1][1]) || ($a->[1][0] cmp $b->[1][0]) } @people_sorted; +is_deeply($expected_list, \@people_sorted, 'People with Similar Names'); done_testing();
Merci beaucoup for correcting the sort in my test. On Wed Aug 24 13:25:04 2011, VPIT wrote: Show quoted text
> Hello, > > The last test of t/basic.t fails randomly because the second sort you're > applying does not describe a total order. Both what you expect : > > my @expected = ( > [ [ "Jose", "Wales" ], [ "John", "Wall" ] ], > [ [ "Jose", "Wales" ], [ "John", "Wayne" ] ], > [ [ "John", "Wall" ], [ "John", "Wayne" ] ] > ); > > and what you get after the second sort (on my machine) > > my @got = ( > [ [ 'Jose', 'Wales' ], [ 'John', 'Wayne' ] ], > [ [ 'Jose', 'Wales' ], [ 'John', 'Wall' ] ], > [ [ 'John', 'Wall' ], [ 'John', 'Wayne' ] ] > ); > > are sorted according to > > sort { ($a->[0][1] cmp $b->[0][1]) || ($a->[0][0] cmp $b->[0][0]) } > @array > > but that's because your criterion considers that [ [ 'Jose', 'Wales' ], > [ 'John', 'Wayne' ] ] and [ 'Jose', 'Wales' ], [ 'John', 'Wall' ] ] > are equal. > > The fix is just to also look at the second element. Patch attached. I > think the order may differ on different machines because > Math::Combinatorics make no guarantee on the order on which it iterates > on the pairs, and that using Test::More instead of Test::Leaner may > magically change that order. > > Vincent.