stable_sort 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d61b6a670323dd69a4a5459e5f8f609200d0a9ac
4
- data.tar.gz: e18748c4c9c95857df1605d20cd761f32a26b0f7
3
+ metadata.gz: 777ec400327e086d13b80a9fd42efb92f9c64c63
4
+ data.tar.gz: 5463c4a22c1af3935b72f60cce1672527cb7ef7d
5
5
  SHA512:
6
- metadata.gz: 6d4c3b319970536c3a87cd08f34c6ecf100350e58f1ef9210384ca7fc0a446ee3600e0d3cbe18179d71add22dcd6b9ad45e32d0b67206e91f7bbcaf650dd6da2
7
- data.tar.gz: 5a8a389481407b91ab209b5aa18bcced4afb7548f498e6008f9d3e02238ff7bf8f3b62a5d5a9c8e4ebcbfa70845269d31286e2e41c38c20dbe2f8498cdb1c1b4
6
+ metadata.gz: 9115952988e5392c3c650a7848a5654b964d6cffed2ea30bc99f5ca3cce314e21e1363117935c6fd2aa491a6164ed715d8583a30b6405343603bb791f968dfb6
7
+ data.tar.gz: 49ebe196275b69f3d92402fd12f0ed3d04dd361eff6bed572ff9097557e36f929fba98a6b53bcf935015febbe5dd964fdb21d94b53ead19ad2849c4e83fd7a83
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # StableSort
1
+ # StableSort [![Build Status](https://travis-ci.org/awakia/ruby_stable_sort.png)](https://travis-ci.org/awakia/ruby_stable_sort)
2
2
 
3
- TODO: Write a gem description
3
+ Add `stable_sort` and `stable_sort_by` to Array and Enumerator.
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,33 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ stable_sort
22
+
23
+ ```
24
+ KeyValue = Struct.new(:key, :value) do
25
+ def <=> (other)
26
+ self.key <=> other.key
27
+ end
28
+ end
29
+
30
+ [KeyValue.new(1, 1), KeyValue.new(1, 2), KeyValue.new(1, 3), KeyValue.new(1, 4), KeyValue.new(0, 10)].sort
31
+ # => [#<struct KeyValue key=0, value=10>, #<struct KeyValue key=1, value=3>, #<struct KeyValue key=1, value=2>, #<struct KeyValue key=1, value=4>, #<struct KeyValue key=1, value=1>]
32
+
33
+ [KeyValue.new(1, 1), KeyValue.new(1, 2), KeyValue.new(1, 3), KeyValue.new(1, 4), KeyValue.new(0, 10)].stable_sort
34
+ # => [#<struct KeyValue key=0, value=10>, #<struct KeyValue key=1, value=1>, #<struct KeyValue key=1, value=2>, #<struct KeyValue key=1, value=3>, #<struct KeyValue key=1, value=4>]
35
+ ```
36
+
37
+ stable_sort_by
38
+
39
+ ```
40
+ ['a', 'c', 'bd', 'fe', 'b'].sort_by { |x| x.length }
41
+ # => ["a", "c", "b", "fe", "bd"]
42
+
43
+ ['a', 'c', 'bd', 'fe', 'b'].stable_sort_by { |x| x.length }
44
+ # => ["a", "c", "b", "bd", "fe"]
45
+ ```
46
+
47
+ Currently, stable_sort gem do not take block. If you needed, please send a pull request :)
22
48
 
23
49
  ## Contributing
24
50
 
@@ -1,3 +1,3 @@
1
1
  module StableSort
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -1,6 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Array do
4
+ KeyValue = Struct.new(:key, :value) do
5
+ def <=> (other)
6
+ self.key <=> other.key
7
+ end
8
+ end
9
+
10
+ let (:array) { [KeyValue.new(1, 1), KeyValue.new(1, 2), KeyValue.new(1, 3), KeyValue.new(1, 4), KeyValue.new(0, 10)] }
11
+ let (:expect) { [KeyValue.new(0, 10), KeyValue.new(1, 1), KeyValue.new(1, 2), KeyValue.new(1, 3), KeyValue.new(1, 4)] }
12
+
4
13
  describe "#stable_sort_by" do
