我经常想要比较数组并确保它们以任何顺序包含相同的元素.在RSpec中有一个简洁的方法吗?
以下是不可接受的方法:
#to_set例如:
expect(array.to_set).to eq another_array.to_set
Run Code Online (Sandbox Code Playgroud)
要么
array.to_set.should == another_array.to_set
Run Code Online (Sandbox Code Playgroud)
当数组包含重复项时,这会失败.
#sort例如:
expect(array.sort).to eq another_array.sort
Run Code Online (Sandbox Code Playgroud)
要么
array.sort.should == another_array.sort
Run Code Online (Sandbox Code Playgroud)
当数组元素未实现时,这会失败 #<=>
假设我有两个 Numpy 数组 A 和 B,我想看看是否有sorted(A) == sorted(B)?例如:如果A = [5,3,2,4]和B = [3,2,5,4],那么我必须得到真。这样做的最快方法是什么?