range_extd 0.1.1 → 0.2.0

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c920255a38ca8b0805d5cfe50d4fbabd4718417f
4
- data.tar.gz: 47fa8995de09e68a381144751fffe86e42082804
3
+ metadata.gz: dae65a7801b819ebc7527acbbf1080c33b39f30b
4
+ data.tar.gz: f242186b0e029594148cd3f09fd460fc0e8143ae
5
5
  SHA512:
6
- metadata.gz: bf51ff3e606ec3b1955fe0978a407ec60130eacf0591fb3c5f85f927f890043e4adc6bd88a094ab14e19d954f40bef24e94048e0078ac8cfcbe0fcb775fccb3a
7
- data.tar.gz: c8ac4fb7471a7246b5d238b3acbc7a97355e59d4addf10e8075c3376edfcdcdb8291b631921c76cac5b099ac21ca538dc07f30dddb87e7162844de71f5eb7099
6
+ metadata.gz: 7520c16da3bbfe5e13cb4c6d18553c412b6e34431704f4ba2f591549af3e712d285e821567cfa8f9bd597c09dcf4335a02d330085a9163adeb6b8ee4aef86025
7
+ data.tar.gz: 10febe606e27681b7f7e4fdb43589f3127ba1a5cd976baa97b8ba09da506c63659b6c81d05af2fe76dec88a7df233fd99cbbcec0b48e05f177cb6a4978e90a3f
data/ChangeLog CHANGED
@@ -1,6 +1,16 @@
1
+ -----
2
+ (Version: 0.2.0)
3
+ 2014-04-29 Masa Saskano
4
+ * Changed the name of a constant from RangeExtd::EVERYTHING to RangeExtd::ALL.
5
+ Now accepts optional arguments in RangeExtd.new().
6
+ Bug fix in RangeExtd#size when the begin is Float/Rational.
7
+ Updated the embeded document in infinity.rb, mentioning about Time and Date classes.
8
+ Added a text file News at the top directory.
9
+
1
10
  -----
2
11
  (Version: 0.1.1)
3
- 2014-04-28 Masa Saskano
12
+ 2014-04-28 Masa Sakano
13
+
4
14
  * Merging Japanese README into the same file as the English one.
5
15
 
6
16
  -----
data/News ADDED
@@ -0,0 +1,13 @@
1
+ -----
2
+ (Version: 0.2.0) 2014-04-29
3
+ * Changed the name of a constant from RangeExtd::EVERYTHING to RangeExtd::ALL.
4
+ * Now accepts optional arguments in RangeExtd.new().
5
+ * Bug fix in RangeExtd#size when the begin is Float/Rational.
6
+
7
+ -----
8
+ (Version: 0.1.1) 2014-04-28
9
+ * Merging Japanese README into the same file as the English one.
10
+
11
+ -----
12
+ (Version: 0.1.0) 2014-04-27
13
+ * First upload to RubyGems.
data/README.en.rdoc CHANGED
@@ -5,7 +5,7 @@ This package contains RangeExtd class, the Extended Range class that features:
5
5
 
6
6
  1. includes exclude_begin? (to exclude the "begin" boundary),
7
7
  2. allows open-ended range (to the infinity),
8
- 3. defines NONE and EVERYTHING constants,
8
+ 3. defines NONE and ALL constants,
9
9
  4. the first self-consistent logical structure,
10
10
  5. complete backward-compatibility within the built-in Range.
11
11
 
@@ -62,6 +62,14 @@ with it, and I think it achieves the good logical completeness within the frame.
62
62
  I hope you find it to be useful.
63
63
 
64
64
 
65
+ ==== NOTE: Relationship with Rangesmaller
66
+
67
+ This package supercedes the obsolete Rangesmaller package and class,
68
+ with the added open-ended feature, and a different interface in
69
+ creating a new instance.
70
+ {https://rubygems.org/gems/rangesmaller}
71
+
72
+
65
73
  == Install
66
74
 
67
75
  gem install range_extd
@@ -100,18 +108,21 @@ Here are some simple examples.
100
108
  RangeExtd(1, 1, true, true) == RangeExtd::NONE # => true
101
109
  RangeExtd(1, 1, false, true) # => ArgumentError
102
110
  (RangeExtd::Infinity::NEGATIVE..RangeExtd::Infinity::POSITIVE) \
103
- == RangeExtd::EVERYTHING # => true
111
+ == RangeExtd::ALL # => true
104
112
 
105
113
  Basically, there are two forms:
106
114
 
107
- RangeExtd(range, [exclude_begin=false, [exclude_end=false]])
108
- RangeExtd(obj_begin, obj_end, [exclude_begin=false, [exclude_end=false]])
115
+ RangeExtd(range, [exclude_begin=false, [exclude_end=false]], opts)
116
+ RangeExtd(obj_begin, obj_end, [exclude_begin=false, [exclude_end=false]], opts)
109
117
 
110
- The last two parameters specify the respective boundary to be excluded if true,
118
+ The two parameters in the brackets specify the respective boundary to be excluded if true,
111
119
  or included if false (Default). If they contradict to the first
112
120
  parameter of the range (Range or RangeExtd), those latter two parameters are used.
121
+ Also, you can specify the same parameters as the options <tt>:exclude_begin</tt>
122
+ and <tt>:exclude_end</tt>, which have the highest priority, if specified.
113
123
  <tt>RangeExtd.new()</tt> is the same thing.
114
124
 
125
+
115
126
  === Slightly more advanced uses
116
127
 
117
128
  (1..RangeExtd::Infinity::POSITIVE).each do |i|
@@ -129,7 +140,7 @@ parameter of the range (Range or RangeExtd), those latter two parameters are use
129
140
  RangeExtd(?a, ?e, true, true).to_a? # => ["b", "c", "d"]
130
141
  RangeExtd(?a, ?e, true, true).empty? # => false
131
142
  RangeExtd::NONE.is_none? # => true
132
- RangeExtd::EVERYTHING.is_everything? # => true
143
+ RangeExtd::ALL.is_all? # => true
133
144
 
134
145
  All the methods that are in the built-in Range can be used.
135
146
 
@@ -182,7 +193,7 @@ sections). Any attempt to try to create an instance that is not
182
193
  There are two constants defined in this class:
183
194
 
184
195
  * RangeExtd::NONE
185
- * RangeExtd::EVERYTHING
196
+ * RangeExtd::ALL
186
197
 
187
198
  The former represents the empty range and the latter does the range
188
199
  covers everything, namely open-ended for the both negative and
@@ -198,7 +209,7 @@ Range class, as RangeExtd inherits it).
198
209
  * <tt>empty?</tt>
199
210
  * <tt>null?</tt>
200
211
  * <tt>is_none?</tt>
201
- * <tt>is_everything?</tt>
212
+ * <tt>is_all?</tt>
202
213
 
203
214
  There is a class method, which is equivalent to the instance
