TT#69200 Reimplement removeduplicates() based of List::Util's uniq

This adds a behavior change, reflected in the unit test changes, by
always returning the lowercased versions of the array elements when
case insensitiveness is enabled. This should be fine, given that we
do not care from the callers PoV, and the result might have changed
depending on the order of the inputs.

Change-Id: I44896183b566e921cc1287f106fb4bb9332acb97
changes/74/34774/3
Guillem Jover 6 years ago
parent 54704e0837
commit 9485368290

@ -3,7 +3,7 @@ use strict;
## no critic
use List::Util qw(any);
use List::Util qw(any uniq);
use NGCP::BulkProcessor::Table;
@ -40,18 +40,19 @@ sub mergearrays {
}
sub removeduplicates {
my ($array_ptr, $case_insensitive) = @_;
my ($array_ptr,$case_insensitive) = @_;
my @result = ();
if (defined $array_ptr and ref $array_ptr eq 'ARRAY') {
foreach my $element (@$array_ptr) {
if (not contains($element,\@result,$case_insensitive)) {
push @result,$element;
}
my @result;
if (defined $array_ptr and ref $array_ptr eq 'ARRAY') {
if ($case_insensitive) {
@result = map { lc } @{$array_ptr};
} else {
@result = @{$array_ptr};
}
@result = uniq @result;
}
}
return \@result;
return \@result;
}

@ -53,7 +53,7 @@ is_deeply(removeduplicates([ qw(aa bb aa cc aa) ], 0), [ qw(aa bb cc) ]);
is_deeply(removeduplicates([ qw(aa aa bb bb cc cc) ], 0), [ qw(aa bb cc) ]);
is_deeply(removeduplicates([ qw(aa bb aa cc bb cc) ], 0), [ qw(aa bb cc) ]);
is_deeply(removeduplicates([ qw(Aa BB cC) ], 1), [ qw(Aa BB cC) ]);
is_deeply(removeduplicates([ qw(aA BB Aa Cc aa) ], 1), [ qw(aA BB Cc) ]);
is_deeply(removeduplicates([ qw(aA AA bB Bb CC cc) ], 1), [ qw(aA bB CC) ]);
is_deeply(removeduplicates([ qw(AA bB Aa cc Bb CC) ], 1), [ qw(AA bB cc) ]);
is_deeply(removeduplicates([ qw(Aa BB cC) ], 1), [ qw(aa bb cc) ]);
is_deeply(removeduplicates([ qw(aA BB Aa Cc aa) ], 1), [ qw(aa bb cc) ]);
is_deeply(removeduplicates([ qw(aA AA bB Bb CC cc) ], 1), [ qw(aa bb cc) ]);
is_deeply(removeduplicates([ qw(AA bB Aa cc Bb CC) ], 1), [ qw(aa bb cc) ]);

Loading…
Cancel
Save