ludy 0.0.1
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.
- data/LICENSE +201 -0
- data/NOTICE +26 -0
- data/README +17 -0
- data/lib/lib/amulti.rb +40 -0
- data/lib/lib/multi.rb +139 -0
- data/lib/lib/smulti.rb +56 -0
- data/lib/ludy.rb +31 -0
- data/lib/ludy/callstack.rb +39 -0
- data/lib/ludy/dice.rb +68 -0
- data/lib/ludy/lazy.rb +39 -0
- data/lib/ludy/ludy_ext.rb +34 -0
- data/lib/ludy/rambda.rb +41 -0
- data/lib/ludy/this.rb +33 -0
- data/lib/ludy/variable.rb +37 -0
- data/lib/ludy/y_combinator.rb +29 -0
- data/lib/ludy/z_combinator.rb +25 -0
- data/ludy.gemspec +44 -0
- data/test/tc_callstack.rb +33 -0
- data/test/tc_dice.rb +47 -0
- data/test/tc_lazy.rb +33 -0
- data/test/tc_ludy_ext.rb +27 -0
- data/test/tc_rambda.rb +32 -0
- data/test/tc_this.rb +84 -0
- data/test/tc_variable.rb +44 -0
- data/test/tc_y_combinator.rb +35 -0
- data/test/tc_z_combinator.rb +35 -0
- data/test/ts_ludy.rb +18 -0
- metadata +76 -0
data/test/tc_dice.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2007, Lin Jen-Shin(a.k.a. godfat 真常)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'test/unit'
|
18
|
+
require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
|
19
|
+
require_ludy 'dice'
|
20
|
+
include Ludy
|
21
|
+
class TestDice < Test::Unit::TestCase
|
22
|
+
def test_dice
|
23
|
+
50.times{ assert((1..20).include?(1.roll)) }
|
24
|
+
50.times{ assert((2..40).include?(2.roll)) }
|
25
|
+
50.times{ assert((3..18).include?(3.roll(6))) }
|
26
|
+
|
27
|
+
_4d20 = 4.dice
|
28
|
+
assert_equal 4, _4d20.min
|
29
|
+
assert_equal 4*20, _4d20.max
|
30
|
+
50.times{ assert((4..80).include?(_4d20.roll)) }
|
31
|
+
|
32
|
+
_5d12 = 5.dice 12
|
33
|
+
assert_equal 5, _5d12.min
|
34
|
+
assert_equal 5*12, _5d12.max
|
35
|
+
50.times{ assert((5..60).include?(_5d12.roll)) }
|
36
|
+
|
37
|
+
ds = DiceSet.new _4d20, _5d12
|
38
|
+
assert_equal _4d20.min+_5d12.min, ds.min
|
39
|
+
assert_equal _4d20.max+_5d12.max, ds.max
|
40
|
+
50.times{ assert((ds.min..ds.max).include?(ds.roll)) }
|
41
|
+
|
42
|
+
du = DiceSet.new ds, 6.dice(6)
|
43
|
+
assert_equal ds.min+6, du.min
|
44
|
+
assert_equal ds.max+36, du.max
|
45
|
+
50.times{ assert((du.min..du.max).include?(du.roll)) }
|
46
|
+
end
|
47
|
+
end
|
data/test/tc_lazy.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2007, Lin Jen-Shin(a.k.a. godfat 真常)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'test/unit'
|
18
|
+
require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
|
19
|
+
require_ludy 'lazy'
|
20
|
+
include Ludy
|
21
|
+
class TestLazy < Test::Unit::TestCase
|
22
|
+
def setup; @data = 0; end
|
23
|
+
def get; @data += 1; end
|
24
|
+
def test_lazy
|
25
|
+
assert_equal 0, @data
|
26
|
+
v = lazy{get}
|
27
|
+
assert_equal 0, @data
|
28
|
+
assert_equal 1, v
|
29
|
+
assert_equal '1', v.to_s
|
30
|
+
assert_equal 1, v
|
31
|
+
assert_equal '1', v.to_s
|
32
|
+
end
|
33
|
+
end
|
data/test/tc_ludy_ext.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2007, Lin Jen-Shin(a.k.a. godfat 真常)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'test/unit'
|
18
|
+
require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
|
19
|
+
require_ludy 'ludy_ext'
|
20
|
+
class TestLudyExt < Test::Unit::TestCase
|
21
|
+
def test_tap
|
22
|
+
assert_equal '11', 10.tap{|i| assert_equal '10', i.to_s}.succ.to_s
|
23
|
+
end
|
24
|
+
def test_nil
|
25
|
+
assert_nil nil.XD.Orz.zzz
|
26
|
+
end
|
27
|
+
end
|
data/test/tc_rambda.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2007, Lin Jen-Shin(a.k.a. godfat 真常)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'test/unit'
|
18
|
+
require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
|
19
|
+
require_ludy 'rambda'
|
20
|
+
include Ludy
|
21
|
+
class TestRambda < Test::Unit::TestCase
|
22
|
+
def test_rambda
|
23
|
+
assert_equal(3628800, rambda{|n| n==1 ? 1 : n*this[n-1]}[10])
|
24
|
+
assert_equal([1,1,2,3,5,8,13,21,34,55],
|
25
|
+
(0...10).map(&rambda{|n| n<=1 ? 1 : this[n-2]+this[n-1]}))
|
26
|
+
|
27
|
+
v = "can't refer v"
|
28
|
+
assert_raise(NameError){
|
29
|
+
rambda{v}.call
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
data/test/tc_this.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2007, Lin Jen-Shin(a.k.a. godfat 真常)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'test/unit'
|
18
|
+
require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
|
19
|
+
require_ludy 'this'
|
20
|
+
include Ludy
|
21
|
+
class TestThis < Test::Unit::TestCase
|
22
|
+
def test_fact
|
23
|
+
assert_equal(120, fact(5))
|
24
|
+
assert_equal(3628800, fact(10))
|
25
|
+
assert_equal(5040, lambda{|n| n==1 ? 1 : n*this[n-1]}[7])
|
26
|
+
|
27
|
+
# can't play with yielded method! that's a problem
|
28
|
+
assert_raise(ArgumentError){
|
29
|
+
(0...10).map(&lambda{|n| n<=1 ? 1 : this[n-2]+this[n-1]})
|
30
|
+
}
|
31
|
+
end
|
32
|
+
def fact n
|
33
|
+
return n*this[n-1] if n > 0
|
34
|
+
1
|
35
|
+
end
|
36
|
+
##
|
37
|
+
def test_pass_around
|
38
|
+
assert_equal(method(:pass_around_forward), pass_around.call(lambda{|v| v}))
|
39
|
+
end
|
40
|
+
def pass_around mode = 'pass'
|
41
|
+
case mode
|
42
|
+
when 'pass'
|
43
|
+
pass_around_forward this
|
44
|
+
else
|
45
|
+
'value'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
def pass_around_forward func
|
49
|
+
assert_equal('value', func['value'])
|
50
|
+
this
|
51
|
+
end
|
52
|
+
##
|
53
|
+
def test_with_block
|
54
|
+
with_block{|b| assert_equal('value', b['value'])}
|
55
|
+
end
|
56
|
+
def with_block mode = 'pass', &block
|
57
|
+
case mode
|
58
|
+
when 'pass'
|
59
|
+
block[this]
|
60
|
+
else
|
61
|
+
'value'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
##
|
65
|
+
def test_more_args
|
66
|
+
more_args('get_this'){}.call('call', 1, 2, 3, 4, 5, &lambda{6})
|
67
|
+
more_args('get_this'){}.call('call', 1, 2, 3, 4, 5){6}
|
68
|
+
end
|
69
|
+
def more_args mode, a1=nil, a2=nil, a3=nil, *as, &block
|
70
|
+
case mode
|
71
|
+
when 'get_this'
|
72
|
+
this
|
73
|
+
else
|
74
|
+
assert_equal(1, a1)
|
75
|
+
assert_equal(2, a2)
|
76
|
+
assert_equal(3, a3)
|
77
|
+
assert_equal(4, as[0])
|
78
|
+
assert_equal(5, as[1])
|
79
|
+
assert_equal(nil, as[2])
|
80
|
+
assert_equal(6, yield)
|
81
|
+
assert_equal(6, block.call)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/test/tc_variable.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2007, Lin Jen-Shin(a.k.a. godfat 真常)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'test/unit'
|
18
|
+
require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
|
19
|
+
require_ludy 'variable'
|
20
|
+
include Ludy
|
21
|
+
class TestVariable < Test::Unit::TestCase
|
22
|
+
class Qoo
|
23
|
+
def cool
|
24
|
+
'cool ~~~~'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_variable
|
29
|
+
x = var Qoo.new
|
30
|
+
y = x
|
31
|
+
|
32
|
+
assert_equal x.__obj__, y.__obj__
|
33
|
+
assert_equal Qoo, x.__obj__.class
|
34
|
+
assert_equal Qoo, x.class
|
35
|
+
|
36
|
+
assert_equal 'cool ~~~~', x.cool
|
37
|
+
assert_equal 'cool ~~~~', y.cool
|
38
|
+
|
39
|
+
x.__obj__ = nil
|
40
|
+
|
41
|
+
assert x.nil?
|
42
|
+
assert y.nil?
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2007, Lin Jen-Shin(a.k.a. godfat 真常)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'test/unit'
|
18
|
+
require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
|
19
|
+
require_ludy 'y_combinator'
|
20
|
+
include Ludy
|
21
|
+
class TestYCombinator < Test::Unit::TestCase
|
22
|
+
def test_y_combinator
|
23
|
+
fact_ = lambda{|this|
|
24
|
+
lambda{|n| n==1 ? 1 : n*this[n-1]}
|
25
|
+
}
|
26
|
+
fact = Y[fact_]
|
27
|
+
assert_equal(3628800, fact[10])
|
28
|
+
|
29
|
+
fib_ = lambda{|this|
|
30
|
+
lambda{|n| n<=1 ? 1 : this[n-2]+this[n-1]}
|
31
|
+
}
|
32
|
+
fib = Y[fib_]
|
33
|
+
assert_equal([1,1,2,3,5,8,13,21,34,55], (0...10).map(&fib))
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2007, Lin Jen-Shin(a.k.a. godfat 真常)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'test/unit'
|
18
|
+
require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
|
19
|
+
require_ludy 'z_combinator'
|
20
|
+
include Ludy
|
21
|
+
class TestZCombinator < Test::Unit::TestCase
|
22
|
+
def test_z_combinator
|
23
|
+
fact_ = lambda{|this|
|
24
|
+
lambda{|n| n==1 ? 1 : n*this[n-1]}
|
25
|
+
}
|
26
|
+
fact = Z[fact_]
|
27
|
+
assert_equal(3628800, fact[10])
|
28
|
+
|
29
|
+
fib_ = lambda{|this|
|
30
|
+
lambda{|n| n<=1 ? 1 : this[n-2]+this[n-1]}
|
31
|
+
}
|
32
|
+
fib = Z[fib_]
|
33
|
+
assert_equal([1,1,2,3,5,8,13,21,34,55], (0...10).map(&fib))
|
34
|
+
end
|
35
|
+
end
|
data/test/ts_ludy.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2007, Lin Jen-Shin(a.k.a. godfat 真常)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
|
18
|
+
require_all_in_dir __FILE__
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: ludy
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2007-04-30 00:00:00 +08:00
|
8
|
+
summary: Aims to extend Ruby standard library, providing some useful tools that's not existed in the standard library.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: "strip number: 135godfat7911@246gmail.890com"
|
12
|
+
homepage: http://ludy.rubyforge.org/
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire: ludy
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Lin Jen-Shin(a.k.a. godfat)
|
31
|
+
files:
|
32
|
+
- lib/lib
|
33
|
+
- lib/ludy
|
34
|
+
- lib/ludy.rb
|
35
|
+
- lib/lib/amulti.rb
|
36
|
+
- lib/lib/multi.rb
|
37
|
+
- lib/lib/smulti.rb
|
38
|
+
- lib/ludy/callstack.rb
|
39
|
+
- lib/ludy/dice.rb
|
40
|
+
- lib/ludy/lazy.rb
|
41
|
+
- lib/ludy/ludy_ext.rb
|
42
|
+
- lib/ludy/rambda.rb
|
43
|
+
- lib/ludy/this.rb
|
44
|
+
- lib/ludy/variable.rb
|
45
|
+
- lib/ludy/y_combinator.rb
|
46
|
+
- lib/ludy/z_combinator.rb
|
47
|
+
- test/tc_callstack.rb
|
48
|
+
- test/tc_dice.rb
|
49
|
+
- test/tc_lazy.rb
|
50
|
+
- test/tc_ludy_ext.rb
|
51
|
+
- test/tc_rambda.rb
|
52
|
+
- test/tc_this.rb
|
53
|
+
- test/tc_variable.rb
|
54
|
+
- test/tc_y_combinator.rb
|
55
|
+
- test/tc_z_combinator.rb
|
56
|
+
- test/ts_ludy.rb
|
57
|
+
- lib
|
58
|
+
- LICENSE
|
59
|
+
- ludy.gemspec
|
60
|
+
- NOTICE
|
61
|
+
- README
|
62
|
+
- test
|
63
|
+
test_files:
|
64
|
+
- test/ts_ludy.rb
|
65
|
+
rdoc_options: []
|
66
|
+
|
67
|
+
extra_rdoc_files: []
|
68
|
+
|
69
|
+
executables: []
|
70
|
+
|
71
|
+
extensions: []
|
72
|
+
|
73
|
+
requirements: []
|
74
|
+
|
75
|
+
dependencies: []
|
76
|
+
|