204
215
  method <tt>valid?</tt>.
data/README.ja.rdoc CHANGED
@@ -5,7 +5,7 @@ This package contains RangeExtd class, the Extended Range class that features:
5
5
 
6
6
  1. includes exclude_begin? (to exclude the "begin" boundary),
7
7
  2. allows open-ended range (to the infinity),
8
- 3. defines NONE and EVERYTHING constants,
8
+ 3. defines NONE and ALL constants,
9
9
  4. the first self-consistent logical structure,
10
10
  5. complete backward-compatibility within the built-in Range.
11
11
 
@@ -62,6 +62,14 @@ with it, and I think it achieves the good logical completeness within the frame.
62
62
  I hope you find it to be useful.
63
63
 
64
64
 
65
+ ==== NOTE: Relationship with Rangesmaller
66
+
67
+ This package supercedes the obsolete Rangesmaller package and class,
68
+ with the added open-ended feature, and a different interface in
69
+ creating a new instance.
70
+ {https://rubygems.org/gems/rangesmaller}
71
+
72
+
65
73
  == Install
66
74
 
67
75
  gem install range_extd
@@ -100,16 +108,18 @@ Here are some simple examples.
100
108
  RangeExtd(1, 1, true, true) == RangeExtd::NONE # => true
101
109
  RangeExtd(1, 1, false, true) # => ArgumentError
102
110
  (RangeExtd::Infinity::NEGATIVE..RangeExtd::Infinity::POSITIVE) \
103
- == RangeExtd::EVERYTHING # => true
111
+ == RangeExtd::ALL # => true
104
112
 
105
113
  Basically, there are two forms:
106
114
 
107
- RangeExtd(range, [exclude_begin=false, [exclude_end=false]])
108
- RangeExtd(obj_begin, obj_end, [exclude_begin=false, [exclude_end=false]])
115
+ RangeExtd(range, [exclude_begin=false, [exclude_end=false]], opts)
116
+ RangeExtd(obj_begin, obj_end, [exclude_begin=false, [exclude_end=false]], opts)
109
117
 
110
- The last two parameters specify the respective boundary to be excluded if true,
118
+ The two parameters in the brackets specify the respective boundary to be excluded if true,
111
119
  or included if false (Default). If they contradict to the first
112
120
  parameter of the range (Range or RangeExtd), those latter two parameters are used.
121
+ Also, you can specify the same parameters as the options <tt>:exclude_begin</tt>
122
+ and <tt>:exclude_end</tt>, which have the highest priority, if specified.
113
123
  <tt>RangeExtd.new()</tt> is the same thing.
114
124
 
115
125
  === Slightly more advanced uses
@@ -129,7 +139,7 @@ parameter of the range (Range or RangeExtd), those latter two parameters are use
129
139
  RangeExtd(?a, ?e, true, true).to_a? # => ["b", "c", "d"]
130
140
  RangeExtd(?a, ?e, true, true).empty? # => false
131
141
  RangeExtd::NONE.is_none? # => true
132
- RangeExtd::EVERYTHING.is_everything? # => true
142
+ RangeExtd::ALL.is_all? # => true
133
143
 
134
144
  All the methods that are in the built-in Range can be used.
135
145
 
@@ -182,7 +192,7 @@ sections). Any attempt to try to create an instance that is not
182
192
  There are two constants defined in this class:
183
193
 
184
194
  * RangeExtd::NONE
185
- * RangeExtd::EVERYTHING
195
+ * RangeExtd::ALL
186
196
 
187
197
  The former represents the empty range and the latter does the range
188
198
  covers everything, namely open-ended for the both negative and
@@ -198,7 +208,7 @@ Range class, as RangeExtd inherits it).
198
208
  * <tt>empty?</tt>
199
209
  * <tt>null?</tt>
200
210
  * <tt>is_none?</tt>
201
- * <tt>is_everything?</tt>
211
+ * <tt>is_all?</tt>
202
212
 
203
213
  There is a class method, which is equivalent to the instance
204
214
  method <tt>valid?</tt>.
@@ -324,7 +334,7 @@ Versions:: The versions of this package follow Semantic Versioning (2.0.0) http:
324
334
 
325
335
  1. メソッド exclude_begin? の導入 (レンジの始点を除外できる),
326
336
  2. (無限大に)開いたレンジ
327
- 3. NONE (空レンジ) と EVERYTHING (全範囲レンジ)定数の導入
337
+ 3. NONE (空レンジ) と ALL (全範囲レンジ)定数の導入
328
338
  4. 初めて自己論理的に完結したレンジ構造の達成
329
339
  5. 組込Rangeとの完全後方互換性
330
340
 
@@ -377,6 +387,13 @@ Versions:: The versions of this package follow Semantic Versioning (2.0.0) http:
377
387
  このクラスが少なからぬ人に有用なものであることを願ってここにリリースします。
378
388
 
379
389
 
