gpt4 book ai didi

actionscript-3 - AS3 Hamcrest - 断言一个数组包含另一个数组

转载 作者:行者123 更新时间:2023-12-04 05:01:51 24 4
gpt4 key购买 nike

我正在尝试使用 Flashbuilder 4.7 环境附带的 Hamcrest 匹配器。我有 2 个数组,数组 A 和数组 B。我想要做的是确保 B 的所有成员都在 A 中找到,无论顺序如何。我正在寻找像这样工作的东西。

var a:Array = new Array( 1, 2, 3, 4);
var b:Array = new Array( 1, 2, 3, 4 );

//Both arrays contain the same values so this should
//return true
assertThat( a , hasEachAndEveryLastOneInsideOfIt(b));

现在我已经尝试过 'allOf' 和 'hasItems' 但我不太能掌握语法。

最佳答案

这是使用自定义 hamcrest 匹配器处理此问题的要点。

用法: assertThat( a , arrayExact(b) );

匹配器类:

https://gist.github.com/jamieowen/5480802

而速记“arrayExact()”函数访问:

https://gist.github.com/jamieowen/5480819

它也应该匹配二维数组。

关于actionscript-3 - AS3 Hamcrest - 断言一个数组包含另一个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16072884/

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