Sha256: b5e3a10df223255f9d21bd264aac755f8a90dfffd5c5cd2407c18c1ff0ddc388

Contents?: true

Size: 519 Bytes

Versions: 16

Compression:

Stored size: 519 Bytes

Contents

require 'rspec'
require 'enumerable_ext'

describe Enumerable do
  describe '#stable_sort' do
    it 'sorts stably' do
      xs = [-2, 2, 1, -1]
      result = xs.stable_sort{|a, b| a.abs <=> b.abs}
      expected_result = [1, -1, -2, 2]
      expect(result).to eql expected_result

      normal_sort_result = xs.sort{|a, b| a.abs <=> b.abs}
      expect(normal_sort_result).to_not eql expected_result
    end

    it 'does not require a block' do
      expect([3, 2, 1].stable_sort).to eql [1, 2, 3]
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
abstractivator-0.0.31 spec/lib/enumerable_ext_spec.rb
abstractivator-0.0.30 spec/lib/enumerable_ext_spec.rb
abstractivator-0.0.29 spec/lib/enumerable_ext_spec.rb
abstractivator-0.0.28 spec/lib/enumerable_ext_spec.rb
abstractivator-0.0.27 spec/lib/enumerable_ext_spec.rb
abstractivator-0.0.26 spec/lib/enumerable_ext_spec.rb
abstractivator-0.0.25 spec/lib/enumerable_ext_spec.rb
abstractivator-0.0.24 spec/lib/enumerable_ext_spec.rb
abstractivator-0.0.23 spec/lib/enumerable_ext_spec.rb
abstractivator-0.0.22 spec/lib/enumerable_ext_spec.rb
abstractivator-0.0.21 spec/lib/enumerable_ext_spec.rb
abstractivator-0.0.20 spec/lib/enumerable_ext_spec.rb
abstractivator-0.0.19 spec/lib/enumerable_ext_spec.rb
abstractivator-0.0.18 spec/lib/enumerable_ext_spec.rb
abstractivator-0.0.16 spec/lib/enumerable_ext_spec.rb
abstractivator-0.0.15 spec/lib/enumerable_ext_spec.rb