range_builder 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/range_builder/version.rb +1 -1
- data/lib/range_builder.rb +2 -2
- data/test/range_builder_test.rb +13 -1
- metadata +2 -2
data/lib/range_builder.rb
CHANGED
@@ -22,8 +22,8 @@ class RangeBuilder
|
|
22
22
|
# arg: sorted enum. elements must implement succ
|
23
23
|
def self.build_from_sorted enum
|
24
24
|
ranges = []
|
25
|
-
|
26
|
-
last =
|
25
|
+
return ranges if enum.empty?
|
26
|
+
first = last = enum.first
|
27
27
|
enum.each_cons(2) do |a,b|
|
28
28
|
last = b
|
29
29
|
if a.succ != b
|
data/test/range_builder_test.rb
CHANGED
@@ -8,7 +8,6 @@ class RangeBuilderTest < MiniTest::Unit::TestCase
|
|
8
8
|
|
9
9
|
def test_build_range
|
10
10
|
m = [3, 2, 6, 2].map{|i|M.new(i)}
|
11
|
-
puts RangeBuilder.build_range(m){|a|a.foo}.inspect
|
12
11
|
first, last = RangeBuilder.build_range(m){|a|a.foo}
|
13
12
|
assert_equal 2, first.foo
|
14
13
|
assert_equal 6, last.foo
|
@@ -23,4 +22,17 @@ class RangeBuilderTest < MiniTest::Unit::TestCase
|
|
23
22
|
assert_equal (9..9), ranges[2]
|
24
23
|
assert_equal (11..13), ranges[3]
|
25
24
|
end
|
25
|
+
|
26
|
+
def test_trivial_build_from_sorted
|
27
|
+
m = [ 2 ]
|
28
|
+
ranges = RangeBuilder.build_from_sorted(m)
|
29
|
+
assert_equal 1, ranges.size
|
30
|
+
assert_equal (2..2), ranges[0]
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_empty_build_from_sorted
|
34
|
+
m = []
|
35
|
+
ranges = RangeBuilder.build_from_sorted(m)
|
36
|
+
assert_equal 0, ranges.size
|
37
|
+
end
|
26
38
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: range_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-06 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Build ranges from an enumeration
|
15
15
|
email:
|