stable_sort 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/stable_sort.rb +1 -1
- data/lib/stable_sort/extension/array.rb +1 -9
- data/lib/stable_sort/extension/{enumerator.rb → enumerable.rb} +2 -2
- data/lib/stable_sort/version.rb +1 -1
- data/spec/extension/array_spec.rb +0 -14
- data/spec/extension/{enumrator_spec.rb → enumerable_spec.rb} +19 -3
- data/spec/spec_helper.rb +3 -0
- data/stable_sort.gemspec +1 -0
- metadata +31 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79ca6cc4ccfc6bc4fb05be043d633dac987b8709
|
4
|
+
data.tar.gz: 0dc38cf1bce379ebae924d53ae150a73d5ac31de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2223fe4c43564e4b7cfa51e20d48cec881de1ff9fda71eeb64b84897da90c39f7bb2703d84c624c5e682e02cab3a688ef69a99de4f727134d31a5aaa2adaf5ea
|
7
|
+
data.tar.gz: 169a1480787c94ae22ec765b0b7d40b1940385f5c24d3d1366d4785e07c8a92b84ed24b6680827b998c13faf536139d93ba299d7f97c7d15e650421eebdb8130
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# StableSort [![Build Status](https://travis-ci.org/awakia/ruby_stable_sort.png)](https://travis-ci.org/awakia/ruby_stable_sort)
|
1
|
+
# StableSort [![Build Status](https://travis-ci.org/awakia/ruby_stable_sort.png)](https://travis-ci.org/awakia/ruby_stable_sort) [![Coverage Status](https://coveralls.io/repos/awakia/ruby_stable_sort/badge.png)](https://coveralls.io/r/awakia/ruby_stable_sort)
|
2
2
|
|
3
3
|
Add `stable_sort` and `stable_sort_by` to Array and Enumerator.
|
4
4
|
|
data/lib/stable_sort.rb
CHANGED
@@ -1,16 +1,8 @@
|
|
1
1
|
class Array
|
2
|
-
def stable_sort_by
|
3
|
-
sort_by.with_index{ |e, index| [yield(e), index] }
|
4
|
-
end
|
5
|
-
|
6
2
|
def stable_sort_by!
|
3
|
+
return to_enum(:stable_sort_by!) if !block_given?
|
7
4
|
sort_by!.with_index{ |e, index| [yield(e), index] }
|
8
5
|
end
|
9
|
-
|
10
|
-
def stable_sort
|
11
|
-
stable_sort_by { |x| x }
|
12
|
-
end
|
13
|
-
|
14
6
|
def stable_sort!
|
15
7
|
stable_sort_by! { |x| x }
|
16
8
|
end
|
data/lib/stable_sort/version.rb
CHANGED
@@ -10,13 +10,6 @@ describe Array do
|
|
10
10
|
let (:array) { [KeyValue.new(1, 1), KeyValue.new(1, 2), KeyValue.new(1, 3), KeyValue.new(1, 4), KeyValue.new(0, 10)] }
|
11
11
|
let (:expect) { [KeyValue.new(0, 10), KeyValue.new(1, 1), KeyValue.new(1, 2), KeyValue.new(1, 3), KeyValue.new(1, 4)] }
|
12
12
|
|
13
|
-
describe "#stable_sort_by" do
|
14
|
-
it 'sorts stably' do
|
15
|
-
['a', 'c', 'bd', 'fe', 'b'].sort_by { |x| x.length }.should_not eq ['a', 'c', 'b', 'bd', 'fe']
|
16
|
-
['a', 'c', 'bd', 'fe', 'b'].stable_sort_by { |x| x.length }.should eq ['a', 'c', 'b', 'bd', 'fe']
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
13
|
describe "#stable_sort_by!" do
|
21
14
|
it 'sorts stably' do
|
22
15
|
arr = ['a', 'c', 'bd', 'fe', 'b']
|
@@ -25,13 +18,6 @@ describe Array do
|
|
25
18
|
end
|
26
19
|
end
|
27
20
|
|
28
|
-
describe "#stable_sort" do
|
29
|
-
it 'sorts stably' do
|
30
|
-
array.sort.to_s.should_not eq expect.to_s
|
31
|
-
array.stable_sort.to_s.should eq expect.to_s
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
21
|
describe "#stable_sort!" do
|
36
22
|
it 'sorts stably' do
|
37
23
|
array.stable_sort!.to_s.should eq expect.to_s
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Enumerable do
|
4
4
|
KeyValue = Struct.new(:key, :value) do
|
5
5
|
def <=> (other)
|
6
6
|
self.key <=> other.key
|
@@ -10,14 +10,30 @@ describe Enumerator do
|
|
10
10
|
let (:array) { [KeyValue.new(1, 1), KeyValue.new(1, 2), KeyValue.new(1, 3), KeyValue.new(1, 4), KeyValue.new(0, 10)] }
|
11
11
|
let (:expect) { [KeyValue.new(0, 10), KeyValue.new(1, 1), KeyValue.new(1, 2), KeyValue.new(1, 3), KeyValue.new(1, 4)] }
|
12
12
|
|
13
|
-
describe "#stable_sort_by" do
|
13
|
+
describe "#stable_sort_by (Array)" do
|
14
|
+
it 'sorts stably' do
|
15
|
+
['a', 'c', 'bd', 'fe', 'b'].sort_by { |x| x.length }.should_not eq ['a', 'c', 'b', 'bd', 'fe']
|
16
|
+
['a', 'c', 'bd', 'fe', 'b'].stable_sort_by { |x| x.length }.should eq ['a', 'c', 'b', 'bd', 'fe']
|
17
|
+
['a', 'c', 'bd', 'fe', 'b'].stable_sort_by.is_a?(Enumerator).should be_true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#stable_sort_by (Enumerator)" do
|
14
22
|
it 'sorts stably' do
|
15
23
|
['a', 'c', 'bd', 'fe', 'b'].each.sort_by { |x| x.length }.should eq ['a', 'c', 'b', 'fe', 'bd']
|
16
24
|
['a', 'c', 'bd', 'fe', 'b'].each.stable_sort_by { |x| x.length }.should eq ['a', 'c', 'b', 'bd', 'fe']
|
25
|
+
['a', 'c', 'bd', 'fe', 'b'].each.stable_sort_by.is_a?(Enumerator).should be_true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#stable_sort (Array)" do
|
30
|
+
it 'sorts stably' do
|
31
|
+
array.sort.to_s.should_not eq expect.to_s
|
32
|
+
array.stable_sort.to_s.should eq expect.to_s
|
17
33
|
end
|
18
34
|
end
|
19
35
|
|
20
|
-
describe "#stable_sort" do
|
36
|
+
describe "#stable_sort (Enumerator)" do
|
21
37
|
it 'sorts stably' do
|
22
38
|
array.each.sort.to_s.should_not eq expect.to_s
|
23
39
|
array.each.stable_sort.to_s.should eq expect.to_s
|
data/spec/spec_helper.rb
CHANGED
data/stable_sort.gemspec
CHANGED
metadata
CHANGED
@@ -1,55 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stable_sort
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naoyoshi Aikawa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
69
|
description: Add stable sort functionality to ruby
|
@@ -59,19 +73,19 @@ executables: []
|
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
62
|
-
- .gitignore
|
63
|
-
- .rspec
|
64
|
-
- .travis.yml
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
65
79
|
- Gemfile
|
66
80
|
- LICENSE.txt
|
67
81
|
- README.md
|
68
82
|
- Rakefile
|
69
83
|
- lib/stable_sort.rb
|
70
84
|
- lib/stable_sort/extension/array.rb
|
71
|
-
- lib/stable_sort/extension/
|
85
|
+
- lib/stable_sort/extension/enumerable.rb
|
72
86
|
- lib/stable_sort/version.rb
|
73
87
|
- spec/extension/array_spec.rb
|
74
|
-
- spec/extension/
|
88
|
+
- spec/extension/enumerable_spec.rb
|
75
89
|
- spec/spec_helper.rb
|
76
90
|
- spec/stable_sort_spec.rb
|
77
91
|
- stable_sort.gemspec
|
@@ -85,23 +99,23 @@ require_paths:
|
|
85
99
|
- lib
|
86
100
|
required_ruby_version: !ruby/object:Gem::Requirement
|
87
101
|
requirements:
|
88
|
-
- -
|
102
|
+
- - ">="
|
89
103
|
- !ruby/object:Gem::Version
|
90
104
|
version: '0'
|
91
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
106
|
requirements:
|
93
|
-
- -
|
107
|
+
- - ">="
|
94
108
|
- !ruby/object:Gem::Version
|
95
109
|
version: '0'
|
96
110
|
requirements: []
|
97
111
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.
|
112
|
+
rubygems_version: 2.2.2
|
99
113
|
signing_key:
|
100
114
|
specification_version: 4
|
101
115
|
summary: Add stable_sort and stable_sort_by to Array and Enumerator.
|
102
116
|
test_files:
|
103
117
|
- spec/extension/array_spec.rb
|
104
|
-
- spec/extension/
|
118
|
+
- spec/extension/enumerable_spec.rb
|
105
119
|
- spec/spec_helper.rb
|
106
120
|
- spec/stable_sort_spec.rb
|
107
121
|
has_rdoc:
|