lazylist 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ 2005-12-05 * 0.2.1 * Fixed a documentation bug, reported by Gary Wright
2
+ <at2002@mac.com>.
3
+ * enable/disable index reference cache added.
4
+ * LazyList#sublist added to generate sublists that
5
+ share elements with their "super" lists.
1
6
  2005-10-08 * 0.2.0 * Lots of changes (without backwards compatibility):
2
7
  - Now the usual methods from the Ruby Enumerable module
3
8
  should be much better supported.
data/README.en CHANGED
@@ -9,7 +9,7 @@ Documentation
9
9
  =============
10
10
 
11
11
  The API documentatin of this library is can be produced by typing:
12
- $ ruby makedoc.rb
12
+ $ ruby make_doc.rb
13
13
 
14
14
  You should also look into the files in the examples directory to get an idea
15
15
  how this library is used. It is also interesting to examine test.rb for this
data/Rakefile CHANGED
@@ -5,12 +5,12 @@ include Config
5
5
 
6
6
  PKG_NAME = 'lazylist'
7
7
  PKG_VERSION = File.read('VERSION').chomp
8
- PKG_FILES = Dir.glob("**/*").delete_if { |item|
9
- item.include?("CVS") or item.include?("pkg")
10
- }
8
+ PKG_FILES = FileList['**/*'].exclude(/^doc/).exclude(/^CVS/).exclude(/^pkg/)
9
+
10
+ task :default => :test
11
11
 
12
12
  desc "Run unit tests"
13
- task(:test) do
13
+ task :test do
14
14
  cd 'tests' do
15
15
  ruby %{-I../ext runner.rb}
16
16
  end
@@ -26,6 +26,12 @@ task :doc do
26
26
  ruby 'make_doc.rb'
27
27
  end
28
28
 
29
+ desc "Removing generated files"
30
+ task :clean do
31
+ rm_rf 'doc'
32
+ rm_rf 'tests/coverage'
33
+ end
34
+
29
35
  spec = Gem::Specification.new do |s|
30
36
  #### Basic information.
31
37
 
@@ -57,11 +63,11 @@ spec = Gem::Specification.new do |s|
57
63
  #### Documentation and testing.
58
64
 
59
65
  s.has_rdoc = true
60
- #s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
61
- #s.rdoc_options <<
62
- # '--title' << 'Rake -- Ruby Make' <<
63
- # '--main' << 'README' <<
64
- # '--line-numbers'
66
+ s.extra_rdoc_files = [ 'lib/lazylist.rb' ]
67
+ s.rdoc_options <<
68
+ '--title' << 'LazyList -- Infinite lists in Ruby' <<
69
+ '--main' << 'LazyList' <<
70
+ '--line-numbers'
65
71
  s.test_files << 'tests/test.rb'
66
72
 
67
73
  #### Author and project details.
@@ -76,4 +82,6 @@ Rake::GemPackageTask.new(spec) do |pkg|
76
82
  pkg.need_tar = true
77
83
  pkg.package_files += PKG_FILES
78
84
  end
85
+
86
+ task :release => [ :clean, :package ]
79
87
  # vim: set et sw=2 ts=2:
data/TODO CHANGED
@@ -1,4 +1,5 @@
1
1
  * adding better support for finite lazy lists
2
+ * make lists even
2
3
  * this stuff
3
4
  # XXX
4
5
  def append(*elements)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -1,4 +1,6 @@
1
1
  require 'lazylist'
2
+ $:.unshift 'examples'
3
+ require 'pi'
2
4
 
3
5
  puts "Random number lazy list (infinite)"
4
6
  def rand(s = 666)
@@ -66,4 +68,15 @@ me = LazyList[File.new($0)]
66
68
  me.each(6) { |line| puts line }
67
69
  p me[66]
68
70
  puts me.length
71
+ puts
72
+
73
+ puts "Proof that PI is the number of the beast"
74
+ p PI.take(10)
75
+
76
+ def window(l, n, m = 0)
77
+ list([ l.take(n) * '', m ]) { window(l.drop, n, m + 1) }
78
+ end
79
+ w = window(PI, 3)
80
+ index = w.find { |(x, i)| x == '666' and break i }
81
+ puts "Found #{PI.take_span(index, 3)} at #{index}!"
69
82
  # vim: set et sw=2 ts=2:
