1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
# perl
#$Id$
# 42_func_hashes_dual_unsorted.t
use strict;
use Test::More tests => 38;
use List::Compare::Functional qw(:originals :aliases);
use lib ("./t");
use Test::ListCompareSpecial qw( :seen :func_wrap :hashes :results );
use Capture::Tiny q|:all|;
my @pred = ();
my %seen = ();
my %pred = ();
my @unpred = ();
my (@unique, @complement, @intersection, @union, @symmetric_difference, @bag);
my ($unique_ref, $complement_ref, $intersection_ref, $union_ref,
$symmetric_difference_ref, $bag_ref);
my ($LR, $RL, $eqv, $disj, $return, $vers);
my (@nonintersection, @shared);
my ($nonintersection_ref, $shared_ref);
my ($memb_hash_ref, $memb_arr_ref, @memb_arr);
my ($unique_all_ref, $complement_all_ref);
my @args;
%pred = map {$_, 1} qw( abel baker camera delta edward fargo golfer hilton );
@unpred = qw| icon jerky |;
@union = get_union( '-u', [ \%h0, \%h1 ] );
$seen{$_}++ foreach (@union);
is_deeply(\%seen, \%pred, "unsorted: got expected union");
ok(unseen(\%seen, \@unpred),
"union: All non-expected elements correctly excluded");
%seen = ();
$union_ref = get_union_ref( '-u', [ \%h0, \%h1 ] );
$seen{$_}++ foreach (@{$union_ref});
is_deeply(\%seen, \%pred, "unsorted: got expected union");
ok(unseen(\%seen, \@unpred),
"union: All non-expected elements correctly excluded");
%seen = ();
%pred = map {$_, 1} qw( baker camera delta edward fargo golfer );
@unpred = qw| abel hilton icon jerky |;
@shared = get_shared( '-u', [ \%h0, \%h1 ] );
$seen{$_}++ foreach (@shared);
is_deeply(\%seen, \%pred, "unsorted: got expected shared");
ok(unseen(\%seen, \@unpred),
"shared: All non-expected elements correctly excluded");
%seen = ();
$shared_ref = get_shared_ref( '-u', [ \%h0, \%h1 ] );
$seen{$_}++ foreach (@{$shared_ref});
is_deeply(\%seen, \%pred, "unsorted: got expected shared");
ok(unseen(\%seen, \@unpred),
"shared: All non-expected elements correctly excluded");
%seen = ();
%pred = map {$_, 1} qw( baker camera delta edward fargo golfer );
@unpred = qw| abel hilton icon jerky |;
@intersection = get_intersection( '-u', [ \%h0, \%h1 ] );
$seen{$_}++ foreach (@intersection);
is_deeply(\%seen, \%pred, "unsorted: got expected intersection");
ok(unseen(\%seen, \@unpred),
"intersection: All non-expected elements correctly excluded");
%seen = ();
$intersection_ref = get_intersection_ref( '-u', [ \%h0, \%h1 ] );
$seen{$_}++ foreach (@{$intersection_ref});
is_deeply(\%seen, \%pred, "unsorted: got expected intersection");
ok(unseen(\%seen, \@unpred),
"intersection: All non-expected elements correctly excluded");
%seen = ();
%pred = map {$_, 1} qw( abel );
@unpred = qw| baker camera delta edward fargo golfer hilton icon jerky |;
@unique = get_unique( '-u', [ \%h0, \%h1 ] );
$seen{$_}++ foreach (@unique);
is_deeply(\%seen, \%pred, "unsorted: got expected unique");
ok(unseen(\%seen, \@unpred),
"unique: All non-expected elements correctly excluded");
%seen = ();
$unique_ref = get_unique_ref( '-u', [ \%h0, \%h1 ] );
$seen{$_}++ foreach (@{$unique_ref});
is_deeply(\%seen, \%pred, "unsorted: got expected unique");
ok(unseen(\%seen, \@unpred),
"unique: All non-expected elements correctly excluded");
%seen = ();
@pred = (
[ 'abel' ],
[ 'hilton' ],
);
$unique_all_ref = get_unique_all( '-u', [ \%h0, \%h1 ] );
is_deeply(
make_array_seen_hash($unique_all_ref),
make_array_seen_hash(\@pred),
"Got expected values for get_unique_all()");
%pred = map {$_, 1} qw( hilton );
@unpred = qw| abel baker camera delta edward fargo golfer icon jerky |;
@complement = get_complement( '-u', [ \%h0, \%h1 ] );
$seen{$_}++ foreach (@complement);
is_deeply(\%seen, \%pred, "unsorted: got expected complement");
ok(unseen(\%seen, \@unpred),
"complement: All non-expected elements correctly excluded");
%seen = ();
$complement_ref = get_complement_ref( '-u', [ \%h0, \%h1 ] );
$seen{$_}++ foreach (@{$complement_ref});
is_deeply(\%seen, \%pred, "unsorted: got expected complement");
ok(unseen(\%seen, \@unpred),
"complement: All non-expected elements correctly excluded");
%seen = ();
@pred = (
[ qw( hilton ) ],
[ qw( abel ) ],
);
$complement_all_ref = get_complement_all( '-u', [ \%h0, \%h1 ] );
is_deeply(
make_array_seen_hash($complement_all_ref),
make_array_seen_hash(\@pred),
"Got expected values for get_complement_all()");
%pred = map {$_, 1} qw( abel hilton );
@unpred = qw| baker camera delta edward fargo golfer icon jerky |;
@symmetric_difference = get_symmetric_difference( '-u', [ \%h0, \%h1 ] );
$seen{$_}++ foreach (@symmetric_difference);
is_deeply(\%seen, \%pred, "unsorted: Got expected symmetric difference");
ok(unseen(\%seen, \@unpred),
"symmetric difference: All non-expected elements correctly excluded");
%seen = ();
$symmetric_difference_ref =
get_symmetric_difference_ref( '-u', [ \%h0, \%h1 ] );
$seen{$_}++ foreach (@{$symmetric_difference_ref});
is_deeply(\%seen, \%pred, "unsorted: Got expected symmetric difference");
ok(unseen(\%seen, \@unpred),
"symmetric difference: All non-expected elements correctly excluded");
%seen = ();
@symmetric_difference = get_symdiff( '-u', [ \%h0, \%h1 ] );
$seen{$_}++ foreach (@symmetric_difference);
is_deeply(\%seen, \%pred, "unsorted: Got expected symmetric difference");
ok(unseen(\%seen, \@unpred),
"symmetric difference: All non-expected elements correctly excluded");
%seen = ();
$symmetric_difference_ref = get_symdiff_ref( '-u', [ \%h0, \%h1 ] );
$seen{$_}++ foreach (@{$symmetric_difference_ref});
is_deeply(\%seen, \%pred, "unsorted: Got expected symmetric difference");
ok(unseen(\%seen, \@unpred),
"symmetric difference: All non-expected elements correctly excluded");
%seen = ();
%pred = map {$_, 1} qw( abel hilton );
@unpred = qw| baker camera delta edward fargo golfer icon jerky |;
@nonintersection = get_nonintersection( '-u', [ \%h0, \%h1 ] );
$seen{$_}++ foreach (@nonintersection);
is_deeply(\%seen, \%pred, "unsorted: Got expected nonintersection");
ok(unseen(\%seen, \@unpred),
"nonintersection: All non-expected elements correctly excluded");
%seen = ();
$nonintersection_ref = get_nonintersection_ref( '-u', [ \%h0, \%h1 ] );
$seen{$_}++ foreach (@{$nonintersection_ref});
is_deeply(\%seen, \%pred, "unsorted: Got expected nonintersection");
ok(unseen(\%seen, \@unpred),
"nonintersection: All non-expected elements correctly excluded");
%seen = ();
%pred = (
abel => 2,
baker => 2,
camera => 2,
delta => 3,
edward => 2,
fargo => 2,
golfer => 2,
hilton => 1,
);
@unpred = qw| icon jerky |;
@bag = get_bag( '-u', [ \%h0, \%h1 ] );
$seen{$_}++ foreach (@bag);
is_deeply(\%seen, \%pred, "Got predicted quantities in bag");
ok(unseen(\%seen, \@unpred),
"bag: All non-expected elements correctly excluded");
%seen = ();
$bag_ref = get_bag_ref( '-u', [ \%h0, \%h1 ] );
$seen{$_}++ foreach (@{$bag_ref});
is_deeply(\%seen, \%pred, "Got predicted quantities in bag");
ok(unseen(\%seen, \@unpred),
"bag: All non-expected elements correctly excluded");
%seen = ();
|