mug 0.0.8 → 0.1.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/lib/mug.rb +13 -12
- data/lib/mug/and-or.rb +48 -48
- data/lib/mug/apply.rb +58 -0
- data/lib/mug/bool.rb +128 -128
- data/lib/mug/fragile-method-chain.rb +70 -70
- data/lib/mug/hashmap.rb +100 -100
- data/lib/mug/hashop.rb +54 -54
- data/lib/mug/iterator.rb +2 -2
- data/lib/mug/iterator/for.rb +29 -29
- data/lib/mug/iterator/method.rb +29 -29
- data/lib/mug/iterator_c.rb +44 -44
- data/lib/mug/maybe.rb +59 -59
- data/lib/mug/self.rb +33 -33
- data/lib/mug/tau.rb +44 -44
- data/lib/mug/to_h.rb +44 -44
- data/test/test-and-or.rb +41 -41
- data/test/test-bool.rb +70 -70
- data/test/test-fragile-method-chain.rb +65 -65
- data/test/test-hashmap.rb +24 -24
- data/test/test-hashop.rb +62 -62
- data/test/test-iterator-for.rb +18 -18
- data/test/test-iterator-method.rb +18 -18
- data/test/test-maybe.rb +90 -90
- data/test/test-self.rb +13 -13
- data/test/test-tau.rb +22 -22
- data/test/test-to_h.rb +16 -15
- data/test/test_apply.rb +56 -0
- metadata +28 -25
data/test/test-to_h.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
|
3
|
-
$VERBOSE = true
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
assert_equal( {
|
9
|
-
assert_equal( {1=>nil,2=>nil},
|
10
|
-
assert_equal( {1=>2
|
11
|
-
assert_equal( {1=>4}, [[1,2],[
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
$VERBOSE = true
|
4
|
+
$ruby_2_1 = RUBY_VERSION.to_f >= 2.1
|
5
|
+
require_relative '../lib/mug/to_h'
|
6
|
+
class Test_enum_to_h < Test::Unit::TestCase
|
7
|
+
def test_enum_to_h
|
8
|
+
assert_equal( {}, [].to_h )
|
9
|
+
assert_equal( {1=>nil,2=>nil}, [1,2].to_h ) unless $ruby_2_1
|
10
|
+
assert_equal( {1=>nil,2=>nil}, (1..2).to_h ) unless $ruby_2_1
|
11
|
+
assert_equal( {1=>2,3=>4}, [[1,2],[3,4]].to_h )
|
12
|
+
assert_equal( {1=>4}, [[1,2],[1,4]].to_h )
|
13
|
+
assert_raise(ArgumentError) { [[1,2,3]].to_h }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
data/test/test_apply.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
$VERBOSE = true
|
3
|
+
|
4
|
+
class Foo
|
5
|
+
def bar a, b
|
6
|
+
(a||0) + (b||0)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
require_relative '../lib/mug/apply'
|
11
|
+
class Test_self < Test::Unit::TestCase
|
12
|
+
def test_apply_proc
|
13
|
+
prc = proc{|a,b,*c| (a||0) + (b||0) + c.inject(0, &:+) }
|
14
|
+
p1 = prc.apply(1)
|
15
|
+
assert( p1.is_a? Proc )
|
16
|
+
assert_equal( 3, p1.apply(2) )
|
17
|
+
assert_equal( 3, prc.apply(1,2) )
|
18
|
+
assert_equal( 15, prc.apply(1,2,3,4,5) )
|
19
|
+
end
|
20
|
+
def test_apply_lambda
|
21
|
+
lmb = lambda{|a,b,c| (a||0) + (b||0) + (c||0) }
|
22
|
+
|
23
|
+
l1 = lmb.apply(1)
|
24
|
+
assert( l1.is_a? Proc )
|
25
|
+
|
26
|
+
l2 = l1.apply(2)
|
27
|
+
assert( l2.is_a? Proc )
|
28
|
+
|
29
|
+
assert_equal( 6, l2.apply(3) )
|
30
|
+
assert_equal( 6, l1.apply(2,3) )
|
31
|
+
|
32
|
+
assert_raise( ArgumentError ){ l2.apply(3, 4) }
|
33
|
+
assert_raise( ArgumentError ){ lmb.apply(1, 2, 3, 4) }
|
34
|
+
end
|
35
|
+
def test_apply_method
|
36
|
+
m1 = 1.method :+
|
37
|
+
assert_equal( 3, m1.apply(2) )
|
38
|
+
assert_raise( ArgumentError ){ m1.apply(2,3) }
|
39
|
+
|
40
|
+
m2 = Foo.new.method :bar
|
41
|
+
l1 = m2.apply(1)
|
42
|
+
assert( l1.is_a? Proc )
|
43
|
+
|
44
|
+
assert_equal( 3, l1.apply(2) )
|
45
|
+
assert_equal( 3, m2.apply(1,2) )
|
46
|
+
|
47
|
+
assert_raise( ArgumentError ){ l1.apply(2, 3) }
|
48
|
+
assert_raise( ArgumentError ){ m2.apply(1, 2, 3) }
|
49
|
+
end
|
50
|
+
def test_curry_method
|
51
|
+
m1 = 1.method :+
|
52
|
+
assert( m1.curry.is_a? Proc )
|
53
|
+
assert( m1.curry(1).is_a? Proc )
|
54
|
+
assert_raise( ArgumentError ){ m1.curry(2) }
|
55
|
+
end
|
56
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Kerwin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
== MUG: Matty's Ultimate Gem
|
@@ -20,31 +20,33 @@ executables: []
|
|
20
20
|
extensions: []
|
21
21
|
extra_rdoc_files: []
|
22
22
|
files:
|
23
|
-
- lib/mug.rb
|
24
|
-
- lib/mug/hashmap.rb
|
25
|
-
- lib/mug/tau.rb
|
26
|
-
- lib/mug/to_h.rb
|
27
|
-
- lib/mug/fragile-method-chain.rb
|
28
|
-
- lib/mug/self.rb
|
29
|
-
- lib/mug/iterator.rb
|
30
23
|
- lib/mug/and-or.rb
|
24
|
+
- lib/mug/apply.rb
|
25
|
+
- lib/mug/bool.rb
|
26
|
+
- lib/mug/fragile-method-chain.rb
|
27
|
+
- lib/mug/hashmap.rb
|
31
28
|
- lib/mug/hashop.rb
|
32
29
|
- lib/mug/iterator/for.rb
|
33
30
|
- lib/mug/iterator/method.rb
|
34
|
-
- lib/mug/
|
31
|
+
- lib/mug/iterator.rb
|
35
32
|
- lib/mug/iterator_c.rb
|
36
|
-
- lib/mug/
|
37
|
-
-
|
38
|
-
-
|
33
|
+
- lib/mug/maybe.rb
|
34
|
+
- lib/mug/self.rb
|
35
|
+
- lib/mug/tau.rb
|
36
|
+
- lib/mug/to_h.rb
|
37
|
+
- lib/mug.rb
|
38
|
+
- test/test-and-or.rb
|
39
39
|
- test/test-bool.rb
|
40
|
-
- test/test-to_h.rb
|
41
40
|
- test/test-fragile-method-chain.rb
|
42
|
-
- test/test-and-or.rb
|
43
|
-
- test/test-iterator-method.rb
|
44
|
-
- test/test-iterator-for.rb
|
45
|
-
- test/test-maybe.rb
|
46
41
|
- test/test-hashmap.rb
|
47
42
|
- test/test-hashop.rb
|
43
|
+
- test/test-iterator-for.rb
|
44
|
+
- test/test-iterator-method.rb
|
45
|
+
- test/test-maybe.rb
|
46
|
+
- test/test-self.rb
|
47
|
+
- test/test-tau.rb
|
48
|
+
- test/test-to_h.rb
|
49
|
+
- test/test_apply.rb
|
48
50
|
homepage: http://phluid61.github.com/mug
|
49
51
|
licenses:
|
50
52
|
- ISC License
|
@@ -70,14 +72,15 @@ signing_key:
|
|
70
72
|
specification_version: 4
|
71
73
|
summary: 'MUG: Matty''s Ultimate Gem'
|
72
74
|
test_files:
|
73
|
-
- test/test-
|
74
|
-
- test/test-self.rb
|
75
|
+
- test/test-and-or.rb
|
75
76
|
- test/test-bool.rb
|
76
|
-
- test/test-to_h.rb
|
77
77
|
- test/test-fragile-method-chain.rb
|
78
|
-
- test/test-and-or.rb
|
79
|
-
- test/test-iterator-method.rb
|
80
|
-
- test/test-iterator-for.rb
|
81
|
-
- test/test-maybe.rb
|
82
78
|
- test/test-hashmap.rb
|
83
79
|
- test/test-hashop.rb
|
80
|
+
- test/test-iterator-for.rb
|
81
|
+
- test/test-iterator-method.rb
|
82
|
+
- test/test-maybe.rb
|
83
|
+
- test/test-self.rb
|
84
|
+
- test/test-tau.rb
|
85
|
+
- test/test-to_h.rb
|
86
|
+
- test/test_apply.rb
|