mug 0.5.3 → 0.5.4

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mug/and-or.rb +26 -26
  3. data/lib/mug/any-and-all.rb +16 -16
  4. data/lib/mug/apply.rb +37 -37
  5. data/lib/mug/array/extend.rb +43 -43
  6. data/lib/mug/array/minus.rb +32 -32
  7. data/lib/mug/bool.rb +71 -71
  8. data/lib/mug/clamp.rb +35 -35
  9. data/lib/mug/counts.rb +27 -27
  10. data/lib/mug/fragile-method-chain.rb +42 -42
  11. data/lib/mug/hash/map.rb +75 -75
  12. data/lib/mug/hash/operations.rb +47 -47
  13. data/lib/mug/iterator/for.rb +7 -7
  14. data/lib/mug/iterator/method.rb +7 -7
  15. data/lib/mug/iterator_c.rb +14 -14
  16. data/lib/mug/loop-with.rb +30 -29
  17. data/lib/mug/matchdata/each.rb +40 -40
  18. data/lib/mug/matchdata/hash.rb +29 -29
  19. data/lib/mug/maybe.rb +33 -33
  20. data/lib/mug/negativity.rb +20 -20
  21. data/lib/mug/not.rb +6 -6
  22. data/lib/mug/rexproc.rb +6 -6
  23. data/lib/mug/self.rb +31 -31
  24. data/lib/mug/to_h.rb +2 -2
  25. data/lib/mug/top.rb +100 -100
  26. data/test/test-and-or.rb +32 -32
  27. data/test/test-any-and-all.rb +19 -19
  28. data/test/test-apply.rb +47 -47
  29. data/test/test-array-extend.rb +54 -54
  30. data/test/test-array-minus.rb +11 -11
  31. data/test/test-bool.rb +48 -48
  32. data/test/test-clamp.rb +42 -42
  33. data/test/test-counts.rb +21 -21
  34. data/test/test-fragile-method-chain.rb +56 -56
  35. data/test/test-hashmap.rb +14 -14
  36. data/test/test-hashop.rb +47 -47
  37. data/test/test-iterator-for.rb +12 -12
  38. data/test/test-loop-with.rb +117 -66
  39. data/test/test-matchdata_each.rb +50 -50
  40. data/test/test-matchdata_hash.rb +40 -40
  41. data/test/test-maybe.rb +76 -76
  42. data/test/test-negativity.rb +40 -40
  43. data/test/test-not.rb +53 -53
  44. data/test/test-rexproc.rb +6 -6
  45. data/test/test-self.rb +21 -21
  46. data/test/test-tau.rb +12 -12
  47. data/test/test-top.rb +100 -100
  48. metadata +4 -4
@@ -3,45 +3,45 @@ $VERBOSE = true
3
3
 
4
4
  require_relative '../lib/mug/matchdata/hash'
5
5
  class Test_matchdata_hash < Test::Unit::TestCase
