I am looking for a test routine like is_deeply in Test::More.
There’s cmp_bag from Test::Deep but this only operates on the array itself, not the horribly large hash-of-arrays-of-hashes data structure I’m passing in. Is there something like:
is_deeply $got, $expected, {
array => cmp_bag,
# and other configuration...
}, "Ugly data structure should be the same, barring array order.";
Clarification
I could recursively delve into my $expected and $got objects and convert the arrays into bag objects:
sub bagIt {
my $obj = shift;
switch (ref($obj)) {
case "ARRAY" {
return bag([
map { $_ = bagIt($_) }
@$obj
]);
} case "HASH" {
return {
map { $_ => bagIt( $obj->{$_} ) }
keys %$obj
};
} else {
return $obj;
}
}
}
I’m wondering if there is a way to tell some variant of is_deeply to do this for me.
Looks like there isn’t an option in
Test::Deepor otherTest::*packages to treat each array as a bag-set. The following function works, but is not efficient for testing over large data structures:In the end, I ended up refactoring my code to not depend upon such a course-grained test.