backports 2.3.0 → 2.4.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.
Files changed (55) hide show
  1. data/.irbrc +1 -0
  2. data/README.rdoc +55 -3
  3. data/Rakefile +1 -0
  4. data/VERSION.yml +1 -1
  5. data/backports.gemspec +99 -118
  6. data/lib/backports/1.8.7/string.rb +1 -1
  7. data/lib/backports/1.9.1/array.rb +1 -2
  8. data/lib/backports/1.9.1/file.rb +20 -0
  9. data/lib/backports/1.9.1/float.rb +19 -0
  10. data/lib/backports/1.9.1/hash.rb +20 -3
  11. data/lib/backports/1.9.1/integer.rb +19 -0
  12. data/lib/backports/1.9.1/io.rb +18 -3
  13. data/lib/backports/1.9.1/numeric.rb +9 -0
  14. data/lib/backports/1.9.1/regexp.rb +1 -6
  15. data/lib/backports/1.9.1/stdlib/prime.rb +495 -0
  16. data/lib/backports/1.9.1/stdlib.rb +1 -0
  17. data/lib/backports/1.9.1/string.rb +2 -7
  18. data/lib/backports/1.9.2/array.rb +3 -4
  19. data/lib/backports/1.9.2/complex.rb +6 -0
  20. data/lib/backports/1.9.2/stdlib/matrix/eigenvalue_decomposition.rb +886 -0
  21. data/lib/backports/1.9.2/stdlib/matrix/lup_decomposition.rb +218 -0
  22. data/lib/backports/1.9.2/stdlib/matrix.rb +1872 -0
  23. data/lib/backports/1.9.2/stdlib/set.rb +13 -0
  24. data/lib/backports/1.9.2/stdlib.rb +1 -0
  25. data/lib/backports/1.9.3/io.rb +12 -0
  26. data/lib/backports/1.9.3.rb +5 -0
  27. data/lib/backports/1.9.rb +1 -1
  28. data/lib/backports/basic_object.rb +3 -2
  29. data/lib/backports/force/array_map.rb +1 -0
  30. data/lib/backports/force/enumerable_map.rb +3 -0
  31. data/lib/backports/force/hash_select.rb +9 -0
  32. data/lib/backports/force/string_length.rb +10 -0
  33. data/lib/backports/force/string_size.rb +1 -0
  34. data/lib/backports/tools.rb +137 -1
  35. data/test/README +13 -0
  36. metadata +25 -42
  37. data/.gitignore +0 -7
  38. data/test/_README +0 -1
  39. data/test/array_test.rb +0 -82
  40. data/test/basic_object_test.rb +0 -70
  41. data/test/binding_test.rb +0 -20
  42. data/test/enumerable_test.rb +0 -244
  43. data/test/enumerator_test.rb +0 -45
  44. data/test/hash_test.rb +0 -26
  45. data/test/kernel_test.rb +0 -31
  46. data/test/math_test.rb +0 -59
  47. data/test/method_missing_test.rb +0 -37
  48. data/test/method_test.rb +0 -73
  49. data/test/module_test.rb +0 -20
  50. data/test/object_test.rb +0 -35
  51. data/test/proc_test.rb +0 -116
  52. data/test/regexp_test.rb +0 -14
  53. data/test/string_test.rb +0 -74
  54. data/test/symbol_test.rb +0 -23
  55. data/test/test_helper.rb +0 -8