@@ -104,10 +104,10 @@ class LazyList
104
104
  # list for which the block evaluates to true, the second containing the
105
105
  # rest.
106
106
  def partition(&block)
107
- accepted, rejected = to_a.partition(&block)
108
- return LazyList.from_enum(accepted), LazyList.from_enum(rejected)
107
+ return select(&block), reject(&block)
109
108
  end
110
109
 
110
+
111
111
  # Returns a sorted version of this lazy list. This method should only be
112
112
  # called on finite lazy lists or it will never return. Also see
113
113
  # Enumerable#sort.
@@ -263,6 +263,7 @@ class LazyList
263
263
  # Creates a new LazyList element. The tail can be given either as
264
264
  # second argument or as block.
265
265
  def initialize(head, tail = nil, &promise)
266
+ @cached = true
266
267
  @ref_cache = {}
267
268
  if tail
268
269
  promise and
@@ -274,6 +275,17 @@ class LazyList
274
275
  end
275
276
  end
276
277
 
278
+ # Set this to false, if index references into the lazy list shouldn't be
279
+ # cached for fast access (while spending some memory on this). This value
280
+ # defaults to true.
281
+ attr_writer :cached
282
+
283
+ # Returns true, if index references into the lazy list are cached for fast
284
+ # access to the referenceѕ elements.
285
+ def cached?
286
+ !!@cached
287
+ end
288
+
277
289
  # Denotes the empty LazyList which is a guard at the end of finite
278
290
  # lazy lists.
279
291
  Empty = new(nil, nil)
@@ -303,8 +315,8 @@ class LazyList
303
315
  # Identity lambda expression, mostly used as a default.
304
316
  Identity = lambda { |x| x }
305
317
 
306
- # Returns a lazy list which is generated by LazyList.from_enum or
307
- # LazyList.span.
318
+ # Returns a lazy list which is generated from the Enumerable a or
319
+ # LazyList.span(a, n), if n was given as an argument.
308
320
  def self.[](a, n = nil)
309
321
  case
310
322
  when n
@@ -371,6 +383,48 @@ class LazyList
371
383
  end
372
384
  end
373
385
 
386
+ # Returns the sublist, constructed from the Range _range_ indexed elements,
387
+ # of this lazy list.
388
+ def sublist_range(range)
389
+ f = range.first
390
+ l = range.exclude_end? ? range.last - 1 : range.last
391
+ sublist_span(f, l - f + 1)
392
+ end
393
+
394
+ # Returns the sublist, that spans _m_ elements starting from the _n_-th
395
+ # element of this lazy list, if _m_ was given. If _m_ is non­positive, the
396
+ # empty lazy list LazyList::Empty is returned.
397
+ #
398
+ # If _m_ wasn't given returns the _n_ long sublist starting from the first
399
+ # (index = 0) element. If _n_ is non­positive, the empty lazy list
400
+ # LazyList::Empty is returned.
401
+ def sublist_span(n, m = nil)
402
+ if not m
403
+ sublist_span(0, n)
404
+ elsif m > 0
405
+ l = ref(n)
406
+ self.class.new(l.head) { l.tail.sublist_span(0, m - 1) }
407
+ else
408
+ Empty
409
+ end
410
+ end
411
+
412
+ # Returns the result of sublist_range(n), if _n_ is a Range. The result of
413
+ # sublist_span(n, m), if otherwise.
414
+ def sublist(n, m = nil)
415
+ if n.is_a? Range
416
+ sublist_range(n)
417
+ else
418
+ sublist_span(n, m)
419
+ end
420
+ end
421
+
422
+ def set_ref(n, value)
423
+ return value unless cached?
424
+ @ref_cache[n] = value
425
+ end
426
+ private :set_ref
427
+
374
428
  # Returns the n-th LazyList-Object.
375
429
  def ref(n)
376
430
  if @ref_cache.key?(n)
@@ -380,12 +434,12 @@ class LazyList
380
434
  i = n
381
435
  while i > 0 do
382
436
  if s.empty?
383
- return @ref_cache[n] = nil
437
+ return set_ref(n, self)
384
438
  end
385
439
  s = s.tail
