Home Ask Login Register

Developers Planet

Your answer is one click away!

Ricardo Parro February 2016

Assert that an array is ordered with minitest

I need to be able to write a test with minitest using ruby that asserts that a given array is ordered by asc or desc.

I have incomplete code as follows:

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


Ilya February 2016

You can write something like this:

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

Same for desc, but write tested_array.sort.reverse instead tested_array.sort

Post Status

Asked in February 2016
Viewed 1,495 times
Voted 7
Answered 1 times


Leave an answer

Quote of the day: live life