6
- def test__matchdata__to_h
7
- str = 'a12b'
8
- [
9
- [/( \d)( \d)/x.match(str), { 1 =>'1', 2 =>'2'}],
10
- [/(?<x>\d)(?<y>\d)/x.match(str), {'x'=>'1', 'y'=>'2'}],
11
- [/( \d)(?<y>\d)/x.match(str), { 'y'=>'2'}], # ):
12
- ].each do |m, x|
13
- assert_equal( x, m.to_h )
14
- end
15
- end
16
- def test__matchdata__named_captures
17
- str = 'a12b'
18
- [
19
- [/( \d)( \d)/x.match(str), { }],
20
- [/(?<x>\d)(?<y>\d)/x.match(str), {'x'=>'1', 'y'=>'2'}],
21
- [/( \d)(?<y>\d)/x.match(str), { 'y'=>'2'}],
22
- ].each do |m, x|
23
- assert_equal( x, m.named_captures )
24
- end
25
- end
26
- def test__matchdata__positional_captures
27
- str = 'a12b'
28
- [
29
- [/( \d)( \d)/x.match(str), { 1 =>'1', 2 =>'2'}],
30
- [/(?<x>\d)(?<y>\d)/x.match(str), { }],
31
- [/( \d)(?<y>\d)/x.match(str), { }], # D:
32
- ].each do |m, x|
33
- assert_equal( x, m.positional_captures )
34
- end
35
- end
36
- def test__matchdata__positional_captures2
37
- str = 'a12b'
38
- [
39
- [/( \d)( \d)/x.match(str), { 1 =>'1', 2 =>'2'}],
40
- [/(?<x>\d)(?<y>\d)/x.match(str), { 1 =>'1', 2 =>'2'}],
41
- [/( \d)(?<y>\d)/x.match(str), { 1 =>'2'}], # ):
42
- ].each do |m, x|
43
- assert_equal( x, m.positional_captures(include_names: true) )
44
- end
45
- end
6
+ def test__matchdata__to_h
7
+ str = 'a12b'
8
+ [
9
+ [/( \d)( \d)/x.match(str), { 1 =>'1', 2 =>'2'}],
10
+ [/(?<x>\d)(?<y>\d)/x.match(str), {'x'=>'1', 'y'=>'2'}],
11
+ [/( \d)(?<y>\d)/x.match(str), { 'y'=>'2'}], # ):
12
+ ].each do |m, x|
13
+ assert_equal( x, m.to_h )
14
+ end
15
+ end
16
+ def test__matchdata__named_captures
17
+ str = 'a12b'
18
+ [
19
+ [/( \d)( \d)/x.match(str), { }],
20
+ [/(?<x>\d)(?<y>\d)/x.match(str), {'x'=>'1', 'y'=>'2'}],
21
+ [/( \d)(?<y>\d)/x.match(str), { 'y'=>'2'}],
22
+ ].each do |m, x|
23
+ assert_equal( x, m.named_captures )
24
+ end
25
+ end
26
+ def test__matchdata__positional_captures
27
+ str = 'a12b'
28
+ [
29
+ [/( \d)( \d)/x.match(str), { 1 =>'1', 2 =>'2'}],
30
+ [/(?<x>\d)(?<y>\d)/x.match(str), { }],
31
+ [/( \d)(?<y>\d)/x.match(str), { }], # D:
32
+ ].each do |m, x|
33
+ assert_equal( x, m.positional_captures )
34
+ end
35
+ end
36
+ def test__matchdata__positional_captures2
37
+ str = 'a12b'
38
+ [
39
+ [/( \d)( \d)/x.match(str), { 1 =>'1', 2 =>'2'}],
40
+ [/(?<x>\d)(?<y>\d)/x.match(str), { 1 =>'1', 2 =>'2'}],
41
+ [/( \d)(?<y>\d)/x.match(str), { 1 =>'2'}], # ):
42
+ ].each do |m, x|
43
+ assert_equal( x, m.positional_captures(include_names: true) )
44
+ end
45
+ end
46
46
  end
47
47
 
@@ -2,89 +2,89 @@ require 'test/unit'
2
2
  $VERBOSE = true
3
3
 
4
4
  module MaybeTest
5
- class A
6
- def initialize; @b = B.new; end
7
- attr_accessor :b
8
- end
5
+ class A
6
+ def initialize; @b = B.new; end
7
+ attr_accessor :b
8
+ end
9
9
 
10
- class B
11
- def initialize; @c = C.new; end
12
- attr_accessor :c
13
- end
10
+ class B
11
+ def initialize; @c = C.new; end
12
+ attr_accessor :c
13
+ end
14
14
 
15
- class C
16
- def to_i; 1; end
17
- end
15
+ class C
16
+ def to_i; 1; end
17
+ end
18
18
  end
19
19
 
20
20
  def false.c
21
- 2
21
+ 2
22
22
  end
23
23
 
24
24
  require_relative '../lib/mug/maybe'
25
25
  class Test_maybe < Test::Unit::TestCase
