断言数组是用 minitest 排序的

Assert that an array is ordered with minitest

我需要能够使用 ruby 使用 minitest 编写一个测试,断言给定数组是按 asc 或 desc 排序的。

我有不完整的代码如下:

 it "can order an array by asc order" do
     assert_equal tested_array, sorted_array
end

你可以这样写:

test "array should be sorted asc" do
  sorted_array = tested_array.sort
  assert_equal tested_array, sorted_array, "Array sorted"
end

desc 相同,但写成 tested_array.sort.reverse 而不是 tested_array.sort