gpt4 book ai didi

perl - is_deeply 测试忽略数组顺序?

转载 作者:行者123 更新时间:2023-12-04 15:02:39 25 4
gpt4 key购买 nike

我正在寻找像 is_deeply 这样的测试例程在 Test::More .
cmp_bag来自 Test::Deep 但这仅适用于数组本身,而不是我传入的非常大的哈希数组哈希数据结构。是否有类似的东西:

is_deeply $got, $expected, {
array => cmp_bag,
# and other configuration...
}, "Ugly data structure should be the same, barring array order.";

澄清

我可以递归地钻研我的 $expected$got对象并将数组转换为包对象:
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;
}
}
}

我想知道是否有办法告诉 is_deeply 的某些变体为我做这件事。

最佳答案

好吧,来自 Test::Deep docs , cmp_bag(\@got, \@bag, $name)只是 cmp_deeply(\@got, bag(@bag), $name) 的简写.

is_deeply( $got, {
array => bag(qw/the values you expect/),
# and other expected values
}, "Ugly data structure should be the same, barring array order." );

关于perl - is_deeply 测试忽略数组顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9523141/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com