386
440
  i -= 1
387
441
  end
388
- @ref_cache[n] = s
442
+ set_ref(n, s)
389
443
  end
390
444
  private :ref
391
445
 
@@ -395,13 +449,13 @@ class LazyList
395
449
  # returned.
396
450
  def [](n, m = nil)
397
451
  if n.is_a? Range
398
- LazyList[take_range(n)]
452
+ sublist(n)
399
453
  elsif n < 0
400
454
  nil
401
455
  elsif m
402
- LazyList[take_span(n, m)]
456
+ sublist(n, m)
403
457
  else
404
- ref(n).head rescue nil
458
+ ref(n).head
405
459
  end
406
460
  end
407
461
 
@@ -6,7 +6,7 @@ $:.unshift File.expand_path(File.dirname($0))
6
6
  $:.unshift 'lib'
7
7
  $:.unshift '../lib'
8
8
  begin
9
- #require 'coverage'
9
+ require 'coverage'
10
10
  rescue LoadError
11
11
  end
12
12
  require 'test'
@@ -51,121 +51,144 @@ class TC_LazyList < Test::Unit::TestCase
51
51
  @read_queue1 = LazyList::ReadQueue.new(1..1)
52
52
  @read_queue10 = LazyList::ReadQueue.new(1..10)
53
53
  assert(@read_queue0.empty?)
54
- assert_equal(nil, @read_queue0.pop)
54
+ assert_equal nil, @read_queue0.pop
55
55
  assert(!@read_queue1.empty?)
56
- assert_equal(1, @read_queue1.pop)
56
+ assert_equal 1, @read_queue1.pop
57
57
  assert(!@read_queue10.empty?)
58
58
  for i in 1..10 do
59
- assert_equal(i, @read_queue10.pop)
59
+ assert_equal i, @read_queue10.pop
60
60
  end
61
61
  end
62
62
 
63
63
  def test_finite
64
- assert_equal(@finite_inner0.to_a, @finite0.to_a)
65
- assert_equal(@finite_inner1.to_a, @finite1.to_a)
66
- assert_equal(@finite_inner10.to_a, @finite10.to_a)
67
- assert_equal(@finite_span_generated, @finite_span.to_a)
64
+ assert_equal @finite_inner0.to_a, @finite0.to_a
65
+ assert_equal @finite_inner1.to_a, @finite1.to_a
66
+ assert_equal @finite_inner10.to_a, @finite10.to_a
67
+ assert_equal @finite_span_generated, @finite_span.to_a
68
68
  end
69
69
 
70
70
  def test_size
71
- assert_equal(0, @finite0.size)
72
- assert_equal(1, @finite1.size)
73
- assert_equal(10, @finite10.size)
74
- assert_equal(10, @finite_span.size)
75
- assert_equal(0, @finite0.length)
76
- assert_equal(1, @finite1.length)
77
- assert_equal(10, @finite10.length)
78
- assert_equal(10, @finite_span.length)
71
+ assert_equal 0, @finite0.size
72
+ assert_equal 1, @finite1.size
73
+ assert_equal 10, @finite10.size
74
+ assert_equal 10, @finite_span.size
75
+ assert_equal 0, @finite0.length
76
+ assert_equal 1, @finite1.length
77
+ assert_equal 10, @finite10.length
78
+ assert_equal 10, @finite_span.length
79
79
  end
80
80
 
81
81
  def test_select
82
- assert_equal(1, @odd[0])
83
- assert_equal(3, @odd[1])
84
- assert_equal(5, @odd[2])
85
- assert_equal((1..19).select(&@oddp), @odd[0, 10].to_a)
86
- assert_equal((1..10).to_a, @natural[0, 10].to_a)
87
- assert_equal([ 1 ] * 10, @ones[0, 10].to_a)
82
+ assert_equal 1, @odd[0]
83
+ assert_equal 3, @odd[1]
84
+ assert_equal 5, @odd[2]
85
+ assert_equal (1..19).select(&@oddp), @odd[0, 10].to_a
86
+ assert_equal (1..10).to_a, @natural[0, 10].to_a
87
+ assert_equal [ 1 ] * 10, @ones[0, 10].to_a
88
88
  ends_with_a = @strings.select { |x| x[-1] == ?a }
