Skip to content

Instantly share code, notes, and snippets.

@notbenh
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notbenh/866b95cbea06a5d50b4f to your computer and use it in GitHub Desktop.
Save notbenh/866b95cbea06a5d50b4f to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Differences;
use List::MoreUtils qw{uniq};
sub pp {
my %lookup;
my $i;
$lookup{$_} = $i++ for sort( uniq( map{@$_} @_ ));
my @blank = map{undef} keys %lookup;
return [ map{ my @a = @blank;
$a[$lookup{$_}] = $_ for @$_;
\@a;
} @_
];
}
eq_or_diff pp( [qw{ b c f }]
, [qw{ a d }]
, [qw{ c d e }]
)
, [ [ undef, 'b', 'c', undef, undef, 'f' ]
, [ 'a', undef, undef, 'd', undef, undef ]
, [ undef, undef, 'c', 'd', 'e', undef ]
]
, 'example from blog';
eq_or_diff pp( [qw{ f c b }]
, [qw{ a d d}]
, [qw{ c c d e }]
)
, [ [ undef, 'b', 'c', undef, undef, 'f' ]
, [ 'a', undef, undef, 'd', undef, undef ]
, [ undef, undef, 'c', 'd', 'e', undef ]
]
, 'shows that this will eat duplicates and alter order';
eq_or_diff pp( [qw{ a b c f j}]
, [qw{ i j }]
, []
)
, [ [ 'a', 'b', 'c', 'f', undef, 'j' ]
, [ undef, undef, undef, undef, 'i', 'j' ]
, [ undef, undef, undef, undef, undef, undef ]
]
, 'test for the j-alignment bug and show that it correctly handles null input';
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment