From b4e1dbdc5fb05f082be6fe240a4c316b527fdd15 Mon Sep 17 00:00:00 2001 From: Frédéric Buclin Date: Sat, 19 Nov 2011 00:57:57 +0100 Subject: Bug 703788: Improve performance of diff_arrays() with large arrays r/a=mkanat --- t/007util.t | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 't') diff --git a/t/007util.t b/t/007util.t index 742c2b2d2..b32a1b90c 100644 --- a/t/007util.t +++ b/t/007util.t @@ -18,7 +18,7 @@ # # Contributor(s): Zach Lipton # Max Kanat-Alexander - +# Frédéric Buclin ################# #Bugzilla Test 7# @@ -26,7 +26,7 @@ use lib 't'; use Support::Files; -use Test::More tests => 13; +use Test::More tests => 15; BEGIN { use_ok(Bugzilla); @@ -72,3 +72,16 @@ foreach my $input (keys %email_strings) { is(Bugzilla::Util::email_filter($input), $email_strings{$input}, "email_filter('$input')"); } + +# diff_arrays(): +my @old_array = qw(alpha beta alpha gamma gamma beta alpha delta epsilon gamma); +my @new_array = qw(alpha alpha beta gamma epsilon delta beta delta); +# The order is not relevant when comparing both arrays for matching items, +# i.e. (foo bar) and (bar foo) are the same arrays (same items). +# But when returning data, we try to respect the initial order. +# We remove the leftmost items first, and return what's left. This means: +# Removed (in this order): gamma alpha gamma. +# Added (in this order): delta +my ($removed, $added) = diff_arrays(\@old_array, \@new_array); +is_deeply($removed, [qw(gamma alpha gamma)], 'diff_array(\@old, \@new) (check removal)'); +is_deeply($added, [qw(delta)], 'diff_array(\@old, \@new) (check addition)'); -- cgit v1.2.3-24-g4f1b