89
- assert(ends_with_a[0, 27].to_a ==
90
- [ "a", ("a".."z").map { |x| x + "a" } ].flatten)
89
+ assert_equal ends_with_a[0, 27].to_a,
90
+ [ "a", ("a".."z").map { |x| x + "a" } ].flatten
91
91
  end
92
92
 
93
93
  def test_map
94
94
  id = @natural.map
95
- assert_equal(1, id[0])
96
- assert_equal(2, id[1])
97
- assert_equal(3, id[2])
98
- assert_equal((1..10).to_a, id[0, 10].to_a)
99
- assert_equal((1..10).to_a, @natural[0, 10].to_a)
95
+ assert_equal 1, id[0]
96
+ assert_equal 2, id[1]
97
+ assert_equal 3, id[2]
98
+ assert_equal (1..10).to_a, id[0, 10].to_a
99
+ assert_equal (1..10).to_a, @natural[0, 10].to_a
100
100
  squaredf = lambda { |x| x ** 2 }
101
101
  squared = @natural.map(&squaredf)
102
- assert_equal(1, squared[0])
103
- assert_equal(4, squared[1])
104
- assert_equal(9, squared[2])
105
- assert_equal((1..10).map(&squaredf), squared[0, 10].to_a)
106
- assert_equal((1..10).to_a, @natural[0, 10].to_a)
102
+ assert_equal 1, squared[0]
103
+ assert_equal 4, squared[1]
104
+ assert_equal 9, squared[2]
105
+ assert_equal (1..10).map(&squaredf), squared[0, 10].to_a
106
+ assert_equal (1..10).to_a, @natural[0, 10].to_a
107
107
  strangef = lambda { |x| x * (x[0] - ?a + 1) }
108
108
  strange = @strings.map(&strangef)
109
- assert_equal("a", strange[0])
110
- assert_equal("bb", strange[1])
111
- assert_equal("ccc", strange[2])
112
- assert_equal(("a".."z").map(&strangef), strange[0, 26].to_a)
113
- assert_equal(("a".."z").to_a, @strings[0, 26].to_a)
109
+ assert_equal "a", strange[0]
110
+ assert_equal "bb", strange[1]
111
+ assert_equal "ccc", strange[2]
112
+ assert_equal ("a".."z").map(&strangef), strange[0, 26].to_a
113
+ assert_equal ("a".."z").to_a, @strings[0, 26].to_a
114
114
  end
115
115
 
116
116
  def test_index
117
- assert_equal(nil, @natural[-1])
118
- assert_equal(1, @natural[0])
119
- assert_equal(2, @natural[1])
120
- assert_equal(nil, @natural[-1, 10])
121
- assert_equal(LazyList[1..10], @natural[0, 10])
122
- =begin
123
- assert_equal((6..15).to_a, @natural[5, 10])
124
- assert_equal((1..1).to_a, @natural[0..0])
125
- assert_equal((1..0).to_a, @natural[0..-1])
126
- assert_equal((1...1).to_a, @natural[0...0])
127
- assert_equal((1...0).to_a, @natural[0...-1])
128
- assert_equal((1..10).to_a, @natural[0..9])
129
- assert_equal((6..15).to_a, @natural[5..14])
130
- assert_equal((1..10).to_a, @natural[0...10])
131
- assert_equal((6..15).to_a, @natural[5...15])
132
- =end
117
+ assert_equal nil, LazyList::Empty[-1]
118
+ assert_equal nil, LazyList::Empty[0]
119
+ assert_equal nil, LazyList::Empty[1]
120
+ assert @natural.cached?
121
+ assert_equal nil, @natural[-1]
122
+ assert_equal nil, @natural[-1]
123
+ assert_equal 1, @natural[0]
124
+ assert_equal 1, @natural[0]
125
+ assert_equal 2, @natural[1]
126
+ assert_equal 2, @natural[1]
127
+ assert_equal nil, @natural[-1, 10]
128
+ assert_equal (1..10).to_a, @natural[0, 10].to_a
129
+ assert_equal (6..15).to_a, @natural[5, 10].to_a
130
+ assert_equal (1..1).to_a, @natural[0..0].to_a
131
+ assert_equal (1..0).to_a, @natural[0..-1].to_a
132
+ assert_equal (1...1).to_a, @natural[0...0].to_a
133
+ assert_equal (1...0).to_a, @natural[0...-1].to_a
134
+ assert_equal (1..10).to_a, @natural[0..9].to_a
135
+ assert_equal (6..15).to_a, @natural[5..14].to_a
136
+ assert_equal (1..10).to_a, @natural[0...10].to_a
137
+ assert_equal (6..15).to_a, @natural[5...15].to_a
138
+ end
139
+
140
+ def test_index_without_cache
141
+ LazyList::Empty.cached = false
142
+ assert_equal nil, LazyList::Empty[-1]
143
+ assert_equal nil, LazyList::Empty[0]
144
+ assert_equal nil, LazyList::Empty[1]
145
+ @natural.cached = false
146
+ assert !@natural.cached?
147
+ assert_equal nil, @natural[-1]
148
+ assert_equal nil, @natural[-1]
149
+ assert_equal 1, @natural[0]
150
+ assert_equal 1, @natural[0]
151
+ assert_equal 2, @natural[1]
152
+ assert_equal 2, @natural[1]
153
+ assert_equal nil, @natural[-1, 10]
133
154
  end
