rangeary 0.2.0 → 0.3.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 +4 -4
- data/ChangeLog +7 -1
- data/lib/rangeary/rangeary.rb +31 -16
- data/rangeary.gemspec +2 -2
- data/test/test_rangeary.rb +63 -9
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a68fed02c28c7598ccd0e5e850012be4d1212948
|
4
|
+
data.tar.gz: a13032cc6cd7020224255079aaf63f6f8d314411
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6124f036424de4b48bbfa1950602677b61ba780c6d686cc95605803ac7d3e49547f36473f58bc1f148f629cdd5bb99e7e526ace4de95a1f2d8d39c9bfc8997ba
|
7
|
+
data.tar.gz: 9bd1973fb2f6006363c7c5f8280a4462fc9f79239aa58183f50f0a899f63816a16b8c5dbf7f8b0e684ee6f7eb2aef191354d7d7abaf057f53ad8f8707d1ca938
|
data/ChangeLog
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
+
-----
|
2
|
+
(Version: 0.3.0)
|
3
|
+
2016-05-27 Masa Sakano
|
4
|
+
* Fixed a bug *,^,- raises an exception when one of them is #null? Added a method #add? Added a file .gitignore in the repository.
|
5
|
+
|
1
6
|
-----
|
2
7
|
(Version: 0.2.0)
|
3
|
-
2014-05-11 Masa
|
8
|
+
2014-05-11 Masa Sakano
|
9
|
+
|
4
10
|
* New method of Rangeary#equiv?(), with the added dependency on range_extd ">= 0.4.0".
|
5
11
|
|
6
12
|
-----
|
data/lib/rangeary/rangeary.rb
CHANGED
@@ -197,8 +197,18 @@ class Rangeary < Array
|
|
197
197
|
self.freeze
|
198
198
|
end # def initialize(*inarall, **opts)
|
199
199
|
|
200
|
+
alias_method :triple_equals_orig, :=== if ! self.method_defined?(:triple_equals_orig)
|
200
201
|
|
201
|
-
|
202
|
+
# If self covers the entire range?
|
203
|
+
#
|
204
|
+
def all?
|
205
|
+
rfirst = self[0]
|
206
|
+
((1 == size) &&
|
207
|
+
(@infinities[:negative] == rfirst.begin) &&
|
208
|
+
(@infinities[:positive] == rfirst.end) &&
|
209
|
+
(!rfirst.exclude_begin?) &&
|
210
|
+
(!rfirst.exclude_end?))
|
211
|
+
end
|
202
212
|
|
203
213
|
# True if the inObj is in the range.
|
204
214
|
#
|
@@ -222,8 +232,8 @@ class Rangeary < Array
|
|
222
232
|
return false
|
223
233
|
end
|
224
234
|
|
225
|
-
|
226
|
-
|
235
|
+
alias_method :include_element?, :===
|
236
|
+
alias_method :member_element?, :===
|
227
237
|
|
228
238
|
|
229
239
|
# @return [Object] The {RangeExtd#begin} of the first {RangeExtd}.
|
@@ -234,7 +244,7 @@ class Rangeary < Array
|
|
234
244
|
nil # Should not happen!
|
235
245
|
end
|
236
246
|
end
|
237
|
-
|
247
|
+
alias_method :begin_element, :begin
|
238
248
|
|
239
249
|
|
240
250
|
# If inObj is within the ranges, it will return true.
|
@@ -286,7 +296,7 @@ class Rangeary < Array
|
|
286
296
|
nil
|
287
297
|
end
|
288
298
|
end
|
289
|
-
|
299
|
+
alias_method :end_element, :end
|
290
300
|
|
291
301
|
|
292
302
|
# {Range#equiv?} method, defined in range_extd library, extended to this {Rangeary}.
|
@@ -423,7 +433,7 @@ class Rangeary < Array
|
|
423
433
|
end
|
424
434
|
return true
|
425
435
|
end
|
426
|
-
|
436
|
+
alias_method :null?, :null_element?
|
427
437
|
|
428
438
|
|
429
439
|
# Return the sum of {RangeExtd#size} of all the ranges in the object.
|
@@ -459,8 +469,8 @@ class Rangeary < Array
|
|
459
469
|
self.class.new(self, inr)
|
460
470
|
end
|
461
471
|
|
462
|
-
|
463
|
-
|
472
|
+
alias_method :+, :disjunction
|
473
|
+
alias_method :|, :disjunction # "|" (plus with Object#eql?) in general, but in this case it is identical.
|
464
474
|
|
465
475
|
# Exclusive Disjunction (XOR) with a Rangeary (or RangeExtd or Range)
|
466
476
|
#
|
@@ -479,8 +489,8 @@ class Rangeary < Array
|
|
479
489
|
(disjunction(inr)).conjunction(conjunction(inr).negation)
|
480
490
|
end
|
481
491
|
|
482
|
-
|
483
|
-
|
492
|
+
alias_method :^, :exclusive_disjunction
|
493
|
+
alias_method :xor, :exclusive_disjunction
|
484
494
|
|
485
495
|
# Subtraction.
|
486
496
|
#
|
@@ -490,7 +500,7 @@ class Rangeary < Array
|
|
490
500
|
conjunction( Rangeary.new(r).negation )
|
491
501
|
end
|
492
502
|
|
493
|
-
|
503
|
+
alias_method :-, :subtraction
|
494
504
|
|
495
505
|
|
496
506
|
# Conjunction.
|
@@ -501,8 +511,8 @@ class Rangeary < Array
|
|
501
511
|
self.class.conjunction(self, r)
|
502
512
|
end
|
503
513
|
|
504
|
-
|
505
|
-
|
514
|
+
alias_method :&, :conjunction
|
515
|
+
alias_method :*, :conjunction
|
506
516
|
|
507
517
|
|
508
518
|
# Negation.
|
@@ -564,7 +574,7 @@ class Rangeary < Array
|
|
564
574
|
Rangeary.new(arran, :positive => @infinities[:positive], :negative => @infinities[:negative])
|
565
575
|
end # def negation()
|
566
576
|
|
567
|
-
|
577
|
+
alias_method :~@, :negation
|
568
578
|
|
569
579
|
|
570
580
|
####################
|
@@ -580,6 +590,9 @@ class Rangeary < Array
|
|
580
590
|
|
581
591
|
r1 = Rangeary.new(r1) if ! defined? r1.first_element
|
582
592
|
r2 = Rangeary.new(r2) if ! defined? r2.first_element
|
593
|
+
return Rangeary.new(RangeExtd::NONE) if r1.null? || r2.null?
|
594
|
+
return Rangeary.new(r1) if r2.all?
|
595
|
+
return Rangeary.new(r2) if r1.all?
|
583
596
|
|
584
597
|
# Getting inherited options (if Rangeary is given) for the later use.
|
585
598
|
hsInherited = {}
|
@@ -848,8 +861,9 @@ class Rangeary < Array
|
|
848
861
|
end
|
849
862
|
end
|
850
863
|
|
851
|
-
|
864
|
+
hsFlag[:found?] = false # Redundant, but for the sake of readability
|
852
865
|
if hsFlag[:empty?]
|
866
|
+
# It is all empty, hence delete all but one.
|
853
867
|
hsFlag[:klass] = NilClass if hsFlag[:klass].nil?
|
854
868
|
newRanges.delete_if do |er|
|
855
869
|
if hsFlag[:found?]
|
@@ -862,7 +876,8 @@ class Rangeary < Array
|
|
862
876
|
end
|
863
877
|
end
|
864
878
|
else
|
865
|
-
|
879
|
+
# Deletes all the empty ones.
|
880
|
+
newRanges.delete_if { |er| er.empty? }
|
866
881
|
end
|
867
882
|
|
868
883
|
newRanges
|
data/rangeary.gemspec
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{rangeary}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.3.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{
|
10
|
+
s.date = %q{2016-05-27}
|
11
11
|
s.summary = %q{Rangeary - class to represent any 1-dimensional multiple-range}
|
12
12
|
s.description = %q{Rangeary is a sub-class of Array and represents any 1-dimensional multiple-range. For example, (x<4 and 7<x<=9). All the standard logical operations, such as negation and conjunction, are supported and can be used with conventional Ruby-style operators. Each range is represented as RangeExtd class (Extended Range), which is a sub-class of Range and supports exclude-begin and open-ended (to Infinity) ranges, and is downloadable from https://rubygems.org/gems/range_extd}
|
13
13
|
# s.email = %q{abc@example.com}
|
data/test/test_rangeary.rb
CHANGED
@@ -52,7 +52,7 @@ end
|
|
52
52
|
#################################################
|
53
53
|
|
54
54
|
#if $0 == __FILE__
|
55
|
-
require 'minitest/unit'
|
55
|
+
# require 'minitest/unit'
|
56
56
|
require 'minitest/autorun'
|
57
57
|
# MiniTest::Unit.autorun
|
58
58
|
|
@@ -139,10 +139,13 @@ end
|
|
139
139
|
def RaE(*rest)
|
140
140
|
RangeExtd(*rest)
|
141
141
|
end
|
142
|
-
T = true
|
143
|
-
F = false
|
144
142
|
|
145
|
-
class TestUnitFoo < MiniTest::
|
143
|
+
class TestUnitFoo < MiniTest::Test
|
144
|
+
T = true
|
145
|
+
F = false
|
146
|
+
RaN = Rangeary(RangeExtd::NONE)
|
147
|
+
RaA = Rangeary(RangeExtd::ALL)
|
148
|
+
|
146
149
|
def setup
|
147
150
|
@ib = 1
|
148
151
|
@ie = 6
|
@@ -238,10 +241,17 @@ end
|
|
238
241
|
def test_disjunction
|
239
242
|
# Plus
|
240
243
|
rs = Rangeary.new([3..5, -6..-1, -4..-3, 2..4, 8..8])
|
241
|
-
assert_equal [-6..-1, 2..5, 8..8], (rs+rs).to_a
|
242
244
|
assert_equal rs, rs+rs
|
245
|
+
assert_equal [-6..-1, 2..5, 8..8], rs.to_a
|
246
|
+
assert_equal rs.to_a, (rs+rs).to_a
|
247
|
+
assert_equal rs.to_a, (rs+RaN).to_a
|
248
|
+
assert_equal rs.to_a, (RaN+rs).to_a
|
243
249
|
assert_equal [-6..-1, 2..5, 8..9], (rs+(8..9)).to_a
|
244
250
|
assert (rs != (rs+(8..9)))
|
251
|
+
assert_equal RaN, RaN + RaN
|
252
|
+
assert_equal RaA, RaA + RaA
|
253
|
+
assert_equal RaA, RaA + RaN
|
254
|
+
assert_equal RaA, RaN + RaA
|
245
255
|
end # def test_disjunction
|
246
256
|
|
247
257
|
def test_minus
|
@@ -271,6 +281,10 @@ end
|
|
271
281
|
assert_equal [-6..-1, 2...4], (rs-(4..11)).to_a
|
272
282
|
#assert_equal [-6..-1, 2..3], (rs-(4..11)).to_a
|
273
283
|
assert_equal rs, rs-(-99..-95)
|
284
|
+
assert_equal rs, rs-RaN
|
285
|
+
assert_equal RaN, RaN-rs
|
286
|
+
assert_equal RaN, RaN-RaN
|
287
|
+
assert_equal RaN, RaA-RaA
|
274
288
|
end # def test_minus
|
275
289
|
|
276
290
|
|
@@ -281,11 +295,12 @@ end
|
|
281
295
|
assert_equal ar[-1], rs[-1]
|
282
296
|
assert_equal ar[1..2], rs[1..2]
|
283
297
|
assert_equal ar[0,2], rs[0,2]
|
298
|
+
assert_equal RangeExtd::NONE, RaN[0]
|
299
|
+
assert_equal nil, RaN[1]
|
284
300
|
end
|
285
301
|
|
286
302
|
|
287
303
|
def test_conjunctionRangeExtd
|
288
|
-
t = true
|
289
304
|
r38 = RangeExtd(3..8, :exclude_begin => 1)
|
290
305
|
r38e = RangeExtd(3...8, :exclude_begin => 1)
|
291
306
|
r39 = RangeExtd(3..9, :exclude_begin => 1)
|
@@ -371,8 +386,8 @@ end
|
|
371
386
|
assert_equal (?d..?f), conjRE(?a..?f, ?d..?z)
|
372
387
|
|
373
388
|
# Empty
|
374
|
-
assert_equal RangeExtd::NONE, conjRE(RangeExtd(1,1,
|
375
|
-
assert_equal RangeExtd::NONE, conjRE(0..8, RangeExtd(1,1,
|
389
|
+
assert_equal RangeExtd::NONE, conjRE(RangeExtd(1,1,T,T), 0..8)
|
390
|
+
assert_equal RangeExtd::NONE, conjRE(0..8, RangeExtd(1,1,T,T))
|
376
391
|
assert_equal RangeExtd::NONE, conjRE(RangeExtd::NONE, ?a..?d)
|
377
392
|
assert_equal RangeExtd::NONE, conjRE(?a..?d, RangeExtd::NONE)
|
378
393
|
|
@@ -380,7 +395,7 @@ end
|
|
380
395
|
assert_raises(ArgumentError){ conjRE(true..true, true..true) }
|
381
396
|
assert_raises(TypeError){ conjRE(1..5, ?a..?d) }
|
382
397
|
|
383
|
-
assert_equal RangeExtd(24...25,
|
398
|
+
assert_equal RangeExtd(24...25,T), conjRE(RangeExtd(24..26,T), 24...25)
|
384
399
|
end
|
385
400
|
|
386
401
|
|
@@ -402,6 +417,15 @@ end
|
|
402
417
|
assert rcab.empty_element?
|
403
418
|
assert rcab.null_element?
|
404
419
|
assert rcab.null?
|
420
|
+
|
421
|
+
assert_equal r1, r1 * Rangeary(RangeExtd::ALL)
|
422
|
+
assert_equal r1, Rangeary(RangeExtd::ALL) * r1
|
423
|
+
|
424
|
+
assert_equal RaN, r1 * RaN
|
425
|
+
assert_equal RaN, r1 * RaN
|
426
|
+
assert_equal RaN, RaN * r1
|
427
|
+
assert_equal RaN, RaN * RaN
|
428
|
+
assert_equal RaA, RaA * RaA
|
405
429
|
end # def test_conjunctionRangeary
|
406
430
|
|
407
431
|
|
@@ -438,6 +462,16 @@ end
|
|
438
462
|
assert_equal rc12tobe, rc12
|
439
463
|
# Actual: <Rangeary:[-Infinity..1, 3...4, 6<...8, 8<...12, 12<...14, 15...17, 18<..22, 24..26, 28..32, 33..Infinity]>
|
440
464
|
|
465
|
+
assert_equal r1, r1.disjunction(RaN)
|
466
|
+
assert_equal true, r1.conjunction(RaN).null?
|
467
|
+
assert_equal Rangeary(RangeExtd::ALL), r1.conjunction(RaN).negation
|
468
|
+
assert_equal r1, r1 * (r1.conjunction(RaN).negation)
|
469
|
+
assert_equal r1, r1 ^ RaN
|
470
|
+
assert_equal r1, RaN ^ r1
|
471
|
+
assert_equal RaN, RaN ^ RaN
|
472
|
+
assert_equal RaA, RaA ^ RaN
|
473
|
+
assert_equal RaA, RaN ^ RaA
|
474
|
+
assert_equal RaN, RaA ^ RaA
|
441
475
|
end # def test_xor
|
442
476
|
|
443
477
|
|
@@ -446,6 +480,7 @@ end
|
|
446
480
|
assert_equal Rangeary(-inf...3,RangeExtd(8..inf,1)), Rangeary(3..8).negation
|
447
481
|
assert_equal Rangeary(-inf...12, RangeExtd(12...14,T), RangeExtd(15,inf,T)), ~Rangeary(12..12, 14..15)
|
448
482
|
|
483
|
+
assert_equal Rangeary(RangeExtd::ALL), ~RaN
|
449
484
|
end # def test_negation
|
450
485
|
|
451
486
|
|
@@ -483,6 +518,9 @@ end
|
|
483
518
|
|
484
519
|
assert ! Rangeary(?a..?g, ?m..?o, ?r..?z).cover?(?h)
|
485
520
|
assert !(r1 === RangeExtd(?a..?g))
|
521
|
+
|
522
|
+
assert !RaN.cover?('pp')
|
523
|
+
assert !RaN.cover?(5)
|
486
524
|
end
|
487
525
|
|
488
526
|
def test_each
|
@@ -501,6 +539,12 @@ end
|
|
501
539
|
assert_equal(-6, i)
|
502
540
|
break
|
503
541
|
end
|
542
|
+
|
543
|
+
n = 0
|
544
|
+
rs.each_element do |i|
|
545
|
+
n += 1
|
546
|
+
end
|
547
|
+
assert_equal n, 6+4+2
|
504
548
|
end # def test_each_element
|
505
549
|
|
506
550
|
|
@@ -529,6 +573,16 @@ end
|
|
529
573
|
end # def test_size_element
|
530
574
|
|
531
575
|
|
576
|
+
def test_hash
|
577
|
+
assert_equal Rangeary(1...4).hash, Rangeary(1...4).hash
|
578
|
+
assert_equal Rangeary(?a..?c).hash, Rangeary('A'.downcase..?c).hash
|
579
|
+
assert_equal Rangeary(1...4, RangeExtd(6...9,T)).hash, Rangeary(1...4, RangeExtd(6...9,T)).hash
|
580
|
+
assert(Rangeary(1...4).hash != (1...4).hash)
|
581
|
+
assert(Rangeary(1...4).hash != Rangeary(1..4).hash)
|
582
|
+
assert(Rangeary(1...4, RangeExtd(6...9,F)).hash != Rangeary(1...4, RangeExtd(6...9,T)).hash)
|
583
|
+
end # def test_hash
|
584
|
+
|
585
|
+
|
532
586
|
def test_in_document
|
533
587
|
assert Rangeary(RangeExtd(1,"<...",4), 5...8).equiv?(Rangeary(2..3, 5..7)) # => true
|
534
588
|
assert_equal 33, Rangeary(2...4, 5..6, 8..9).flatten.reduce(:+) # => 33
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rangeary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.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:
|
11
|
+
date: 2016-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: range_extd
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.4.0
|
20
20
|
type: :runtime
|
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.4.0
|
27
27
|
description: Rangeary is a sub-class of Array and represents any 1-dimensional multiple-range. For
|
@@ -36,12 +36,12 @@ extensions: []
|
|
36
36
|
extra_rdoc_files:
|
37
37
|
- README.ja.rdoc
|
38
38
|
files:
|
39
|
-
- News
|
40
39
|
- ChangeLog
|
40
|
+
- News
|
41
41
|
- README.ja.rdoc
|
42
42
|
- Rakefile
|
43
|
-
- rangeary.gemspec
|
44
43
|
- lib/rangeary/rangeary.rb
|
44
|
+
- rangeary.gemspec
|
45
45
|
- test/test_rangeary.rb
|
46
46
|
homepage:
|
47
47
|
licenses:
|
@@ -49,22 +49,22 @@ licenses:
|
|
49
49
|
metadata: {}
|
50
50
|
post_install_message:
|
51
51
|
rdoc_options:
|
52
|
-
- --charset=UTF-8
|
52
|
+
- "--charset=UTF-8"
|
53
53
|
require_paths:
|
54
54
|
- lib
|
55
55
|
required_ruby_version: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
|
-
- -
|
57
|
+
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
59
|
version: '2.0'
|
60
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
61
|
requirements:
|
62
|
-
- -
|
62
|
+
- - ">="
|
63
63
|
- !ruby/object:Gem::Version
|
64
64
|
version: '0'
|
65
65
|
requirements: []
|
66
66
|
rubyforge_project:
|
67
|
-
rubygems_version: 2.
|
67
|
+
rubygems_version: 2.5.1
|
68
68
|
signing_key:
|
69
69
|
specification_version: 4
|
70
70
|
summary: Rangeary - class to represent any 1-dimensional multiple-range
|