Project

General

Profile

Actions

Misc #22515

closed

Add tests for hash#sort_by

Misc #22515: Add tests for hash#sort_by

Added by hdiwan (Hasan Diwan) 1 day ago. Updated 1 day ago.

Status:
Rejected
Assignee:
-
[ruby-core:127365]

Description

I noticed Hash#sort_by had no test coverage, so I added a few tests for it:


  def test_sort_by
    assert_equal({ zebra: 90, apple: 90, banana: 85,c: 3, a: 1, b: 2  }.sort_by { |key, value| [ key, value] }.to_h,{a: 1, apple: 90, b: 2, banana: 85, c: 3, zebra: 90})
    assert_equal({ zebra: 90, apple: 90, banana: 85,c: 3, a: 1, b: 2  }.sort_by { |key, value| [value, key] }.to_h, {a: 1, b: 2, c: 3, banana: 85, apple: 90, zebra: 90})
  end


Actions

Also available in: PDF Atom