134
155
 
135
156
  def test_merge
136
157
  natural = @even.merge(@odd)
137
- assert_equal(@natural[0, 10].to_a, natural[0, 10].to_a)
158
+ assert_equal @natural[0, 10].to_a, natural[0, 10].to_a
138
159
  natural = @odd.merge(@even)
139
- assert_equal(@natural[0, 10].to_a, natural[0, 10].to_a)
160
+ assert_equal @natural[0, 10].to_a, natural[0, 10].to_a
140
161
  double_list = @natural.merge(@natural) { |a,b| a <= b }
141
- assert(double_list[0, 10].to_a, (1..5).map { |x| [x, x] }.flatten)
162
+ assert double_list[0, 10].to_a, (1..5).map { |x| [x, x] }.flatten
142
163
  odd2 = @natural.select(&@oddp).drop(1)
143
164
  some = @even.merge(odd2)
144
- assert_equal(@natural[1, 9].to_a, some[0, 9].to_a)
165
+ assert_equal @natural[1, 9].to_a, some[0, 9].to_a
166
+ more_ones = @ones.merge(@ones)
167
+ assert_equal [1] * 10, more_ones.take(10)
145
168
  end
146
169
 
147
170
  def test_take_drop
148
- assert_equal([ ], @odd.take(0))
149
- assert_equal([ 1, 3, 5 ], @odd.take(3))
150
- assert_equal([ 1, 3, 5 ], @odd.take(3))
151
- assert_equal([ ], @odd.take!(0))
152
- assert_equal([ 1 ], @odd.take(1))
153
- assert_equal([ 1 ], @odd.take!(1))
154
- assert_equal([ 3, 5, 7 ], @odd.take(3))
155
- assert_equal([ 3, 5 ], @odd.take!(2))
156
- assert_equal([ 7, 9, 11 ], @odd.take(3))
157
- assert_equal([ 7, 9, 11 ], @odd.drop(0).take(3))
158
- assert_equal([ 7, 9, 11 ], @odd.take(3))
159
- assert_equal([ 9, 11, 13 ], @odd.drop(1).take(3))
160
- assert_equal([ 7, 9, 11 ], @odd.take(3))
161
- assert_equal([ 11, 13, 15 ], @odd.drop(2).take(3))
162
- assert_equal([ 7, 9, 11 ], @odd.take(3))
171
+ assert_equal [ ], @odd.take(0)
172
+ assert_equal [ 1, 3, 5 ], @odd.take(3)
173
+ assert_equal [ 1, 3, 5 ], @odd.take(3)
174
+ assert_equal [ ], @odd.take!(0)
175
+ assert_equal [ 1 ], @odd.take(1)
176
+ assert_equal [ 1 ], @odd.take!(1)
177
+ assert_equal [ 3, 5, 7 ], @odd.take(3)
178
+ assert_equal [ 3, 5 ], @odd.take!(2)
179
+ assert_equal [ 7, 9, 11 ], @odd.take(3)
180
+ assert_equal [ 7, 9, 11 ], @odd.drop(0).take(3)
181
+ assert_equal [ 7, 9, 11 ], @odd.take(3)
182
+ assert_equal [ 9, 11, 13 ], @odd.drop(1).take(3)
183
+ assert_equal [ 7, 9, 11 ], @odd.take(3)
184
+ assert_equal [ 11, 13, 15 ], @odd.drop(2).take(3)
185
+ assert_equal [ 7, 9, 11 ], @odd.take(3)
163
186
  @odd.drop!(0)
164
- assert_equal([ 7, 9, 11 ], @odd.take(3))
187
+ assert_equal [ 7, 9, 11 ], @odd.take(3)
165
188
  @odd.drop!(1)
166
- assert_equal([ 9, 11, 13 ], @odd.take(3))
189
+ assert_equal [ 9, 11, 13 ], @odd.take(3)
167
190
  @odd.drop!(2)
168
- assert_equal([ 13, 15, 17 ], @odd.take(3))
191
+ assert_equal [ 13, 15, 17 ], @odd.take(3)
169
192
  end
170
193
 
171
194
  def test_io
@@ -181,21 +204,30 @@ class TC_LazyList < Test::Unit::TestCase
181
204
  end
182
205
  @tempfile10.close
183
206
  @tempfile10_list = LazyList[File.new(@tempfile10.path)]
184
- assert_equal(0, @tempfile0_list.size)
185
- assert_equal([], @tempfile0_list.to_a)
186
- assert_equal(10, @tempfile10_list.size)
187
- assert_equal((1..10).map { |x| x.to_s + "\n" },
188
- @tempfile10_list.to_a)
207
+ assert_equal 0, @tempfile0_list.size
208
+ assert_equal [], @tempfile0_list.to_a
209
+ assert_equal 10, @tempfile10_list.size
210
+ assert_equal (1..10).map { |x| x.to_s + "\n" },
211
+ @tempfile10_list.to_a
189
212
  temp = LazyList.io(File.new(@tempfile0.path)) do |io|
190
213
  io.readline
191
214
  end
192
215
  content = temp.inject([]) { |c, line| c << line }
193
- assert_equal([], content)
216
+ assert_equal [], content
194
217
  temp = LazyList.io(File.new(@tempfile10.path)) do |io|
195
218
  io.readline
196
219
  end
197
220
  content = temp.inject([]) { |c, line| c << line }
198
- assert_equal((1..10).map { |x| x.to_s + "\n" }, content)
221
+ assert_equal (1..10).map { |x| x.to_s + "\n" }, content
222
+ end
223
+
224
+ def test_construct_ref
225
+ assert_equal LazyList::Empty, LazyList[0, -1]
226
+ assert_equal [0], LazyList[0, 1].to_a
227
+ assert_equal (0..9).to_a, LazyList[0, 10].to_a
228
+ assert_equal LazyList::Empty, LazyList[0..-1]
229
+ assert_equal [0], LazyList[0..0].to_a
230
+ assert_equal (0..9).to_a, LazyList[0..9].to_a
199
231
  end
200
232
 
201
233
  def test_iterate
@@ -206,24 +238,24 @@ class TC_LazyList < Test::Unit::TestCase
206
238
  5 * x + 1
207
239
  end
208
240
  end
209
- assert_equal(nil, f[-1])
210
- assert_equal(5, f[0])
211
- assert_equal(26, f[1])
212
- assert_equal([5, 26, 13, 66, 33, 166, 83, 416], f[0, 8].to_a)
241
+ assert_equal nil, f[-1]
242
+ assert_equal 5, f[0]
243
+ assert_equal 26, f[1]
244
+ assert_equal [5, 26, 13, 66, 33, 166, 83, 416], f[0, 8].to_a
213
245
  end
214
246
 
215
- def test_inpsect
247
+ def test_inspect
216
248
  l = LazyList[1..11]
217
- assert_equal("[]", LazyList::Empty.inspect)
218
- assert_equal("[1,... ]", l.inspect)
249
+ assert_equal "[]", LazyList::Empty.inspect
250
+ assert_equal "[1,... ]", l.inspect
219
251
  l[1]
220
- assert_equal("[1, 2,... ]", l.inspect)
252
+ assert_equal "[1, 2,... ]", l.inspect
221
253
  l[2]