390
+ ==== 注: Rangesmaller との関係
391
+
392
+ このパッケージは、(今やサポートされていない) Rangesmaller パッケージ及びクラスを
393
+ 後継するものです。同クラスの機能に、無限に開いた範囲を許す機能が加わり、また、オ
394
+ ブジェクト生成時のインターフェースが変更されています。
395
+ {https://rubygems.org/gems/rangesmaller}
396
+
380
397
  == インストール
381
398
 
382
399
  gem install range_extd
@@ -415,17 +432,20 @@ Versions:: The versions of this package follow Semantic Versioning (2.0.0) http:
415
432
  RangeExtd(1, 1, true, true) == RangeExtd::NONE # => true
416
433
  RangeExtd(1, 1, false, true) # => ArgumentError
417
434
  (RangeExtd::Infinity::NEGATIVE..RangeExtd::Infinity::POSITIVE) \
418
- == RangeExtd::EVERYTHING # => true
435
+ == RangeExtd::ALL # => true
419
436
 
420
437
  インスタンスを作成するのには、二通りあります。
421
438
 
422
- RangeExtd(range, [exclude_begin=false, [exclude_end=false]])
423
- RangeExtd(obj_begin, obj_end, [exclude_begin=false, [exclude_end=false]])
439
+ RangeExtd(range, [exclude_begin=false, [exclude_end=false]], opts)
440
+ RangeExtd(obj_begin, obj_end, [exclude_begin=false, [exclude_end=false]], opts)
424
441
 
425
- 後ろの二つのパラメーターが、それぞれ始点と終点とを除外する(true)、または含む
442
+ 大括弧の中の二つのパラメーターが、それぞれ始点と終点とを除外する(true)、または含む
426
443
  (false)を指示します。もし、その二つのパラメーターが最初のパラメーターのレンジ
427
444
  (Range or RangeExtd) と矛盾する場合は、ここで与えた二つのパラメーターが優先され
428
- ます。 <tt>RangeExtd.new()</tt> も上と同意味です。
445
+ ます。同じパラメーターをオプションHash
446
+ (<tt>:exclude_begin</tt> と <tt>:exclude_end</tt>)で指定することもできて、
447
+ もし指定されればそれらが最高の優先度を持ちます。
448
+ <tt>RangeExtd.new()</tt> も上と同意味です。
429
449
 
430
450
 
431
451
  === 少し上級編
@@ -445,7 +465,7 @@ Versions:: The versions of this package follow Semantic Versioning (2.0.0) http:
445
465
  RangeExtd(?a, ?e, true, true).to_a? # => ["b", "c", "d"]
446
466
  RangeExtd(?a, ?e, true, true).empty? # => false
447
467
  RangeExtd::NONE.is_none? # => true
448
- RangeExtd::EVERYTHING.is_everything? # => true
468
+ RangeExtd::ALL.is_all? # => true
449
469
 
450
470
  組込Rangeに含まれる全てのメソッドが使用可能です。
451
471
 
@@ -498,7 +518,7 @@ RangeExtd のインスタンスは、 Rangeと同じくイミュータブルで
498
518
  このクラスには、二つの定数が定義されています。
499
519
 
500
520
  * RangeExtd::NONE
501
- * RangeExtd::EVERYTHING
521
+ * RangeExtd::ALL
502
522
 
503
523
  前者は、空レンジを表し、後者は全てを含むレンジ、すなわち正負両方向に開いたレンジを表します。
504
524
 
@@ -511,7 +531,7 @@ Rangeクラスのみで定義されていて、 RangeExtd はそれを継承し
511
531
  * <tt>empty?</tt>
512
532
  * <tt>null?</tt>
513
533
  * <tt>is_none?</tt>
514
- * <tt>is_everything?</tt>
534
+ * <tt>is_all?</tt>
515
535
 
516
536
  インスタンスメソッドの <tt>valid?</tt> に等価なクラスメソッドも一つあります。
517
537
  * <tt>RangeExtd.valid?</tt>
@@ -39,9 +39,11 @@ class RangeExtd < Range
39
39
  # However any operator is, by Ruby's definition, not commutative,
40
40
  # unless both the classes define so.
41
41
  #
42
- # There are only two built-in classes that are Comparable: String and Numeric
42
+ # There are only three built-in classes that are Comparable: String, Time and Numeric
43
43
  # (except for Complex).
44
- # For String class objects, the [#<=>] operator work as expected
44
+ # Note Date and DateTime objects are so, too, however practically
45
+ # they need "require", hence are (and must be) treated, the same as any other class.
46
+ # For String and Time class objects, the [#<=>] operator work as expected
45
47
  # in the commutative way.
46
48
  # ?z <=> RangeExtd::Infinity::POSITIVE # => nil
47
49
  # RangeExtd::Infinity::POSITIVE <=> ?z # => 1.
@@ -80,7 +82,8 @@ class RangeExtd < Range
80
82
  # However, some existing Comparable classes, perhaps written by some
81
83
  # one else may not be so polite, and has disabled comparison
82
84
  # with any object but those intended. Unlucky you!
83
- #
85
+ # For example, the classes like Date and DateTime are one of them.
86
+ #
84
87
  # For that sort of circumstances,
85
88
  # the class method {RangeExtd::Infinity.overwrite_compare} provides
86
89
  # a convenient way to overcome this problem to make
@@ -39,11 +39,11 @@ class RangeExtd < Range
39
39
  end
40
40
 
41
41
  # Two constants
42
- NONE = RangeExtd.new(nil...nil, true, true) # In Ruby1.8, this causes ArgumentError: bad value for range (because (nil..nil) is unaccepted).
43
- EVERYTHING = RangeExtd.new(Infinity::NEGATIVE..Infinity::POSITIVE, false, false)
42
+ NONE = RangeExtd.new(nil...nil, true, true) # In Ruby1.8, this causes ArgumentError: bad value for range (because (nil..nil) is unaccepted).
43
+ ALL = RangeExtd.new(Infinity::NEGATIVE..Infinity::POSITIVE, false, false)
44
44
 
45
45
  #NONE.freeze
46
- #EVERYTHING.freeze
46
+ #ALL.freeze
47
47
  end
48
48
 
49
49
 
@@ -57,7 +57,7 @@ end
57
57
  # Extended Range class that features:
58
58
  # 1. includes exclude_begin? (to exclude the "begin" boundary),
59
59
  # 2. allows open-ended range (to the infinity),
60
- # 3. defines NONE and EVERYTHING constants,
60
+ # 3. defines NONE and ALL constants,
61
61
  # 4. the first self-consistent logical structure,
62
62
  # 5. complete backward compatibility within the built-in Range.
63
63
  #
@@ -77,28 +77,34 @@ end
77
77
  #
78
78
  class RangeExtd < Range
79
79
 
80
- # @note If the given optional parameter(s) of exclude_begin|end
81
- # do not agree with those in the first parameter (range),
82
- # the value(s) of the optional parameter(s) is used.
80
+ # @note The flag of exclude_begin|end can be given in the arguments in a couple of ways.
81
+ # If there is any duplication, those specified in the optional hash have the highest
82
+ # priority. Then the two descrete Boolean parameters have the second.
83
+ # If not, the values embeded in the {Range} or {RangeExtd} object
84
+ # in the parameter are used. In default, both of them are false.
83
85
  #
84
- # @overload new(range, [exclude_begin=false, [exclude_end=false, [opts]]])
86
+ # @overload new(range, [exclude_begin=false, [exclude_end=false]], opts)
85
87
  # @param [Object] range Instance of Range or its subclasses, including RangeExtd
86
- # @param exclude_begin [Object] true or false(Default) or any
87
- # @param exclude_end [Object] true or false(Default) or any.
88
+ # @param exclude_begin [Boolean] If specified, this has the higher priority, or false in default.
89
+ # @param exclude_end [Boolean] If specified, this has the higher priority, or false in default.
90
+ # @option opts [Boolean] :exclude_begin If specified, this has the highest priority, or false in default.
91
+ # @option opts [Boolean] :exclude_end If specified, this has the highest priority, or false in default.
88
92
  #
89
- # @overload new(obj_begin, obj_end, [exclude_begin=false, [exclude_end=false, [opts]]])
93
+ # @overload new(obj_begin, obj_end, [exclude_begin=false, [exclude_end=false]], opts)
90
94
  # @param obj_begin [Object] Any object that is {Comparable} with end
91
95
  # @param obj_end [Object] Any object that is Comparable with begin
92
- # @param exclude_begin [Object] true or false(Default) or any
93
- # @param exclude_end [Object] true or false(Default) or any.
96
+ # @param exclude_begin [Boolean] If specified, this has the lower priority, or false in default.
97
+ # @param exclude_end [Boolean] If specified, this has the lower priority, or false in default.
98
+ # @option opts [Boolean] :exclude_begin If specified, this has the higher priority, or false in default.
99
+ # @option opts [Boolean] :exclude_end If specified, this has the higher priority, or false in default.
94
100
  #
95
101
  # Note no possible opts are defined at present.
96
102
  # Any opts given as Hash are simply ignored.
97
103
  #
98
104
  # @raise [ArgumentError] particularly if the range to be created is not {#valid?}.
99
- def initialize(*inar)
105
+ def initialize(*inar, **hsopt) # **k expression from Ruby 1.9?
100
106
 
101
- arout = RangeExtd.class_eval{ _get_init_args(*inar) } # From Ruby 1.8.7 (?)
107
+ arout = RangeExtd.class_eval{ _get_init_args(*inar, hsopt) } # class_eval from Ruby 1.8.7 (?)
102
108
 
103
109
  ### The following routine is obsolete.
104
110
  ### Users, if they wish, should call RangeExtd::Infinity.overwrite_compare() beforehand.
@@ -151,10 +157,10 @@ class RangeExtd < Range
151
157
  self.begin.nil? && self.end.nil? && @exclude_begin && @exclude_end # Direct comparison with object_id should be OK?
152
158
  end
153
159
 
154
- # true if self is identical to {RangeExtd::EVERYTHING} ({#==} does not mean it at all!)
160
+ # true if self is identical to {RangeExtd::ALL} ({#==} does not mean it at all!)
155
161
  # @example
156
- # (RangeExtd::Infinity::NEGATIVE..RangeExtd::Infinity::POSITIVE).is_everything? # => false
157
- def is_everything?
162
+ # (RangeExtd::Infinity::NEGATIVE..RangeExtd::Infinity::POSITIVE).is_all? # => false
163
+ def is_all?
158
164
  self.begin.object_id == Infinity::NEGATIVE.object_id && self.end.object_id == Infinity::POSITIVE.object_id && !@exclude_begin && !@exclude_end # Direct comparison with object_id should not work for this one!! (because users can create an identical one.)
159
165
  end
160
166
 
@@ -217,7 +223,7 @@ class RangeExtd < Range
217
223
  # If the object is open-ended to the negative (Infinity),
218
224
  # this returns nil in default, unless the given object is Numeric
219
225
  # (and comparable of Real), in which case this calls {#cover?},
220
- # or if self is {RangeExtd::EVERYTHING} and the object is Comparable.
226
+ # or if self is {RangeExtd::ALL} and the object is Comparable.
221
227
  #
222
228
  # In the standard Range, this checks whether the given object is a member, hence,
223
229
  # (?D..?z) === ?c # => true
@@ -568,11 +574,59 @@ class RangeExtd < Range
568
574
  end
569
575
 
570
576
 
571
-
577
+ # Implementation of {Range#size} to this class.
578
+ #
579
+ # It is essentially the same, but the behaviour when {#exclude_begin?} is true
580
+ # may not always be natural.
572
581
  # See {#first} for the definition when {#exclude_begin?} is true.
582
+ #
583
+ # {Range#size} only works for Numeric ranges.
584
+ # And in {Range#size}, the value is calculated when the initial value is
585
+ # non-Integer, by stepping by 1.0 from the {#begin} value, and the returned
586
+ # value is an integer.
587
+ # For example,
588
+ # (1.4..2.6).size == 2
589
+ # because both 1.4 and 2.4 (== 1.4+1.0) are included in the Range.
590
+ #
591
+ # That means you had better be careful with the uncertainty (error)
592
+ # of floating-point. For example, at least in an environment,
593
+ # 4.8 - 4.5 # => 0.2999999999999998
594
+ # (2.5...4.5000000000000021).size => 2
595
+ # (2.8...4.8000000000000021).size => 3
596
+ # (2.8..4.8).size => 3
597
+ #
598
+ # In {RangeExtd#size}, the principle is the same. If the {#begin} value has
599
+ # the method [#succ] defined, the object is regarded to consist of
600
+ # discrete values. If not, it is a range with continuous elements.
601
+ # This dinstinguishment affects the behavious seriously in some cases
602
+ # when {#exclude_begin?} is true. For example, the following two cases
603
+ # may seem unnatural.
604
+ # RangeExtd(1..5, true, true) == RangeExtd(Rational(1,1), 5, true, true)
605
+ # RangeExtd(1..5, true, true).size != RangeExtd(Rational(1,1), 5, true, true).size
606
+ #
607
+ # Although those two objects are equal by [#==], they are different
608
+ # in nature, as far as {Range} and {RangeExtd} are concerned,
609
+ # and that is why they work differently;
610
+ # RangeExtd(1..5, true, true).eql?(RangeExtd(Rational(1,1), 5, true, true)) # => false
611
+ # RangeExtd(1..5, true, true).to_a # => [2, 3, 4]
612
+ # RangeExtd(1..5, true, true).to_a.size # => 3
613
+ # RangeExtd(Rational(1,1)..5).to_a # => TypeError
614
+ #
615
+ # Also, the floating-point uncertainties in Float can more often be
616
+ # problematic; for example, in an environment,
617
+ # 4.4 - 2.4 # => 2.0000000000000004
618
+ # 4.8 - 2.8 # => 2.0
619
+ # RangeExtd(2.4..4.4, true, true).size # => 3
620
+ # RangeExtd(2.8..4.8, true, true).size # => 2
621
+ # The last example is what you would naively expect, because both
622
+ # 2.8+a(lim a->0) and 3.8+a(lim a->0) are
623
+ # in the range whereas 4.8 is not in the range by definition,
624
+ # but not the example right above.
625
+ #
573
626
  # @see http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/49797 [ruby-list:49797] from matz for how {Range#size} behaves (in Japanese).
574
627
  #
575
628
  # @return [Integer] 0 if {RangeExtd::NONE}
629
+ # @return [Float] Float::INFINITY if either (or both) the end is infinity, regardless of the class of the elements.
576
630
  # @return [nil] if the range is non-Numeric.
577
631
  def size(*rest)
578
632
  # (1..5).size # => 5
@@ -607,9 +661,20 @@ class RangeExtd < Range
607
661
  elsif @exclude_begin
608
662
 
609
663
  begin
610
- 1.0 + self.begin()
664
+ _dummy = 1.0 + self.begin() # _dummy to suppress warning: possibly useless use of + in void context
665
+
611
666
  # Numeric
612
- Range.new(self.begin()+1, self.end, exclude_end?).send(__method__, *rest) # Swap the order of '+' from the above, so that Integer/Rational is calculated as it is.
667
+ if defined? (self.begin().succ)
668
+ Range.new(self.begin().succ, self.end, exclude_end?).send(__method__, *rest)
669
+ else
670
+ size_no_exclude = Range.new(self.begin, self.end).send(__method__, *rest) # exclude_end? == true, ie., Range with both ends inclusinve.
671
+ diff = self.end - self.begin
672
+ if diff.to_i == diff # Integer difference
673
+ return size_no_exclude - 1 # At least exclude_begin?==true (so exclude_end? does not matter)
674
+ else
675
+ return size_no_exclude
676
+ end
677
+ end
613
678
  rescue TypeError
614
679
  # Non-Numeric
615
680
  if defined? self.begin().succ
@@ -658,7 +723,7 @@ class RangeExtd < Range
658
723
 
659
724
 
660
725
  # Private class method to evaluate the arguments.
661
- def self._get_init_args(*inar)
726
+ def self._get_init_args(*inar, **hsopt)
662
727
  nMin = 1; nMax = 4
663
728
  if inar.size < nMin || nMax < inar.size
664
729
  raise ArgumentError, "wrong number of arguments (#{inar.size} for #{nMin}..#{nMax})"
@@ -694,7 +759,8 @@ class RangeExtd < Range
694
759
  raise ArgumentError, "wrong number of arguments (#{inar.size} for #{nMin}..#{nMax})"
695
760
  end
696
761
 
697
- arRet = [inar[0].begin, inar[0].end, exclude_end, exclude_begin]
762
+ beginend = [inar[0].begin, inar[0].end]
763
+ # arRet = [inar[0].begin, inar[0].end, exclude_end, exclude_begin]
698
764
  # @rangepart = Range.new(inar[0].begin, inar[0].end, exclude_end)
699
765
 
700
766
  when :object
@@ -710,14 +776,22 @@ class RangeExtd < Range
710
776
  exclude_end = false
711
777
  end
712
778
 
713
- arRet = [inar[0], inar[1], exclude_end, exclude_begin]
779
+ beginend = [inar[0], inar[1]]
780
+ # arRet = [inar[0], inar[1], exclude_end, exclude_begin]
714
781
  # @rangepart = Range.new(inar[0], inar[1], exclude_end)
715
782
 
716
783
  else
717
784
  raise # (for coding safety)
718
785
  end # case hsFlag[:prm1st]
719
786
 
720
- arRet
787
+ if hsopt.has_key?(:exclude_begin)
788
+ exclude_begin = (hsopt[:exclude_begin] && true)
789
+ end
790
+ if hsopt.has_key?(:exclude_end)
791
+ exclude_end = (hsopt[:exclude_end] && true)
792
+ end
793
+
794
+ beginend + [exclude_end, exclude_begin]
721
795
 
722
796
  end # def self._get_init_args(*inar)
723
797
 
@@ -751,6 +825,11 @@ class RangeExtd < Range
751
825
  #
752
826
  # Note the last example may change in the future release.
753
827
  #
828
+ # Note ([2]..[5]) is NOT valid, because Array does not include Comparable
829
+ # for some reason, as of Ruby 2.1.1, even though it has the redefined
830
+ # and working [#<=>]. You can make those valid, by including Comparable
831
+ # in Array class, should you wish.
832
+ #
754
833
  # @example
755
834
  #
756
835
  # RangeExtd.valid?(nil..nil) # => false
@@ -760,25 +839,35 @@ class RangeExtd < Range
760
839
  # RangeExtd.valid?(0..0, true) # => false
761
840
  # RangeExtd.valid?(0...0, true) # => true
762
841
  # RangeExtd.valid?(2..-1) # => false
763
- # RangeExtd.valid?(RangeExtd::NONE) # => true
764
- # RangeExtd.valid?(RangeExtd::EVERYTHING) # => true
765
- # RangeExtd.valid?(3..Float::INFINITY) # => true
842
+ # RangeExtd.valid?(RangeExtd::NONE) # => true
843
+ # RangeExtd.valid?(RangeExtd::ALL) # => true
844
+ # RangeExtd.valid?(3..Float::INFINITY) # => true
766
845
  # RangeExtd.valid?(3..Float::INFINITY, true) # => true
767
846
  # RangeExtd.valid?(RangeExtd::Infinity::NEGATIVE..?d) # => true
768
847
  # RangeExtd.valid?(RangeExtd::Infinity::NEGATIVE..?d, true) # => true
769
848
  #
770
- # @overload new(range, [exclude_begin=false, [exclude_end=false]])
849
+ # @note The flag of exclude_begin|end can be given in the arguments in a couple of ways.
850
+ # If there is any duplication, those specified in the optional hash have the highest
851
+ # priority. Then the two descrete Boolean parameters have the second.
852
+ # If not, the values embeded in the {Range} or {RangeExtd} object
853
+ # in the parameter are used. In default, both of them are false.
854
+ #
855
+ # @overload new(range, [exclude_begin=false, [exclude_end=false]], opts)
771
856
  # @param [Object] range Instance of Range or its subclasses, including RangeExtd
772
- # @param exclude_begin [Object] true or false(Default) or any
773
- # @param exclude_end [Object] true or false(Default) or any.
857
+ # @param exclude_begin [Boolean] If specified, this has the higher priority, or false in default.
858
+ # @param exclude_end [Boolean] If specified, this has the higher priority, or false in default.
859
+ # @option opts [Boolean] :exclude_begin If specified, this has the highest priority, or false in default.
860
+ # @option opts [Boolean] :exclude_end If specified, this has the highest priority, or false in default.
774
861
  #
775
- # @overload new(obj_begin, obj_end, [exclude_begin=false, [exclude_end=false]])
862
+ # @overload new(obj_begin, obj_end, [exclude_begin=false, [exclude_end=false]], opts)
776
863
  # @param obj_begin [Object] Any object that is {Comparable} with end
777
864
  # @param obj_end [Object] Any object that is Comparable with begin
778
- # @param exclude_begin [Object] true or false(Default) or any
779
- # @param exclude_end [Object] true or false(Default) or any.
865
+ # @param exclude_begin [Boolean] If specified, this has the lower priority, or false in default.
866
+ # @param exclude_end [Boolean] If specified, this has the lower priority, or false in default.
867
+ # @option opts [Boolean] :exclude_begin If specified, this has the higher priority, or false in default.
868
+ # @option opts [Boolean] :exclude_end If specified, this has the higher priority, or false in default.
780
869
  #
781
- def self.valid?(*inar)
870
+ def self.valid?(*inar, **hsopt)
782
871
  (vbeg, vend, exc_beg, exc_end) = _get_init_args(*inar)
783
872
 
784
873
  if (vbeg.nil? && vend.nil? && exc_beg && exc_end)
@@ -920,7 +1009,7 @@ end # class RangeExtd < Range
920
1009
  #== Summary
921
1010
  #
922
1011
  # Modifies {#==}, {#eql?} and add methods of
923
- # {#valid?}, {#empty?}, {#null?}, {#is_none?} and {#is_everything?}.
1012
+ # {#valid?}, {#empty?}, {#null?}, {#is_none?} and {#is_all?}.
924
1013
  #
925
1014
  class Range
926
1015
 
@@ -977,9 +1066,9 @@ class Range
977
1066
  # (0...0).valid? # => false
978
1067
  # (2..-1).valid? # => false
979
1068
  # RangeExtd(0...0, true) # => true
980
- # (3..Float::INFINITY).valid? # => true
981
- # RangeExtd::NONE.valid? # => true
982
- # RangeExtd::EVERYTHING.valid? # => true
1069
+ # (3..Float::INFINITY).valid? # => true
1070
+ # RangeExtd::NONE.valid? # => true
1071
+ # RangeExtd::ALL.valid? # => true
983
1072
  #
984
1073
  # @note By definition, all the {RangeExtd} instances are valid,
985
1074
  # because {RangeExtd#new} checks the validity.
@@ -1050,7 +1139,7 @@ class Range
1050
1139
  if self.exclude_end?
1051
1140
  true # RangeOpen::NONE
1052
1141
  else
1053
- false # RangeOpen::EVERYTHING
1142
+ false # RangeOpen::ALL
1054
1143
  end
1055
1144
  else
1056
1145
  if defined?(self.exclude_begin?)
@@ -1080,7 +1169,7 @@ class Range
1080
1169
  end
1081
1170
 
1082
1171
  # @return [FalseClass]
1083
- def is_everything?
1172
+ def is_all?
1084
1173
  false
1085
1174
  end
1086
1175
 
data/range_extd.gemspec CHANGED
@@ -2,14 +2,14 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{range_extd}
5
- s.version = "0.1.1"
5
+ s.version = "0.2.0"
6
6
  # s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
7
7
  # s.executables << 'hola'
8
8
  # s.bindir = 'bin'
9
9
  s.authors = ["Masa Sakano"]
10
- s.date = %q{2014-04-28}
10
+ s.date = %q{2014-04-29}
11
11
  s.summary = %q{RangeExtd - Extended Range class with exclude_begin and open-ends}
12
- s.description = %q{This defines a subclass of Range, RangeExtd and its subclass, RangeExtd::Infinity. The former defines a range that enables an exclusion of the begin boundary, in addition to the end boundary as in the built-in Range, and accepts open-ended ranges to infinity for either (or both) positive/negative direction. The latter has the two constant objects, POSITIVE and NEGATIVE, and they are a generalised Infinity of Float::INFINITY to any Comparable objects.}
12
+ s.description = %q{Package for a subclass of Range, RangeExtd and RangeExtd::Infinity. The former defines a range that enables an exclusion of the begin boundary, in addition to the end boundary as in the built-in Range, and accepts open-ended ranges to infinity for either (or both) positive/negative direction. The latter has the two constant objects, POSITIVE and NEGATIVE, and they are a generalised Infinity of Float::INFINITY to any Comparable objects.}
13
13
  # s.email = %q{abc@example.com}
14
14
  s.extra_rdoc_files = [
15
15
  # "LICENSE",
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
21
21
  #".document",
22
22
  #".gitignore",
23
23
  #"VERSION",
24
+ "News",
24
25
  "ChangeLog",
25
26
  "README.en.rdoc",
26
27
  "README.ja.rdoc",
@@ -340,6 +340,69 @@ return
340
340
  end
341
341
 
342
342
 
343
+ def test_new_exclude_begin_end
344
+ # Form 1: 1 parameters
345
+ assert !RangeExtd(3..5).exclude_begin?
346
+ assert !RangeExtd(3..5).exclude_end?
347
+ assert !RangeExtd(3..5).exclude_begin?
348
+ assert RangeExtd(3...5).exclude_end?
349
+
350
+ # Form 1: 1 parameters: RangeExtd
351
+ assert !RangeExtd(RangeExtd(3...5)).exclude_begin?
352
+ assert RangeExtd(RangeExtd(3...5)).exclude_end?
353
+ assert RangeExtd(RangeExtd(3...5,7)).exclude_begin?
354
+
355
+ # Form 1: 2-3 parameters
356
+ assert RangeExtd(3..5,7).exclude_begin?
357
+ assert !RangeExtd(3..5,7).exclude_end?
358
+ assert RangeExtd(3..5,7,8).exclude_begin?
359
+ assert RangeExtd(3..5,7,8).exclude_end?
360
+ assert RangeExtd(3...5,7,8).exclude_begin?
361
+ assert RangeExtd(3...5,7,8).exclude_end?
362
+ assert !RangeExtd(3...5,7,nil).exclude_end?
363
+ assert RangeExtd(RangeExtd(3...5,7,nil)).exclude_begin?
364
+ assert RangeExtd(RangeExtd(3...5,7,nil),7,8).exclude_begin?
365
+ assert RangeExtd(RangeExtd(3..5,7),7,8).exclude_begin?
366
+ assert RangeExtd(RangeExtd(3..5,7),7,8).exclude_end?
367
+ assert !RangeExtd(RangeExtd(3...5,7),nil,nil).exclude_begin?
368
+ assert !RangeExtd(RangeExtd(3...5,7),nil,nil).exclude_end?
369
+
370
+ # Form 1: 2-3 parameters + opts
371
+ assert !RangeExtd(3..5,7, :exclude_begin =>nil).exclude_begin?
372
+ assert RangeExtd(3..5,7, :exclude_end =>8).exclude_end?
373
+ assert !RangeExtd(3..5,7,8, :exclude_begin =>nil).exclude_begin?
374
+ assert !RangeExtd(3..5,7,8, :exclude_end =>nil).exclude_end?
375
+ assert !RangeExtd(3...5,7,8, :exclude_begin =>nil).exclude_begin?
376
+ assert !RangeExtd(3...5,7,8, :exclude_end =>nil).exclude_end?
377
+ assert RangeExtd(3...5,7,nil,:exclude_end =>9).exclude_end?
378
+
379
+ # Form 2: 2 parameters
380
+ assert !RangeExtd(3,5).exclude_begin?
381
+ assert !RangeExtd(3,5).exclude_end?
382
+
383
+ # Form 2: 3-4 parameters
384
+ assert RangeExtd(3,5,9).exclude_begin?
385
+ assert !RangeExtd(3,5,9).exclude_end?
386
+ assert RangeExtd(3,5,true,9).exclude_begin?
387
+ assert RangeExtd(3,5,true,9).exclude_end?
388
+ assert !RangeExtd(3,5,true,nil).exclude_end?
389
+
390
+ # Form 2: 2-4 parameters + opts
391
+ assert RangeExtd(3,5, :exclude_begin =>8).exclude_begin?
392
+ assert !RangeExtd(3,5,false, :exclude_begin =>8).exclude_end?
393
+ assert RangeExtd(3,5,false, :exclude_begin =>8).exclude_begin?
394
+ assert RangeExtd(3,5,false,9, :exclude_begin =>8).exclude_begin?
395
+ assert RangeExtd(3,5,false,9, :exclude_begin =>8).exclude_end?
396
+ assert !RangeExtd(3,5,false,nil,:exclude_begin =>8).exclude_end?
397
+ assert !RangeExtd(3,5,false,9, :exclude_begin =>nil).exclude_begin?
398
+ assert RangeExtd(3,5,false,9, :exclude_begin =>false).exclude_end?
399
+ assert RangeExtd(3...5,false,nil,:exclude_begin =>8, :exclude_end =>8).exclude_begin?
400
+ assert RangeExtd(3...5,false,nil,:exclude_begin =>8, :exclude_end =>8).exclude_end?
401
+ assert !RangeExtd(3,5,false,9, :exclude_end =>8).exclude_begin?
402
+ assert !RangeExtd(3,5,false,9, :exclude_end =>false).exclude_end?
403
+ assert RangeExtd(3,5,false,nil,:exclude_end =>8).exclude_end?
404
+ end
405
+
343
406
  def test_exclude_begin
344
407
  b = 1
345
408
  e = 4
@@ -354,7 +417,7 @@ return
354
417
  assert !RangeExtd.new(b,e,nil).exclude_end?
355
418
  assert RangeExtd.new(b,e,'c').exclude_begin?
356
419
  assert !RangeExtd.new(b,e,'c').exclude_end?
357
- assert RangeExtd.new(b,e,:a =>5).exclude_begin?
420
+ assert RangeExtd.new(b,e, :exclude_begin => 5).exclude_begin?
358
421
  assert !RangeExtd.new(b,e, false, false).exclude_begin?
359
422
  assert !RangeExtd.new(b,e, false, false).exclude_end?
360
423
  assert !RangeExtd.new(b,e, false, true ).exclude_begin?
@@ -389,12 +452,12 @@ return
389
452
  assert !((1...1).is_none?)
390
453
  end
391
454
 
392
- # Test of Range(Extd)#is_everything?
393
- def test_is_everything
394
- assert (RangeExtd::EVERYTHING.is_everything?)
395
- assert (RangeExtd(RangeExtd::Infinity::NEGATIVE, RangeExtd::Infinity::POSITIVE).is_everything?) # You can create it, if you want.
396
- assert !((RangeExtd::Infinity::NEGATIVE..RangeExtd::Infinity::POSITIVE).is_everything?) # Not the standard Range, though.
397
- assert !(RangeExtd(-Float::INFINITY, Float::INFINITY).is_everything?) # Different from Numeric, though.
455
+ # Test of Range(Extd)#is_all?
456
+ def test_is_all
457
+ assert (RangeExtd::ALL.is_all?)
458
+ assert (RangeExtd(RangeExtd::Infinity::NEGATIVE, RangeExtd::Infinity::POSITIVE).is_all?) # You can create it, if you want.
459
+ assert !((RangeExtd::Infinity::NEGATIVE..RangeExtd::Infinity::POSITIVE).is_all?) # Not the standard Range, though.
460
+ assert !(RangeExtd(-Float::INFINITY, Float::INFINITY).is_all?) # Different from Numeric, though.
398
461
  end
399
462
 
400
463
 
@@ -768,7 +831,7 @@ return
768
831
  assert_equal(@ie-@ib-1, @s22.size)
769
832
  assert_equal nil, RangeExtd("a", "c").size
770
833
  assert_equal 0, RangeExtd::NONE.size
771
- assert_equal Float::INFINITY, RangeExtd::EVERYTHING.size
834
+ assert_equal Float::INFINITY, RangeExtd::ALL.size
772
835
 
773
836
  # Infinity
774
837
  inf = Float::INFINITY
@@ -784,18 +847,38 @@ return
784
847
  assert_equal inf, RangeExtd( 1, inf, excl_ini).size
785
848
 
786
849
  # Float
787
- rfi = (2.4..4.4) # size() => 3 see [ruby-list:49797] from matz
788
- rfe = (2.4...4.4) # size() => 2
850
+ rfi = (2.8..4.8) # size() => 3 see [ruby-list:49797] from matz
851
+ rfe = (2.8...4.8) # size() => 2
789
852
  siz = rfi.size
790
853
  assert_equal siz, RangeExtd(rfi).size
791
854
  assert_equal siz-1, RangeExtd(rfe).size
792
855
  assert_equal siz-1, RangeExtd(rfi, excl_ini).size
793
- assert_equal siz-2, RangeExtd(rfe, excl_ini).size
794
- assert_equal siz-1, RangeExtd(Rational(24,10)..4.4, excl_ini).size
795
- assert_equal siz-2, RangeExtd(Rational(24,10)...4.4, excl_ini).size
856
+ assert_equal siz-1, RangeExtd(rfe, excl_ini).size
857
+
858
+ # Float No.2
859
+ # @see http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/49797 [ruby-list:49797] from matz for how {Range#size} behaves (in Japanese).
860
+ assert_equal 4, RaE( 1..5, true).size
861
+ assert_equal 3, RaE( 1..5, true, true).size # (1...5).size == 3
862
+ assert_equal 4, RaE(Rational(1,1), 5, true, true).size # (1/1...5).size == 4
863
+ assert_equal 3, RaE(1..Rational(5,1), true, true).size # (1...1/5).size == 3
864
+ assert_equal 4, RaE(1..Rational(5,1), true, false).size # (1..1/5).size == 4
865
+
866
+ assert_equal 5, RaE(0.8..5, true).size
867
+ assert_equal 4, RaE(1.2..5, true).size
868
+ assert_equal 4, RaE(1.5..5, true).size
869
+ assert_equal 4, RaE(1.5..4.9, true).size
870
+ assert_equal 3, RaE(1.5...4.5, true).size
871
+ assert_equal 2, RaE(2.8...4.8, true).size
872
+ assert_equal RaE(2.8...4.8, true).size, RaE(Rational(28,10)...4.8, true).size
873
+ assert_equal RaE(2.8...4.8, true).size, RaE(Rational(28,10)...Rational(48,10), true).size
874
+ assert_equal Float::INFINITY, RaE(0..Float::INFINITY, true).size
796
875
  # (0.5...5).size # => 5 (Ruby 2.1)
797
876
  # (Rational(1,2)...5).size # => 4 (Ruby 2.1) => Bug!
798
877
 
878
+ if 4.8-2.8 > 2 # => 2.0000000000000004
879
+ assert_equal 3, RaE(2.8...4.8, true).size
880
+ end
881
+
799
882
  # String
800
883
  rsi = (?a..?d)
801
884
  if rsi.size.nil?
@@ -876,10 +959,17 @@ return
876
959
  # end
877
960
  end
878
961
 
962
+ def test_Infinity_from_obj
963
+ assert_equal( 1, (?a <=> RangeExtd::Infinity::NEGATIVE))
964
+ assert_equal(-1, (?a <=> RangeExtd::Infinity::POSITIVE))
965
+ assert_equal( 1, (Time.now <=> RangeExtd::Infinity::NEGATIVE))
966
+ assert_equal(-1, (Time.now <=> RangeExtd::Infinity::POSITIVE))
967
+ end
968
+
879
969
 
880
970
  def test_Range_valid
881
971
  assert RangeExtd::NONE.valid?
882
- assert RangeExtd::EVERYTHING.valid?
972
+ assert RangeExtd::ALL.valid?
883
973
  assert (1..3).valid?
884
974
  assert !(3..1).valid?
885
975
  assert (?a..?a).valid? # single element
@@ -904,7 +994,7 @@ return
904
994
 
905
995
  def test_Range_empty
906
996
  assert RangeExtd::NONE.empty?
907
- assert !RangeExtd::EVERYTHING.empty?
997
+ assert !RangeExtd::ALL.empty?
908
998
  assert !(1..3).empty?
909
999
  assert_nil (3..1).empty?
910
1000
  assert !(?a..?a).empty? # single element
@@ -933,7 +1023,7 @@ return
933
1023
 
934
1024
  def test_Range_nullfunc
935
1025
  assert RangeExtd::NONE.null?
936
- assert !RangeExtd::EVERYTHING.null?
1026
+ assert !RangeExtd::ALL.null?
937
1027
  assert !(1..3).null?
938
1028
  assert (3..1).null?
939
1029
  assert !(?a..?a).null? # single element
@@ -996,15 +1086,15 @@ return
996
1086
  end
997
1087
 
998
1088
 
999
- def test_RangeExtd_everything
1000
- assert !RangeExtd::EVERYTHING.is_none?
1001
- assert RangeExtd::EVERYTHING.valid?
1002
- assert !RangeExtd::EVERYTHING.null?
1003
- assert !RangeExtd::EVERYTHING.empty?
1004
- assert_equal (-Float::INFINITY..Float::INFINITY), RangeExtd::EVERYTHING
1005
- assert_equal RangeExtd::EVERYTHING, (-Float::INFINITY..Float::INFINITY)
1006
- assert_equal RangeExtd::Infinity::POSITIVE, RangeExtd::EVERYTHING.end
1007
- assert_equal RangeExtd::Infinity::NEGATIVE, RangeExtd::EVERYTHING.begin
1089
+ def test_RangeExtd_all
1090
+ assert !RangeExtd::ALL.is_none?
1091
+ assert RangeExtd::ALL.valid?
1092
+ assert !RangeExtd::ALL.null?
1093
+ assert !RangeExtd::ALL.empty?
1094
+ assert_equal (-Float::INFINITY..Float::INFINITY), RangeExtd::ALL
1095
+ assert_equal RangeExtd::ALL, (-Float::INFINITY..Float::INFINITY)
1096
+ assert_equal RangeExtd::Infinity::POSITIVE, RangeExtd::ALL.end
1097
+ assert_equal RangeExtd::Infinity::NEGATIVE, RangeExtd::ALL.begin
1008
1098
  end
1009
1099
 
1010
1100
  def test_RangeExtd_num
@@ -1147,6 +1237,22 @@ return
1147
1237
  assert_raises(TypeError){ (1.3...5).minmax } # => TypeError: can't iterate from Float
1148
1238
 
1149
1239
  # RangeExtd#size
1240
+ assert_equal 2, (1.4..2.6).size
1241
+ assert_equal 2, (1.4..2.6).size
1242
+ # (2.5...4.5000000000000021).size => 2
1243
+ # (2.8...4.8000000000000021).size => 3
1244
+ assert_equal 3, (2.8..4.8).size
1245
+ assert(RangeExtd(1..5, true, true) == RangeExtd(Rational(1,1), 5, true, true))
1246
+ assert(RangeExtd(1..5, true, true).size != RangeExtd(Rational(1,1), 5, true, true).size)
1247
+ # 4.4 - 2.4 # => 2.0000000000000004
1248
+ # 4.8 - 2.8 # => 2.0
1249
+ assert(! RangeExtd(1..5, true, true).eql?(RangeExtd(Rational(1,1), 5, true, true))) # => false
1250
+ assert_equal [2, 3, 4], RangeExtd(1..5, true, true).to_a # => [2, 3, 4]
1251
+ assert_equal 3, RangeExtd(1..5, true, true).to_a.size # => 3
1252
+ assert_raises(TypeError){ RangeExtd(Rational(1,1)..5).to_a } # => TypeError
1253
+ assert_equal 3, RangeExtd(2.4..4.4, true, true).size # => 3
1254
+ assert_equal 2, RangeExtd(2.8..4.8, true, true).size # => 2
1255
+
1150
1256
  assert_equal 5, (1..5).size
1151
1257
  assert_equal 4, (1...5).size
1152
1258
  assert_equal 5, (0.8...5).size # => 5 # Why???
@@ -1170,7 +1276,7 @@ return
1170
1276
  assert RangeExtd.valid?(0...0, true) # => true
1171
1277
  assert !RangeExtd.valid?(2..-1) # => false
1172
1278
  assert RangeExtd.valid?(RangeExtd::NONE) # => true
1173
- assert RangeExtd.valid?(RangeExtd::EVERYTHING) # => true
1279
+ assert RangeExtd.valid?(RangeExtd::ALL) # => true
1174
1280
  assert RangeExtd.valid?(3..Float::INFINITY) # => true
1175
1281
  assert RangeExtd.valid?(3..Float::INFINITY, true) # => true
1176
1282
  assert RangeExtd.valid?(RangeExtd::Infinity::NEGATIVE..?d) # => true
@@ -1190,7 +1296,7 @@ return
1190
1296
  assert RangeExtd(0...0, true) # => true
1191
1297
  assert (3..Float::INFINITY).valid? # => true
1192
1298
  assert RangeExtd::NONE.valid? # => true
1193
- assert RangeExtd::EVERYTHING.valid? # => true
1299
+ assert RangeExtd::ALL.valid? # => true
1194
1300
 
1195
1301
  # Range.empty?
1196
1302
  assert_equal nil, (nil..nil).empty? # => nil
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: range_extd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masa Sakano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-28 00:00:00.000000000 Z
11
+ date: 2014-04-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: This defines a subclass of Range, RangeExtd and its subclass, RangeExtd::Infinity. The
13
+ description: Package for a subclass of Range, RangeExtd and RangeExtd::Infinity. The
14
14
  former defines a range that enables an exclusion of the begin boundary, in addition
15
15
  to the end boundary as in the built-in Range, and accepts open-ended ranges to infinity
16
16
  for either (or both) positive/negative direction. The latter has the two constant
@@ -23,6 +23,7 @@ extra_rdoc_files:
23
23
  - README.en.rdoc
24
24
  - README.ja.rdoc
25
25
  files:
26
+ - News
26
27
  - ChangeLog
27
28
  - README.en.rdoc
28
29
  - README.ja.rdoc