RubyRanges 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ruby_ranges/range.rb +5 -5
- data/lib/ruby_ranges/version.rb +1 -1
- data/test/ruby_ranges_test.rb +10 -0
- metadata +3 -3
data/lib/ruby_ranges/range.rb
CHANGED
@@ -21,14 +21,14 @@ module RubyRanges
|
|
21
21
|
|
22
22
|
def include_range?(range)
|
23
23
|
case
|
24
|
+
when self.include?(range.begin) && self.end <= range.end # upload inclusive
|
25
|
+
RubyRanges::UpwardIncluded
|
26
|
+
when self.include?(range.end) && self.begin >= range.begin # downward inclusive
|
27
|
+
RubyRanges::DownwardIncluded
|
24
28
|
when self.include?(range.begin) && self.include?(range.end) # wholly inclusive
|
25
29
|
RubyRanges::WhollyIncluded
|
26
30
|
when range.include?(self.begin) && range.include?(self.end) # inverse wholly inclusive
|
27
31
|
RubyRanges::InverseWhollyIncluded
|
28
|
-
when self.include?(range.begin) && self.end < range.end # upload inclusive
|
29
|
-
RubyRanges::UpwardIncluded
|
30
|
-
when self.include?(range.end) && self.begin > range.begin # downward inclusive
|
31
|
-
RubyRanges::DownwardIncluded
|
32
32
|
else # exclusive range
|
33
33
|
RubyRanges::MutuallyExcluded
|
34
34
|
end
|
@@ -56,7 +56,7 @@ module RubyRanges
|
|
56
56
|
nil
|
57
57
|
when TrueClass # self split by wholly inclusive range
|
58
58
|
RubyRanges::Array.new(self.begin..range.begin, range.end..self.end)
|
59
|
-
when 1 # self shortened by
|
59
|
+
when 1 # self shortened by upward inclusive range
|
60
60
|
self.begin..range.begin
|
61
61
|
when -1 # self shortened by downward inclusive range
|
62
62
|
range.end..self.end
|
data/lib/ruby_ranges/version.rb
CHANGED
data/test/ruby_ranges_test.rb
CHANGED
@@ -60,6 +60,16 @@ class RubyRanges::RangeTest < Test::Unit::TestCase
|
|
60
60
|
assert_equal RubyRanges::Array.new((1..4), (8..9)), output
|
61
61
|
end
|
62
62
|
|
63
|
+
def test_subtracting_range_with_common_least_value
|
64
|
+
output = (1..10) - (1..10)
|
65
|
+
assert_equal (1..9), output
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_subtracting_range_with_common_greatest_value
|
69
|
+
output = (1..10) - (9..10)
|
70
|
+
assert_equal (1..9), output
|
71
|
+
end
|
72
|
+
|
63
73
|
def test_subtracting_wholly_included_range
|
64
74
|
output = (1..9) - (5..7)
|
65
75
|
assert_equal RubyRanges::Array.new(1..5, 7..9), output
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: RubyRanges
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Chris Winslett
|