26
- def test_maybe_block_nil
27
- a = MaybeTest::A.new
28
- assert_equal( 1, a.maybe{ b.maybe{ c } }.to_i )
29
- assert_equal( 1, a.maybe{ b.c.to_i } )
30
- assert_equal( 1, a.maybe{ b }.c.to_i )
31
- a.b.c = nil
32
- assert_equal( 0, a.maybe{ b.maybe{ c } }.to_i )
33
- assert_equal( 0, a.maybe{ b.c.to_i } )
34
- assert_equal( 0, a.maybe{ b }.c.to_i )
35
- a.b = nil
36
- assert_nil( a.maybe{ b.maybe{ c } } )
37
- assert_raise(NoMethodError) { a.maybe{ b.c } }
38
- assert_raise(NoMethodError) { a.maybe{ b }.c }
39
- a = nil
40
- assert_nil( a.maybe{ b.maybe{ c } } )
41
- assert_nil( a.maybe{ b.c } )
42
- assert_raise(NoMethodError) { a.maybe{ b }.c }
43
- end
44
- def test_maybe_block_false
45
- a = MaybeTest::A.new
46
- assert_equal( 1, a.maybe{ b.maybe{ c } }.to_i )
47
- assert_equal( 1, a.maybe{ b.c.to_i } )
48
- assert_equal( 1, a.maybe{ b }.c.to_i )
49
- a.b.c = false
50
- assert_raise(NoMethodError) { a.maybe{ b.maybe{ c } }.to_i }
51
- assert_raise(NoMethodError) { a.maybe{ b.c.to_i } }
52
- assert_raise(NoMethodError) { a.maybe{ b }.c.to_i }
53
- a.b = false
54
- assert_equal( false, a.maybe{ b.maybe{ c } } )
55
- assert_equal( 2, a.maybe{ b.c } )
56
- assert_equal( 2, a.maybe{ b }.c )
57
- a = false
58
- assert_equal( false, a.maybe{ b.maybe{ c } } )
59
- assert_equal( false, a.maybe{ b.c } )
60
- assert_equal( 2, a.maybe{ b }.c )
61
- end
62
- def test_maybe_delegator_nil
63
- a = MaybeTest::A.new
64
- assert_equal( 1, a.maybe.b.maybe.c.to_i )
65
- assert_equal( 1, a.maybe.b.c.to_i )
66
- a.b.c = nil
67
- assert_nil( a.maybe.b.maybe.c )
68
- assert_nil( a.maybe.b.c )
69
- a.b = nil
70
- assert_nil( a.maybe.b.maybe.c )
71
- assert_raise(NoMethodError) { a.maybe.b.c }
72
- a = nil
73
- assert_nil( a.maybe.b.maybe.c )
74
- assert_raise(NoMethodError) { a.maybe.b.c }
75
- end
76
- def test_maybe_delegator_false
77
- a = MaybeTest::A.new
78
- assert_equal( 1, a.maybe.b.maybe.c.to_i )
79
- assert_equal( 1, a.maybe.b.c.to_i )
80
- a.b.c = false
81
- assert_equal( false, a.maybe.b.maybe.c )
82
- assert_equal( false, a.maybe.b.c )
83
- a.b = false
84
- assert_equal( false, a.maybe.b.maybe.c )
85
- assert_equal( 2, a.maybe.b.c )
86
- a = false
87
- assert_equal( false, a.maybe.b.maybe.c )
88
- assert_equal( 2, a.maybe.b.c )
89
- end
26
+ def test_maybe_block_nil
27
+ a = MaybeTest::A.new
28
+ assert_equal( 1, a.maybe{ b.maybe{ c } }.to_i )
29
+ assert_equal( 1, a.maybe{ b.c.to_i } )
30
+ assert_equal( 1, a.maybe{ b }.c.to_i )
31
+ a.b.c = nil
32
+ assert_equal( 0, a.maybe{ b.maybe{ c } }.to_i )
33
+ assert_equal( 0, a.maybe{ b.c.to_i } )
34
+ assert_equal( 0, a.maybe{ b }.c.to_i )
35
+ a.b = nil
36
+ assert_nil( a.maybe{ b.maybe{ c } } )
37
+ assert_raise(NoMethodError) { a.maybe{ b.c } }
38
+ assert_raise(NoMethodError) { a.maybe{ b }.c }
39
+ a = nil
40
+ assert_nil( a.maybe{ b.maybe{ c } } )
41
+ assert_nil( a.maybe{ b.c } )
42
+ assert_raise(NoMethodError) { a.maybe{ b }.c }
43
+ end
44
+ def test_maybe_block_false
45
+ a = MaybeTest::A.new
46
+ assert_equal( 1, a.maybe{ b.maybe{ c } }.to_i )
47
+ assert_equal( 1, a.maybe{ b.c.to_i } )
48
+ assert_equal( 1, a.maybe{ b }.c.to_i )
49
+ a.b.c = false
50
+ assert_raise(NoMethodError) { a.maybe{ b.maybe{ c } }.to_i }
51
+ assert_raise(NoMethodError) { a.maybe{ b.c.to_i } }
52
+ assert_raise(NoMethodError) { a.maybe{ b }.c.to_i }
53
+ a.b = false
54
+ assert_equal( false, a.maybe{ b.maybe{ c } } )
55
+ assert_equal( 2, a.maybe{ b.c } )
56
+ assert_equal( 2, a.maybe{ b }.c )
57
+ a = false
58
+ assert_equal( false, a.maybe{ b.maybe{ c } } )
59
+ assert_equal( false, a.maybe{ b.c } )
60
+ assert_equal( 2, a.maybe{ b }.c )
61
+ end
62
+ def test_maybe_delegator_nil
63
+ a = MaybeTest::A.new
64
+ assert_equal( 1, a.maybe.b.maybe.c.to_i )
65
+ assert_equal( 1, a.maybe.b.c.to_i )
66
+ a.b.c = nil
67
+ assert_nil( a.maybe.b.maybe.c )
68
+ assert_nil( a.maybe.b.c )
69
+ a.b = nil
70
+ assert_nil( a.maybe.b.maybe.c )
71
+ assert_raise(NoMethodError) { a.maybe.b.c }
72
+ a = nil
73
+ assert_nil( a.maybe.b.maybe.c )
74
+ assert_raise(NoMethodError) { a.maybe.b.c }
75
+ end
76
+ def test_maybe_delegator_false
77
+ a = MaybeTest::A.new
78
+ assert_equal( 1, a.maybe.b.maybe.c.to_i )
79
+ assert_equal( 1, a.maybe.b.c.to_i )
80
+ a.b.c = false
81
+ assert_equal( false, a.maybe.b.maybe.c )
82
+ assert_equal( false, a.maybe.b.c )
83
+ a.b = false
84
+ assert_equal( false, a.maybe.b.maybe.c )
85
+ assert_equal( 2, a.maybe.b.c )
86
+ a = false
87
+ assert_equal( false, a.maybe.b.maybe.c )
88
+ assert_equal( 2, a.maybe.b.c )
89
+ end
90
90
  end