222
- assert_equal("[1, 2, 3,... ]", l.inspect)
254
+ assert_equal "[1, 2, 3,... ]", l.inspect
223
255
  l[9]
224
- assert_equal("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10,... ]", l.inspect)
256
+ assert_equal "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10,... ]", l.inspect
225
257
  l.to_a
226
- assert_equal("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]", l.inspect)
258
+ assert_equal "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]", l.inspect
227
259
  end
228
260
 
229
261
  def test_zip
@@ -255,5 +287,17 @@ class TC_LazyList < Test::Unit::TestCase
255
287
  assert_equal [ 1 ] * 10 , ones.take(10)
256
288
  assert_equal '[1,... ]', ones.inspect
257
289
  end
290
+
291
+ def test_sublist
292
+ assert_equal LazyList::Empty, @natural.sublist(-1)
293
+ assert_equal LazyList::Empty, @natural.sublist(0)
294
+ assert_equal [1], @natural.sublist(1).to_a
295
+ assert_equal (1..10).to_a, @natural.sublist(10).to_a
296
+ assert_equal (6..15).to_a, @natural[5, 10].to_a
297
+ assert_equal (6..15).to_a, @natural[5..14].to_a
298
+ assert_equal (6..14).to_a, @natural[5...14].to_a
299
+ assert_equal nil, @natural.sublist(10)[10]
300
+ assert_equal 10, @natural.sublist(10)[9]
301
+ end
258
302
  end
259
303
  # vim: set et sw=2 ts=2:
metadata CHANGED
@@ -3,56 +3,65 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: lazylist
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.0
7
- date: 2005-10-08 00:00:00 +02:00
6
+ version: 0.2.1
7
+ date: 2005-12-22 00:00:00 +01:00
8
8
  summary: Implementation of lazy lists for Ruby
9
9
  require_paths:
10
- - lib
10
+ - lib
11
11
  email: flori@ping.de
12
12
  homepage: http://lazylist.rubyforge.org
13
13
  rubyforge_project: lazylist
14
- description: ''
14
+ description: ""
15
15
  autorequire: lazylist
16
16
  default_executable:
17
17
  bindir: bin
18
18
  has_rdoc: true
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
20
20
  requirements:
21
- -
22
- - ">"
23
- - !ruby/object:Gem::Version
24
- version: 0.0.0
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
25
24
  version:
26
25
  platform: ruby
27
26
  signing_key:
28
27
  cert_chain:
29
28
  authors:
30
- - Florian Frank
29
+ - Florian Frank
31
30
  files:
32
- - examples
33
- - install.rb
34
- - GPL
35
- - TODO
36
- - Rakefile
37
- - VERSION
38
- - tests
39
- - CHANGES
40
- - lib
41
- - make_doc.rb
42
- - README.en
43
- - examples/hamming.rb
44
- - examples/sieve.rb
45
- - examples/pi.rb
46
- - examples/examples.rb
47
- - tests/test.rb
48
- - tests/test_enumerable.rb
49
- - tests/runner.rb
50
- - lib/lazylist.rb
31
+ - examples
32
+ - install.rb
33
+ - GPL
34
+ - TODO
35
+ - Rakefile
36
+ - VERSION
37
+ - tests
38
+ - CHANGES
39
+ - lib
40
+ - make_doc.rb
41
+ - README.en
42
+ - examples/hamming.rb
43
+ - examples/sieve.rb
44
+ - examples/pi.rb
45
+ - examples/examples.rb
46
+ - tests/test.rb
47
+ - tests/test_enumerable.rb
48
+ - tests/runner.rb
49
+ - lib/lazylist.rb
51
50
  test_files:
52
- - tests/test.rb
53
- rdoc_options: []
54
- extra_rdoc_files: []
51
+ - tests/test.rb
52
+ rdoc_options:
53
+ - --title
54
+ - LazyList -- Infinite lists in Ruby
55
+ - --main
56
+ - LazyList
57
+ - --line-numbers
58
+ extra_rdoc_files:
59
+ - lib/lazylist.rb
55
60
  executables: []
61
+
56
62
  extensions: []
63
+
57
64
  requirements: []
58
- dependencies: []
65
+
66
+ dependencies: []
67
+