[ruby-core:127365] [Ruby Misc#22515] Add tests for hash#sort_by
Issue #22515 has been reported by hdiwan (Hasan Diwan). ---------------------------------------- Misc #22515: Add tests for hash#sort_by https://bugs.ruby-lang.org/issues/22515 * Author: hdiwan (Hasan Diwan) * Status: Open ---------------------------------------- ``` ruby 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 ``` I noticed Hash#sort_by had no test coverage. -- https://bugs.ruby-lang.org/
Issue #22515 has been updated by byroot (Jean Boussier). Status changed from Open to Rejected Not sure if you intended to link to a patch of some sort but it's not there. Anyway, you are probably best to submit a PR to https://github.com/ruby/spec/ ---------------------------------------- Misc #22515: Add tests for hash#sort_by https://bugs.ruby-lang.org/issues/22515#change-119798 * Author: hdiwan (Hasan Diwan) * Status: Rejected ---------------------------------------- I noticed Hash#sort_by had no test coverage, so I added a few tests for it: ``` ruby 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 ``` -- https://bugs.ruby-lang.org/
participants (2)
-
byroot (Jean Boussier) -
hdiwan (Hasan Diwan)