@@ -11,46 +11,46 @@ $err = [ Complex(1,1) ]
11
11
  require_relative '../lib/mug/negativity'
12
12
  class Test_negativity < Test::Unit::TestCase
13
13
 
14
- alias :assert_true :assert
15
- def assert_false val, msg=UNASSIGNED
16
- assert !val, msg
17
- end
18
-
19
- def test_negative
20
- $neg.each {|n| assert_true n.negative?, "#{n} should be negative" }
21
- $pos.each {|n| assert_false n.negative?, "#{n} should not be negative" }
22
- $zer.each {|n| assert_false n.negative?, "#{n} should not be negative" }
23
- $err.each do |n|
24
- assert_raise(NoMethodError) { n.negative? }
25
- end
26
- end
27
-
28
- def test_positive
29
- $neg.each {|n| assert_false n.positive?, "#{n} should not be positive" }
30
- $pos.each {|n| assert_true n.positive?, "#{n} should be positive" }
31
- $zer.each {|n| assert_false n.positive?, "#{n} should not be positive" }
32
- $err.each do |n|
33
- assert_raise(NoMethodError) { n.positive? }
34
- end
35
- end
36
-
37
- def test_nonnegative
38
- $neg.each {|n| assert_false n.nonnegative?, "#{n} should not be nonnegative" }
39
- $pos.each {|n| assert_true n.nonnegative?, "#{n} should be nonnegative" }
40
- $zer.each {|n| assert_true n.nonnegative?, "#{n} should be nonnegative" }
41
- $err.each do |n|
42
- assert_raise(NoMethodError) { n.nonnegative? }
43
- end
44
- end
45
-
46
- def test_nonpositive
47
- $neg.each {|n| assert_true n.nonpositive?, "#{n} should be nonpositive" }
48
- $pos.each {|n| assert_false n.nonpositive?, "#{n} should not be nonpositive" }
49
- $zer.each {|n| assert_true n.nonpositive?, "#{n} should be nonpositive" }
50
- $err.each do |n|
51
- assert_raise(NoMethodError) { n.nonpositive? }
52
- end
53
- end
14
+ alias :assert_true :assert
15
+ def assert_false val, msg=UNASSIGNED
16
+ assert !val, msg
17
+ end
18
+
19
+ def test_negative
20
+ $neg.each {|n| assert_true n.negative?, "#{n} should be negative" }
21
+ $pos.each {|n| assert_false n.negative?, "#{n} should not be negative" }
22
+ $zer.each {|n| assert_false n.negative?, "#{n} should not be negative" }
23
+ $err.each do |n|
24
+ assert_raise(NoMethodError) { n.negative? }
25
+ end
26
+ end
27
+
28
+ def test_positive
29
+ $neg.each {|n| assert_false n.positive?, "#{n} should not be positive" }
30
+ $pos.each {|n| assert_true n.positive?, "#{n} should be positive" }
31
+ $zer.each {|n| assert_false n.positive?, "#{n} should not be positive" }
32
+ $err.each do |n|
33
+ assert_raise(NoMethodError) { n.positive? }
34
+ end
35
+ end
36
+
37
+ def test_nonnegative
38
+ $neg.each {|n| assert_false n.nonnegative?, "#{n} should not be nonnegative" }
39
+ $pos.each {|n| assert_true n.nonnegative?, "#{n} should be nonnegative" }
40
+ $zer.each {|n| assert_true n.nonnegative?, "#{n} should be nonnegative" }
41
+ $err.each do |n|
42
+ assert_raise(NoMethodError) { n.nonnegative? }
43
+ end
44
+ end
45
+
46
+ def test_nonpositive
47
+ $neg.each {|n| assert_true n.nonpositive?, "#{n} should be nonpositive" }
48
+ $pos.each {|n| assert_false n.nonpositive?, "#{n} should not be nonpositive" }
49
+ $zer.each {|n| assert_true n.nonpositive?, "#{n} should be nonpositive" }
50
+ $err.each do |n|
51
+ assert_raise(NoMethodError) { n.nonpositive? }
52
+ end
53
+ end
54
54
 
