Skip Menu |

This queue is for tickets about the Array-Diff CPAN distribution.

Report information
The Basics
Id: 101707
Status: resolved
Priority: 0/
Queue: Array-Diff

People
Owner: NEILB [...] cpan.org
Requestors: a.shikov [...] dtel-ix.net
Cc: gregoa [...] cpan.org
AdminCc:

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



Subject: Array::Diff->count returns wrong number
Date: Fri, 23 Jan 2015 18:00:40 +0200
To: bug-Array-Diff [...] rt.cpan.org
From: Alexander Shikov <a.shikov [...] dtel-ix.net>
Hello! Bug is reproducible with simple example: #!/usr/bin/perl use warnings; use strict; use Array::Diff; use Data::Dumper; my $old = [ 'a' ]; my @new = ( 'b', 'c', 'd' ); my $diff = Array::Diff->diff( $old, \@new ); my $cnt = $diff->count; my $add_ref = $diff->added; my $del_ref = $diff->deleted; print "cnt=$cnt\n"; print "add: ", Dumper( $add_ref ), "\n"; print "del: ", Dumper( $del_ref ), "\n"; print "add-list: ", @{$add_ref}, "\n"; print "del-list: ", @{$del_ref}, "\n"; __END__ cnt=1 add: $VAR1 = [ 'b', 'c', 'd' ]; del: $VAR1 = [ 'a' ]; add-list: bcd del-list: a $diff->count should be 4, not 1. -- Alexander Shikov Technical Staff, Digital Telecom IX Tel.: +380 44 201 14 07 http://dtel-ix.net/
I have submitted a pull request that fixes this issue, now we need to wait for the module owner (typesetter) to approve it. https://github.com/typester/array-diff-perl/pull/3
I also wish to clarify this Show quoted text
>This count should be equal to the sum of the number of elements in the added and deleted properties.
Test case: Show quoted text
DBG>$old
[ 23, 5, 13, 14, 15, 16, 11, 29, 17, 18, 19, 20, ] Show quoted text
DBG>$new
[ 4, 5, 11, 13, 14, 15, 16, 17, 18, 20, 23, 29, ] Show quoted text
DBG>$diff = Array::Diff->diff( $new, $old )
Array::Diff { added => [ 23, 11, 29, 19, ], count => 5, deleted => [ 4, 11, 23, 29, ], diff_class => Algorithm::Diff, } The sum of added and deleted is 8, not 5
HIPYHOP's PR was merged by TYPESTER, and may have been released when I did 0.08. Fixed now anyway :-)