5
14
  it 'sorts stably' do
6
15
  ['a', 'c', 'bd', 'fe', 'b'].sort_by { |x| x.length }.should_not eq ['a', 'c', 'b', 'bd', 'fe']
@@ -17,16 +26,16 @@ describe Array do
17
26
  end
18
27
 
19
28
  describe "#stable_sort" do
20
- it 'sorts' do
21
- ['a', 'c', 'bd', 'fe', 'b'].stable_sort.should eq ['a', 'b', 'bd', 'c', 'fe']
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
22
32
  end
23
33
  end
24
34
 
25
35
  describe "#stable_sort!" do
26
- it 'sorts' do
27
- arr = ['a', 'c', 'bd', 'fe', 'b']
28
- arr.stable_sort!.should eq ['a', 'b', 'bd', 'c', 'fe']
29
- arr.should eq ['a', 'b', 'bd', 'c', 'fe']
36
+ it 'sorts stably' do
37
+ array.stable_sort!.to_s.should eq expect.to_s
38
+ array.to_s.should eq expect.to_s
30
39
  end
31
40
  end
32
41
  end
@@ -1,16 +1,26 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Enumerator do
4
+ KeyValue = Struct.new(:key, :value) do
5
+ def <=> (other)
6
+ self.key <=> other.key
7
+ end
8
+ end
9
+
10
+ let (:array) { [KeyValue.new(1, 1), KeyValue.new(1, 2), KeyValue.new(1, 3), KeyValue.new(1, 4), KeyValue.new(0, 10)] }
11
+ let (:expect) { [KeyValue.new(0, 10), KeyValue.new(1, 1), KeyValue.new(1, 2), KeyValue.new(1, 3), KeyValue.new(1, 4)] }
12
+
4
13
  describe "#stable_sort_by" do
5
14
  it 'sorts stably' do
6
- ['a', 'c', 'bd', 'fe', 'b'].each.sort_by { |x| x.length }.should_not eq ['a', 'c', 'b', 'bd', 'fe'].each
15
+ ['a', 'c', 'bd', 'fe', 'b'].each.sort_by { |x| x.length }.should eq ['a', 'c', 'b', 'fe', 'bd']
7
16
  ['a', 'c', 'bd', 'fe', 'b'].each.stable_sort_by { |x| x.length }.should eq ['a', 'c', 'b', 'bd', 'fe']
8
17
  end
9
18
  end
10
19
 
11
20
  describe "#stable_sort" do
12
- it 'sorts' do
13
- ['a', 'c', 'bd', 'fe', 'b'].each.stable_sort.should eq ['a', 'b', 'bd', 'c', 'fe']
21
+ it 'sorts stably' do
22
+ array.each.sort.to_s.should_not eq expect.to_s
23
+ array.each.stable_sort.to_s.should eq expect.to_s
14
24
  end
15
25
  end
16
26
  end
data/stable_sort.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = StableSort::VERSION
9
9
  spec.authors = ["Naoyoshi Aikawa"]
10
10
  spec.email = ["n.aikawa91@gmail.com"]
11
- spec.description = %q{Add stable sort functionality}
11
+ spec.description = %q{Add stable sort functionality to ruby}
12
12
  spec.summary = %q{Add stable_sort and stable_sort_by to Array and Enumerator.}
13
13
  spec.homepage = "https://github.com/awakia/ruby_stable_sort"
14
14
  spec.license = "MIT"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stable_sort
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.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: 2013-12-19 00:00:00.000000000 Z
11
+ date: 2013-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: Add stable sort functionality
55
+ description: Add stable sort functionality to ruby
56
56
  email:
57
57
  - n.aikawa91@gmail.com
58
58
  executables: []