@@ -1,244 +0,0 @@
1
- require 'test_helper'
2
- require 'stringio'
3
-
4
- class EnumerableTest < Test::Unit::TestCase
5
- context "Enumerable" do
6
- context "#count" do
7
- should "conform to doc" do
8
- assert_equal 4, (1..4).count
9
- assert_equal 1, (1..4).count(3)
10
- assert_equal 2, (1..4).count{|obj| obj > 2 }
11
- end
12
- end
13
-
14
- context "#cycle" do
15
- should "conform to doc" do
16
- assert_equal ["a", "b", "c", "a", "b", "c"], ('a'..'c').cycle(2).to_a
17
- end
18
- end
19
-
20
- context "#drop" do
21
- should "conform to doc" do
22
- assert_equal [5, 8, 13], [ 1, 1, 2, 3, 5, 8, 13 ].drop(4)
23
- assert_equal [], [ 1, 1, 2, 3, 5, 8, 13 ].drop(99)
24
- end
25
-
26
- should "work with enums" do
27
- assert_equal [14,15], (10...16).drop(4)
28
- end
29
- end
30
-
31
- context "#drop_while" do
32
- should "conform to doc" do
33
- assert_equal [8, 13], [ 1, 1, 2, 3, 5, 8, 13 ].drop_while {|item| item < 6 }
34
- end
35
-
36
- should "work with enums" do
37
- assert_equal [14,15], (10...16).drop_while {|item| item < 14}
38
- end
39
-
40
- should "work with extemity cases" do
41
- assert_equal [10,11,12,13,14,15], (10...16).drop_while {|item| false}
42
- assert_equal [], (10...16).drop_while {|item| true}
43
- end
44
- end
45
-
46
- context "#each_cons" do
47
- should "conform to doc" do
48
- assert_equal [[1,2],[2,3],[3,4]], (1..4).each_cons(2).to_a
49
- end
50
- end
51
-
52
- context "#each_slice" do
53
- should "conform to doc" do
54
- res = []
55
- (1..10).each_slice(4){|ar| res << ar}
56
- assert_equal [[1, 2, 3, 4],[5, 6, 7, 8],[9, 10]], res
57
- assert_equal [[1, 2, 3, 4],[5, 6, 7, 8],[9, 10]], (1..10).each_slice(4).to_a
58
- end
59
- end
60
-
61
- context "#each_with_index" do
62
- should "conform to doc" do
63
- hash = Hash.new
64
- %w(cat dog wombat).each_with_index do |item, index|
65
- hash[item] = index
66
- end
67
- assert_equal({"cat"=>0, "wombat"=>2, "dog"=>1}, hash)
68
- end
69
-
70
- should "be ok with arguments and no block" do
71
- s = StringIO.new("Hello world!")
72
- assert_equal [["Hello",0], [" wo",1], ["rld!",2]], s.each_with_index("o").to_a
73
- end
74
-
75
- end
76
-
77
- context "#each_with_object" do
78
- should "conform to doc" do
79
- hash = %w(cat dog wombat).each_with_object({}) do |item, memo|
80
- memo[item] = item.upcase.reverse
81
- end
82
- assert_equal({"cat"=>"TAC", "dog"=>"GOD", "wombat"=>"TABMOW"}, hash)
83
- end
84
- end
85
-
86
- context "#find" do
87
- should "not require a block" do
88
- assert_equal 3, (1..10).find.each {|item| item > 2 }
89
- end
90
-
91
- should "work as expected" do
92
- assert_equal 3, (1..10).find {|item| item > 2 }
93
- end
94
- end
95
-
96
- context "#find_index" do
97
- should "conform to doc" do
98
- assert_equal 3, %w{ant bat cat dog}.find_index {|item| item =~ /g/ }
99
- assert_equal nil, %w{ant bat cat dog}.find_index {|item| item =~ /h/ }
100
- end
101
-
102
- should "work for enumerables too" do
103
- assert_equal 69-42, (42..666).find_index(69)
104
- end
105
- end
106
-
107
- context "#group_by" do
108
- should "conform to doc" do
109
- x = (1..5).group_by{|item| item.even? ? :even : :odd }
110
- assert_equal({:even => [2,4], :odd => [1,3,5]}, x)
111
- assert_equal nil, x[:xyz]
112
- end
113
- end
114
-
115
- context "#inject" do
116
- should "conform to doc" do
117
- assert_equal 45, (5..10).inject(0) {|sum, n| sum + n }
118
- assert_equal 45, (5..10).inject {|sum, n| sum + n }
119
- assert_equal 45, (5..10).inject(0, :+)
120
- assert_equal 45, (5..10).inject(:+)
121
- end
122
- end
123
-
124
- context "#max_by" do
125
- should "conform to doc" do
126
- a = %w(albatross dog horse fox)
127
- assert_equal "albatross" , a.max_by {|item| item.length }
128
- assert_equal "fox", a.max_by {|item| item.reverse }
129
- end
130
- end
131
-
132
- context "#min_by" do
133
- should "conform to doc" do
134
- a = %w(albatross dog horse fox)
135
- assert_equal "dog" , a.min_by {|item| item.length }
136
- assert_equal "horse", a.min_by {|item| item.reverse }
137
- end
138
- end
139
-
140
- context "#minmax" do
141
- should "conform to doc" do
142
- a = %w(albatross dog horse)
143
- assert_equal ["albatross", "horse"], a.minmax
144
- assert_equal ["dog", "albatross"], a.minmax {|a,b| a.length <=> b.length }
145
- end
146
- end
147
-
148
- context "#one" do
149
- should "conform to doc" do
150
- assert_equal false, %w{ ant bear cat}.one? {|word| word.length >= 3}
151
- assert_equal true, %w{ ant bear cat}.one? {|word| word.length >= 4}
152
- assert_equal true, [ nil, nil, 99 ].one?
153
- end
154
- end
155
-
156
- context "#reverse_each" do
157
- should "work as expected" do
158
- assert_equal [4,3,2], (1..4).reverse_each.take(3)
159
- end
160
- end
161
-
162
- context "#take" do
163
- should "conform to doc" do
164
- assert_equal [1, 2, 3], (1..7).take(3)
165
- assert_equal [["a", 1], ["b", 2]], { 'a'=>1, 'b'=>2, 'c'=>3 }.take(2)
166
- end
167
-
168
- should "only consume what's needed" do
169
- assert_equal [], Enumerator.new(nil).take(0)
170
- assert_raises(NoMethodError) { Enumerator.new(nil).take(1) }
171
- end
172
- end
173
-
174
- context "#take_while" do
175
- should "conform to doc" do
176
- assert_equal [1,2], (1..7).take_while {|item| item < 3 }
177
- assert_equal [2,4,6], [ 2, 4, 6, 9, 11, 16 ].take_while(&:even?)
178
- end
179
-
180
- should "work with infinite enumerables" do
181
- assert_equal [1,2], (1..(1/0.0)).take_while {|item| item < 3 }
182
- end
183
- end
184
-
185
- context "#to_a" do
186
- should "work with arguments" do
187
- s = StringIO.new("Hello world!")
188
- assert_equal ["Hello", " wo", "rld!"], s.to_a("o")
189
- end
190
- end
191
-
192
- context "#chunk" do
193
- context "given no argument" do
194
- should "should chunk correctly even for non-consecutive but similar keys" do
195
- e = (1..7).chunk{|i| (i/3) % 2}
196
- assert_equal true, e.is_a?(Enumerator)
197
- assert_equal [
198
- [0, [1,2]],
199
- [1, [3,4,5]],
200
- [0, [6,7]]], e.to_a
201
- end
202
-
203
- should "should pass two arguments to the block" do
204
- e = (1..7).chunk{|i| (i/3) % 2}
205
- e.each do |key, val|
206
- assert_equal 0, key
207
- assert_equal [1,2], val
208
- break
209
- end
210
- end
211
-
212
- should "handles nil & :_symbol" do
213
- a = [1,1,nil,1,:_separator, 1, :_singleton, 1]
214
- e = a.size.times.chunk{|i| a[i]}
215
- assert_equal [
216
- [1,[0,1]],
217
- [1,[3]],
218
- [1,[5]],
219
- [:_singleton, [6]],
220
- [1,[7]]
221
- ], e.to_a
222
- end
223
-
224
- end
225
-
226
- context "given an initial_state argument" do
227
- should "give a new copy" do
228
- a = []
229
- e = (1..3).chunk(a) do |i, x|
230
- assert_equal true, x.empty?
231
- x << :yo
232
- :_singleton
233
- end
234
- assert_equal [
235
- [:_singleton, [1]],
236
- [:_singleton, [2]],
237
- [:_singleton, [3]]], e.to_a
238
- end
239
- end
240
-
241
- end
242
-
243
- end
244
- end
@@ -1,45 +0,0 @@
1
- require 'test_helper'
2
-
3
-
4
- class EnumeratorTest < Test::Unit::TestCase
5
- context "Enumerator" do
6
- context "#with_object" do
7
- should "conform to doc" do
8
- animals = %w(cat dog wombat).to_enum
9
- hash = animals.with_object({}).each do |item, memo|
10
- memo[item] = item.upcase.reverse
11
- end
12
- assert_equal({"cat"=>"TAC", "dog"=>"GOD", "wombat"=>"TABMOW"}, hash)
13
- end
14
- end
15
-
16
- context "#new" do
17
- should "should accept block" do
18
- enum = Enumerator.new do |yielder|
19
- yielder.yield "This syntax is"
20
- yielder.yield "cool!"
21
- end
22
- assert enum.is_a?(Enumerator)
23
- 2.times do
24
- assert_equal ["This syntax is", "cool!"], enum.to_a
25
- end
26
- end
27
- end
28
-
29
- context "#each" do
30
- should "should not require block" do
31
- assert_nothing_raised { [42].to_enum.each }
32
- assert_equal [42], [42].to_enum.each.to_a
33
- end
34
- end
35
-
36
- context "#next" do
37
- should "conform to doc" do
38
- enum = [10, 20].to_enum
39
- assert_equal 10, enum.next
40
- assert_equal 20, enum.next
41
- assert_raise(StopIteration){ enum.next}
42
- end
43
- end
44
- end
45
- end
data/test/hash_test.rb DELETED
@@ -1,26 +0,0 @@
1
- require 'test_helper'
2
-
3
- class HashTest < Test::Unit::TestCase
4
- context "Hash" do
5
- should "should be constructible from key value pairs" do
6
- assert_equal({1 => 2, 3 => 4}, Hash[[[1,2],[3,4]]])
7
- end
8
-
9
- context "#default_proc=" do
10
- should "conform to doc" do
11
- h = { :foo => :bar }
12
- h.default = "Go fish"
13
- h.default_proc=lambda do |hash, key|
14
- key + key
15
- end
16
- assert_equal :bar, h[:foo]
17
- assert_equal 4, h[2]
18
- assert_equal "catcat", h["cat"]
19
- h.default=nil
20
- assert_equal nil, h[2]
21
- assert_equal nil, h["cat"]
22
- end
23
- end
24
- end
25
-
26
- end
data/test/kernel_test.rb DELETED
@@ -1,31 +0,0 @@
1
- require 'test_helper'
2
-
3
- $outside = __callee__
4
- def fred
5
- "I'm in #{__callee__.inspect}"
6
- end
7
-
8
- class KernelTest < Test::Unit::TestCase
9
- context "Kernel" do
10
- context ".loop" do
11
- should "catch StopIteration" do
12
- i = 0
13
- r = []
14
- loop do
15
- r << i
16
- i += 1
17
- raise StopIteration if i > 2
18
- end
19
- assert_equal [0, 1, 2], r
20
- end
21
- end
22
-
23
-
24
- context ".__callee__" do
25
- should "conform to doc" do
26
- assert_equal "I'm in :fred", fred
27
- assert_equal nil, $outside
28
- end
29
- end
30
- end
31
- end
data/test/math_test.rb DELETED
@@ -1,59 +0,0 @@
1
- require 'test_helper'
2
-
3
- class MathTest < Test::Unit::TestCase
4
- context "Math" do
5
- context ".log" do
6
- should "accept one argument" do
7
- assert_nothing_raised(ArgumentError) { Math.log(1) }
8
- end
9
-
10
- should "accept two arguments" do
11
- assert_nothing_raised(ArgumentError) { Math.log(2, 2) }
12
- end
13
-
14
- should "accept valid arguments" do
15
- assert_nothing_raised(TypeError) { Math.log(2, 2) }
16
- assert_nothing_raised(TypeError) { Math.log(2, 2.0) }
17
- end
18
-
19
- should "reject invalid arguments" do
20
- assert_raises(TypeError) { Math.log(2, nil) }
21
- assert_raises(TypeError) { Math.log(2, "2") }
22
- end
23
-
24
- should "return the correct value" do
25
- assert_equal 0.0, Math.log(1)
26
- assert_equal 1.0, Math.log(Math::E)
27
- assert_equal 3.0, Math.log(Math::E**3)
28
- assert_equal 3.0, Math.log(8, 2)
29
- end
30
- end
31
-
32
- context ".log2" do
33
- should "be defined" do
34
- assert_respond_to Math, :log2
35
- end
36
-
37
- should "accept one argument" do
38
- assert_nothing_raised(ArgumentError) { Math.log2(1) }
39
- end
40
-
41
- should "accept valid arguments" do
42
- assert_nothing_raised(TypeError) { Math.log2(1) }
43
- assert_nothing_raised(TypeError) { Math.log2(1.0) }
44
- end
45
-
46
- should "reject invalid arguments" do
47
- assert_raises(TypeError) { Math.log2(nil) }
48
- assert_raises(TypeError) { Math.log2("1") }
49
- end
50
-
51
- should "return the correct value" do
52
- assert_equal 0.0, Math.log2(1)
53
- assert_equal 1.0, Math.log2(2)
54
- assert_equal 15.0, Math.log2(32768)
55
- assert_equal 16.0, Math.log2(65536)
56
- end
57
- end
58
- end
59
- end
@@ -1,37 +0,0 @@
1
- require 'test_helper'
2
-
3
-
4
- class MethodMissingTest < Test::Unit::TestCase
5
-
6
- class A
7
- def respond_to_missing? method
8
- :ok_if_missing == method
9
- end
10
-
11
- def method_missing method, *args
12
- :bar
13
- end
14
- end
15
-
16
- context "#respond_to?" do
17
- should "takes #respond_to_missing? into account" do
18
- assert_equal true, A.new.respond_to?(:ok_if_missing)
19
- assert_equal false, A.new.respond_to?(:not_ok_if_missing)
20
- end
21
- end
22
-
23
- context "#method" do
24
- should "returns a nice Method with respond_to_missing?" do
25
- assert_equal :bar, A.new.method(:ok_if_missing).call
26
- assert_raise(NameError){ A.new.method(:not_ok_if_missing) }
27
- end
28
- end
29
-
30
- context "Method#unbind" do
31
- should "works for missing Methods" do
32
- assert_equal :ok_if_missing, A.new.method(:ok_if_missing).unbind.name
33
- end
34
- end
35
-
36
-
37
- end
data/test/method_test.rb DELETED
@@ -1,73 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ArrayTest < Test::Unit::TestCase
4
-
5
- context "Method" do
6
- setup do
7
- @cat = "cat"
8
- @bound = @cat.method(:upcase)
9
- end
10
-
11
- context "#name" do
12
- should "conform to doc" do
13
- assert_equal "upcase", @bound.name
14
- end
15
- end
16
-
17
- context "#owner" do
18
- should "conform to doc" do
19
- assert_equal String, @bound.owner
20
- end
21
- end
22
-
23
- context "#receiver" do
24
- should "conform to doc" do
25
- assert @cat === @bound.receiver
26
- end
27
- end
28
-
29
- context "Unbound" do
30
- setup do
31
- @unbound = @bound.unbind
32
- end
33
-
34
- context "#name" do
35
- should "conform to doc" do
36
- assert_equal "upcase", @unbound.name
37
- end
38
- end
39
-
40
- context "#owner" do
41
- should "conform to doc" do
42
- assert_equal String, @unbound.owner
43
- end
44
- end
45
-
46
- context "bound again" do
47
- setup do
48
- @dog = "dog"
49
- @bound_again = @unbound.bind(@dog)
50
- end
51
-
52
- context "#name" do
53
- should "conform to doc" do
54
- assert_equal "upcase", @bound_again.name
55
- end
56
- end
57
-
58
- context "#owner" do
59
- should "conform to doc" do
60
- assert_equal String, @bound_again.owner
61
- end
62
- end
63
-
64
- context "#receiver" do
65
- should "conform to doc" do
66
- assert @dog === @bound_again.receiver
67
- end
68
- end
69
-
70
- end
71
- end
72
- end
73
- end
data/test/module_test.rb DELETED
@@ -1,20 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Thing
4
- end
5
-
6
- class ModuleTest < Test::Unit::TestCase
7
- context "Module" do
8
- context "#module_exec" do
9
- should "conform to doc" do
10
- name = :new_instance_variable
11
- Thing.module_exec(name) do |iv_name|
12
- attr_accessor iv_name
13
- end
14
- t = Thing.new
15
- t.new_instance_variable = "wibble"
16
- assert_equal "wibble", t.new_instance_variable
17
- end
18
- end
19
- end
20
- end
data/test/object_test.rb DELETED
@@ -1,35 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ObjectTest < Test::Unit::TestCase
4
- class KlassWithSecret
5
- def initialize
6
- @secret = 99
7
- end
8
- end
9
- context "Object" do
10
- context "#instance_exec" do
11
- should "conform to doc" do
12
- k = KlassWithSecret.new
13
- assert_equal 104, k.instance_exec(5) {|x| @secret+x }
14
- end
15
- end
16
-
17
- context "#define_singleton_method" do
18
- should "conform to doc" do
19
- a = "cat"
20
- a.define_singleton_method(:speak) do
21
- "miaow"
22
- end
23
- assert_equal "miaow", a.speak
24
-
25
- KlassWithSecret.class_eval do
26
- define_method(:one) { "instance method" }
27
- define_singleton_method(:two) { "class method" }
28
- end
29
- t = KlassWithSecret.new
30
- assert_equal "instance method", t.one
31
- assert_equal "class method", KlassWithSecret.two
32
- end
33
- end
34
- end
35
- end
data/test/proc_test.rb DELETED
@@ -1,116 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ProcTest < Test::Unit::TestCase
4
- # method names correspond with Ruby docs
5
- def n(&b) b.lambda? end
6
- def m() end
7
-
8
- class C
9
- define_method(:d) {}
10
- define_method(:e, &proc {})
11
- end
12
-
13
- def implicit
14
- Proc.new
15
- end
16
-
17
- context "Proc" do
18
- context "#lambda?" do
19
- context "basic usage" do
20
- should "conform to docs" do
21
- assert lambda {}.lambda?
22
- assert !proc {}.lambda?
23
- assert !Proc.new {}.lambda?
24
- end
25
- end
26
-
27
- context "propagation" do
28
- should "conform to docs" do
29
- assert lambda(&lambda {}).lambda?
30
- assert proc(&lambda {}).lambda?
31
- assert Proc.new(&lambda {}).lambda?
32
- end
33
- end
34
-
35
- context "blocks passed to methods" do
36
- should "conform to docs" do
37
- assert !n { }
38
- assert n(&lambda {})
39
- assert !n(&proc {})
40
- assert !n(&Proc.new {})
41
- end
42
-
43
- should "not break Proc.new" do
44
- implicit { }
45
- implicit(&proc {})
46
- end
47
- end
48
-
49
- context "Method#to_proc" do
50
- should "conform to docs" do
51
- assert method(:m).to_proc.lambda?
52
- assert n(&method(:m))
53
- assert n(&method(:m).to_proc)
54
- assert C.new.method(:d).to_proc.lambda?
55
- assert C.new.method(:e).to_proc.lambda?
56
- end
57
- end
58
- end
59
-
60
- context "#curry" do
61
- context "proc" do
62
- context "no arguments" do
63
- should "conform to docs" do
64
- b = proc { :foo }
65
- assert_equal :foo, b.curry[]
66
- end
67
- end
68
-
69
- context "arity > 0" do
70
- should "conform to docs" do
71
- b = Proc.new {|x, y, z| (x||0) + (y||0) + (z||0) }
72
- assert_equal 6, b.curry[1][2][3]
73
- assert_equal 6, b.curry[1, 2][3, 4]
74
- assert_equal 6, b.curry(5)[1][2][3][4][5]
75
- assert_equal 6, b.curry(5)[1, 2][3, 4][5]
76
- assert_equal 1, b.curry(1)[1]
77
- end
78
- end
79
-
80
- context "arity < 0" do
81
- should "conform to docs" do
82
- b = Proc.new {|x, y, z, *w| (x||0) + (y||0) + (z||0) + w.inject(0, &:+) }
83
- assert_equal 6, b.curry[1][2][3]
84
- assert_equal 10, b.curry[1, 2][3, 4]
85
- assert_equal 15, b.curry(5)[1][2][3][4][5]
86
- assert_equal 15, b.curry(5)[1, 2][3, 4][5]
87
- assert_equal 1, b.curry(1)[1]
88
- end
89
- end
90
- end
91
-
92
- context "lambda" do
93
- context "arity > 0" do
94
- should "conform to docs" do
95
- b = lambda {|x, y, z| (x||0) + (y||0) + (z||0) }
96
- assert_equal 6, b.curry[1][2][3]
97
- assert_raises(ArgumentError) { b.curry[1, 2][3, 4] }
98
- assert_raises(ArgumentError) { b.curry(5) }
99
- assert_raises(ArgumentError) { b.curry(1) }
100
- end
101
- end
102
-
103
- context "arity < 0" do
104
- should "conform to docs" do
105
- b = lambda {|x, y, z, *w| (x||0) + (y||0) + (z||0) + w.inject(0, &:+) }
106
- assert_equal 6, b.curry[1][2][3]
107
- assert_equal 10, b.curry[1, 2][3, 4]
108
- assert_equal 15, b.curry(5)[1][2][3][4][5]
109
- assert_equal 15, b.curry(5)[1, 2][3, 4][5]
110
- assert_raises(ArgumentError) { b.curry(1) }
111
- end
112
- end
113
- end
114
- end
115
- end
116
- end