doubly_linked_list 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ODEyNmFlMjQ3ZjYwZWVlNTZjZjgzMTk4NWZkNzYyMDc0ZjVkNjE3NA==
5
- data.tar.gz: !binary |-
6
- YWZlOWQ1Mzk2NTkyNDUzMTVhYzE3M2QzODhjMTk4MjgxODBkZjU1OQ==
2
+ SHA1:
3
+ metadata.gz: cd01a06702ae377d5190ddda0b1fc080f713cbdb
4
+ data.tar.gz: dfd144070ace491c819c55047734cb91058a2348
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- M2M0NTUxNzc4ZTMxMmY5Njk3Mjk1MmRiYWMyNDEyMzlhYmVjNmIzMGMwMGYy
10
- ZjhjZmI2ZDVjMjdkYjk2ZTY4YmQ0YjA2Y2Q4MTIwMTI3OTNkOGUwZjViNDNj
11
- NTM5MTViYTM0YWI4ZGNhNDMwNjYyNzg1ZjY5ODFjNDZlYWNkNzk=
12
- data.tar.gz: !binary |-
13
- NjkyMzcwY2Q1NTg4NTg2OTdjMjUwZGM4YmRkMjA0YzM4ZGE3ZGZlOWNlZjhh
14
- OWU0YmE3OGYwZGY4MjE2ZTgxNjM5NjE3NmFhMmQxNWMwMjE3NjRhZjE4Y2Y5
15
- NGE4YjI0OTEyYzE4ZDgxNzg2OTdmNjRjZGQyODE5MjAyOTZhYjQ=
6
+ metadata.gz: ab08e7e1cde305e1dab14aca6f6b700f1407e02755ea7fe575828017f5fbd56a4e71276a9370ae4d66cf40b6cb5ff5f3978141acd3fb4ddb12f2e3ba23654411
7
+ data.tar.gz: f1a841166ebe687f5a25103cb4d8a873dee728eb2dab6734242b2810bc11233e6edf5ec5ae7e76211ecfd78b3aaec766fe87730f52efd2c82f6861087cfbfc26
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Build Status](https://travis-ci.org/elrayle/doubly_linked_list.png?branch=master)](https://travis-ci.org/elrayle/doubly_linked_list)
4
4
  [![Coverage Status](https://coveralls.io/repos/elrayle/doubly_linked_list/badge.png?branch=master)](https://coveralls.io/r/elrayle/doubly_linked_list?branch=master)
5
5
  [![Gem Version](https://badge.fury.io/rb/doubly_linked_list.svg)](http://badge.fury.io/rb/doubly_linked_list)
6
- [![Dependency Status](https://www.versioneye.com/ruby/doubly_linked_list/0.0.4/badge.svg)](https://www.versioneye.com/ruby/doubly_linked_list/0.0.4)
6
+ [![Dependency Status](https://www.versioneye.com/ruby/doubly_linked_list/0.0.2/badge.svg)](https://www.versioneye.com/ruby/doubly_linked_list/0.0.2)
7
7
 
8
8
 
9
9
  Ruby implementation of doubly linked list, following some Ruby idioms.
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'doubly_linked_list'
7
- spec.version = '0.0.2'
7
+ spec.version = '0.0.4'
8
8
  spec.authors = ["E. Lynette Rayle"]
9
9
  spec.email = ["elr37@cornell.edu"]
10
10
  spec.platform = Gem::Platform::RUBY
@@ -86,18 +86,6 @@ class DoublyLinkedList
86
86
  @list.delete_at(head)
87
87
  end
88
88
 
89
- ##
90
- # Iterates over nodes from top to bottom passing node data to the block if
91
- # given. If no block given, returns +Enumerator+.
92
- #
93
- # @returns +Enumerator+ or yields data to the block stored in every node on the
94
- # list.
95
- #
96
- def each
97
- return to_enum(__callee__) unless block_given?
98
- __each { |node| yield(node.data) }
99
- end
100
-
101
89
  # Returns list array without list info.
102
90
  #
103
91
  def to_a
@@ -106,10 +94,11 @@ class DoublyLinkedList
106
94
  alias_method :to_ary, :to_a
107
95
 
108
96
  # Passing all missing methods to the list so all array operations can be performed.
109
- def method_missing method_id, *args
110
- # binding.pry
97
+ def method_missing method_id, *args, &block
111
98
  begin
112
- return @list.send(method_id,*args)
99
+ return @list.send(method_id,*args, &block) if @list.respond_to?(method_id)
100
+ return @list_info.send(method_id,*args,&block) if @list_info.respond_to?(method_id)
101
+ super
113
102
  rescue
114
103
  super
115
104
  end
@@ -119,16 +108,7 @@ class DoublyLinkedList
119
108
  sprintf('#<%s:%#x %s>', self.class, self.__id__, to_a.inspect)
120
109
  end
121
110
 
122
- # # Conversion function, see +Conversions.List+.
123
- # #
124
- # # == Returns:
125
- # # +self+
126
- # #
127
- # def to_list
128
- # self
129
- # end
130
-
131
- private
111
+ private
132
112
 
133
113
  def head
134
114
  @list && @list.size > 0 ? 0 : nil
@@ -137,12 +117,4 @@ class DoublyLinkedList
137
117
  def tail
138
118
  @list && @list.size > 0 ? @list.size-1 : nil
139
119
  end
140
-
141
- def __each
142
- curr_node = @head
143
- while(curr_node)
144
- yield curr_node
145
- curr_node = curr_node.next
146
- end
147
- end
148
120
  end
@@ -199,4 +199,132 @@ describe 'DoublyLinkedList' do
199
199
  end
200
200
  end
201
201
 
202
+ describe '#missing_method' do
203
+ before do
204
+ class Dummy
205
+ def hello
206
+ "hello back at you"
207
+ end
208
+ def size
209
+ "very large indeed"
210
+ end
211
+ end
212
+ end
213
+
214
+ context "when list responds to missing method" do
215
+ it "should pass method to list and succeed" do
216
+ l = DoublyLinkedList.new :items => ['cat','dog','rabbit','fish'], :list_info => Dummy.new
217
+ expect(l.values_at(1..2)).to eq ['dog','rabbit']
218
+ expect(l.sort).to eq ['cat','dog','fish','rabbit']
219
+ end
220
+
221
+ it "should pass method to list only even if list_info has the same method and succeed" do
222
+ l = DoublyLinkedList.new :items => ['cat','dog','rabbit','fish'], :list_info => Dummy.new
223
+ expect(l.size).to eq 4
224
+ end
225
+
226
+ it "should pass method each to the list" do
227
+ l = DoublyLinkedList.new :items => ['cat','dog','rabbit','fish'], :list_info => Dummy.new
228
+ a = []
229
+ l.each do |i|
230
+ a << i
231
+ expect(l.to_a).to include i
232
+ end
233
+ expect(a).to eq ['cat','dog','rabbit','fish']
234
+ end
235
+
236
+ it "should pass method each to the list when block is inline" do
237
+ l = DoublyLinkedList.new :items => ['cat','dog','rabbit','fish'], :list_info => Dummy.new
238
+ a = []
239
+ l.each { |i| a<<i; expect(l.to_a).to include i }
240
+ expect(a).to eq ['cat','dog','rabbit','fish']
241
+ end
242
+ end
243
+
244
+ context "when list does not respond to missing method" do
245
+ it "should pass method to list_info and succeed if list_info responds to that method" do
246
+ l = DoublyLinkedList.new :items => ['cat','dog','rabbit','fish'], :list_info => Dummy.new
247
+ expect(l.hello).to eq 'hello back at you'
248
+ end
249
+
250
+ it "should not pass array method to list_info when @list is empty and succeed if list_info responds to that method" do
251
+ l = DoublyLinkedList.new :list_info => Dummy.new
252
+ expect(l.size).not_to eq 'very large indeed'
253
+ expect(l.size).to eq 0
254
+ end
255
+ end
256
+
257
+ context "when neither list nor list_info respond to missing method" do
258
+ it "should raise an error if it is not an array method nor list_info method" do
259
+ l = DoublyLinkedList.new :items => ['cat','dog','rabbit','fish'], :list_info => Dummy.new
260
+ expect{ l.foo }.to raise_error(NoMethodError, /undefined method `foo'/)
261
+ end
262
+ end
263
+ end
264
+
265
+ describe '#inspect' do
266
+ it "should return class and items" do
267
+ l = DoublyLinkedList.new :items => ['cat','dog','rabbit']
268
+ expect(l.inspect).to match /#<DoublyLinkedList:0x(\d|[abcdef])* \[\"cat\", \"dog\", \"rabbit\"\]/
269
+ end
270
+ end
271
+
272
+ describe "Array" do
273
+ describe "#move" do
274
+ it "should move an element to first position" do
275
+ a = [1,2,3,4,5,6,7,8,9,10]
276
+ expect(a.move(4,0)).to eq [5,1,2,3,4,6,7,8,9,10]
277
+ end
278
+
279
+ it "should move an element to last position" do
280
+ a = [1,2,3,4,5,6,7,8,9,10]
281
+ expect(a.move(5,9)).to eq [1,2,3,4,5,7,8,9,10,6]
282
+ end
283
+
284
+ it "should move an element from first to middle position" do
285
+ a = [1,2,3,4,5,6,7,8,9,10]
286
+ expect(a.move(0,4)).to eq [2,3,4,5,1,6,7,8,9,10]
287
+ end
288
+
289
+ it "should move an element from last to middle position" do
290
+ a = [1,2,3,4,5,6,7,8,9,10]
291
+ expect(a.move(9,4)).to eq [1,2,3,4,10,5,6,7,8,9]
292
+ end
293
+
294
+ it "should move an element forward from middle" do
295
+ a = [1,2,3,4,5,6,7,8,9,10]
296
+ expect(a.move(3,6)).to eq [1,2,3,5,6,7,4,8,9,10]
297
+ end
298
+
299
+ it "should move an element backward from middle" do
300
+ a = [1,2,3,4,5,6,7,8,9,10]
301
+ expect(a.move(6,3)).to eq [1,2,3,7,4,5,6,8,9,10]
302
+ end
303
+
304
+ it "should move an element beyond end of list" do
305
+ a = [1,2,3,4,5,6,7,8,9,10]
306
+ expect(a.move(6,12)).to eq [1,2,3,4,5,6,8,9,10,nil,nil,nil,7]
307
+ end
308
+
309
+ it "should move an element counting from right when 'from' is negative" do
310
+ a = [1,2,3,4,5,6,7,8,9,10]
311
+ expect(a.move(-3,2)).to eq [1,2,8,3,4,5,6,7,9,10]
312
+ end
313
+
314
+ it "should move an element counting to position counting from right when 'to' is negative" do
315
+ a = [1,2,3,4,5,6,7,8,9,10]
316
+ expect(a.move(2,-3)).to eq [1,2,4,5,6,7,8,3,9,10]
317
+ end
318
+
319
+ it "should add nil at 'to' position if 'from' negative number exceeds size" do
320
+ a = [1,2,3,4,5,6,7,8,9,10]
321
+ expect(a.move(-20,3)).to eq [1,2,3,nil,4,5,6,7,8,9,10]
322
+ end
323
+
324
+ it "should raise error if 'to' negative number exceeds size" do
325
+ a = [1,2,3,4,5,6,7,8,9,10]
326
+ expect{ a.move(3,-20) }.to raise_error(IndexError,'index -19 too small for array; minimum: -9')
327
+ end
328
+ end
329
+ end
202
330
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doubly_linked_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - E. Lynette Rayle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-17 00:00:00.000000000 Z
11
+ date: 2015-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
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: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rdoc
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
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: coveralls
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: Ruby implementation of doubly_linked_lists using an array to hold and
@@ -76,9 +76,9 @@ extra_rdoc_files:
76
76
  - LICENSE.txt
77
77
  - README.md
78
78
  files:
79
- - .coveralls.yml
80
- - .gitignore
81
- - .travis.yml
79
+ - ".coveralls.yml"
80
+ - ".gitignore"
81
+ - ".travis.yml"
82
82
  - Gemfile
83
83
  - LICENSE.txt
84
84
  - README.md
@@ -97,12 +97,12 @@ require_paths:
97
97
  - lib
98
98
  required_ruby_version: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - ! '>='
100
+ - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: 1.9.3
103
103
  required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  requirements:
105
- - - ! '>='
105
+ - - ">="
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  requirements: []