55
55
  end
56
56
 
@@ -3,58 +3,58 @@ $VERBOSE = true
3
3
 
4
4
  require_relative '../lib/mug/not'
5
5
  class Test_not < Test::Unit::TestCase
6
- def test_not__noargs
7
- [
8
- [true, false],
9
- [99, false],
10
- [false, true],
11
- [nil, true],
12
- ].each do |o, x|
13
- assert_equal( x, o.not, "#{o.inspect}.not should be #{x}" )
14
- end
15
- end
16
- def test_not__method
17
- [
18
- [[], false],
19
- [[99], true],
20
- ].each do |o, x|
21
- assert_equal( x, o.not(:empty?), "#{o.inspect}.not(:empty?) should be #{x}" )
22
- end
23
- end
24
- def test_not__method2
25
- [
26
- [[], false],
27
- [[99], true],
28
- ].each do |o, x|
29
- assert_equal( x, o.not(&:empty?), "#{o.inspect}.not(&:empty?) should be #{x}" )
30
- end
31
- end
32
- def test_not__args
33
- [
34
- [1, true],
35
- [0, true],
36
- [-1, false],
37
- ].each do |o, x|
38
- assert_equal( x, o.not(:<, 0), "#{o.inspect}.not(:<, 0) should be #{x}" )
39
- end
40
- end
6
+ def test_not__noargs
7
+ [
8
+ [true, false],
9
+ [99, false],
10
+ [false, true],
11
+ [nil, true],
12
+ ].each do |o, x|
13
+ assert_equal( x, o.not, "#{o.inspect}.not should be #{x}" )
14
+ end
15
+ end
16
+ def test_not__method
17
+ [
18
+ [[], false],
19
+ [[99], true],
20
+ ].each do |o, x|
21
+ assert_equal( x, o.not(:empty?), "#{o.inspect}.not(:empty?) should be #{x}" )
22
+ end
23
+ end
24
+ def test_not__method2
25
+ [
26
+ [[], false],
27
+ [[99], true],
28
+ ].each do |o, x|
29
+ assert_equal( x, o.not(&:empty?), "#{o.inspect}.not(&:empty?) should be #{x}" )
30
+ end
31
+ end
32
+ def test_not__args
33
+ [
34
+ [1, true],
35
+ [0, true],
36
+ [-1, false],
37
+ ].each do |o, x|
38
+ assert_equal( x, o.not(:<, 0), "#{o.inspect}.not(:<, 0) should be #{x}" )
39
+ end
40
+ end
41
41
 
42
- def test_not__block
43
- [
44
- [1, true],
45
- [0, true],
46
- [-1, false],
47
- ].each do |o, x|
48
- assert_equal( x, o.not {|obj| obj < 0 }, "#{o.inspect}.not{|obj|obj<0} should be #{x}" )
49
- end
50
- end
51
- def test_not__method_block
52
- [
53
- [[], true],
54
- [[0,-1], true],
55
- [[0,99], false],
56
- ].each do |o, x|
57
- assert_equal( x, o.not(:any?) {|item| item > 0 }, "#{o.inspect}.not(:any?){|item|item>0} should be #{x}" )
58
- end
59
- end
42
+ def test_not__block
43
+ [
44
+ [1, true],
45
+ [0, true],
46
+ [-1, false],
47
+ ].each do |o, x|
48
+ assert_equal( x, o.not {|obj| obj < 0 }, "#{o.inspect}.not{|obj|obj<0} should be #{x}" )
49
+ end
50
+ end
51
+ def test_not__method_block
52
+ [
53
+ [[], true],
54
+ [[0,-1], true],
55
+ [[0,99], false],
56
+ ].each do |o, x|
57
+ assert_equal( x, o.not(:any?) {|item| item > 0 }, "#{o.inspect}.not(:any?){|item|item>0} should be #{x}" )
58
+ end
59
+ end
60
60
  end