facets 2.0.0 → 2.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/AUTHORS +2 -0
- data/README +58 -140
- data/demo/bench/enumerable/bench_collect.rb +84 -0
- data/demo/bench/enumerable/bench_count.rb +58 -0
- data/demo/bench/{bench_factorial.rb → integer/bench_factorial.rb} +0 -0
- data/lib/core/facets/enumerable.rb +0 -1
- data/lib/core/facets/enumerable/collect.rb +152 -61
- data/lib/core/facets/enumerable/count.rb +12 -14
- data/lib/core/facets/integer/of.rb +8 -3
- data/lib/methods/facets/enumerable/cluster_by.rb +1 -1
- data/lib/methods/facets/enumerable/collect_if.rb +1 -1
- data/lib/methods/facets/enumerable/divide.rb +1 -1
- data/lib/methods/facets/enumerable/each_by.rb +1 -1
- data/lib/methods/facets/enumerable/each_pair.rb +1 -1
- data/lib/methods/facets/enumerable/eachn.rb +1 -1
- data/lib/methods/facets/enumerable/group_by.rb +1 -0
- data/lib/methods/facets/enumerable/map_if.rb +1 -1
- data/lib/methods/facets/enumerable/partition_by.rb +1 -1
- data/meta/manifest.txt +6 -3
- data/meta/version.txt +1 -1
- data/task/clean +2 -2
- data/task/groups +1 -0
- data/task/methods +7 -3
- data/task/rdoc.yaml +1 -0
- data/task/test +4 -2
- data/test/unit/enumerable/test_collect.rb +161 -38
- metadata +10 -8
- data/lib/core/facets/enumerable/partition.rb +0 -285
- data/test/unit/enumerable/test_partition.rb +0 -134
@@ -1,134 +0,0 @@
|
|
1
|
-
# _____ _
|
2
|
-
# |_ _|__ ___| |_
|
3
|
-
# | |/ _ \/ __| __|
|
4
|
-
# | | __/\__ \ |
|
5
|
-
# |_|\___||___/\__|
|
6
|
-
#
|
7
|
-
# for lib/facets/enumerable/partition.rb
|
8
|
-
#
|
9
|
-
# Extracted Mon Sep 03 16:23:07 -0700 2007
|
10
|
-
# w/ Test Extraction Ratchet
|
11
|
-
#
|
12
|
-
|
13
|
-
require 'facets/enumerable/partition.rb'
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
require 'test/unit'
|
18
|
-
require 'set'
|
19
|
-
|
20
|
-
class TestEnumerable < Test::Unit::TestCase
|
21
|
-
|
22
|
-
# def test_op_mod
|
23
|
-
# a = [:A,:B,:C]
|
24
|
-
# assert_equal( a[1], a/1 )
|
25
|
-
# assert_equal( :B, a/1 )
|
26
|
-
# end
|
27
|
-
#
|
28
|
-
# def test_op_div
|
29
|
-
# a = [:A,:B,:C]
|
30
|
-
# assert_equal( a[1], a/1 )
|
31
|
-
# assert_equal( :B, a/1 )
|
32
|
-
# end
|
33
|
-
|
34
|
-
def test_partition_by
|
35
|
-
x = (1..5).partition_by{ |n| n % 3 }
|
36
|
-
o = { 0 => [3], 1 => [1, 4], 2 => [2,5] }
|
37
|
-
assert_equal( o, x )
|
38
|
-
x = ["I had", 1, "dollar and", 50, "cents"].partition_by { |e| e.class }
|
39
|
-
o = { String => ["I had","dollar and","cents"], Fixnum => [1,50] }
|
40
|
-
assert_equal( o, x )
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_each_by_01
|
44
|
-
x = []
|
45
|
-
[1,2,3,4].each_by{ |a,b| x << [a,b] }
|
46
|
-
o = [[1,2],[3,4]]
|
47
|
-
assert_equal( o, x )
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_each_by_02
|
51
|
-
x = []
|
52
|
-
[1,2,3,4,5].each_by{ |a,b,c| x << [a,b,c] }
|
53
|
-
o = [[1,2,3],[4,5,nil]]
|
54
|
-
assert_equal( o, x )
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_each_by_03
|
58
|
-
x = []
|
59
|
-
[1,2,3,4].each_by(2){ |a,b| x << [a,b] }
|
60
|
-
o = [[1,2],[3,4]]
|
61
|
-
assert_equal( o, x )
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_each_by_04
|
65
|
-
x = []
|
66
|
-
[1,2,3,4,5,6,7,8].each_by(4){ |*a| x << a }
|
67
|
-
o = [ [[1,2,3,4]],[[5,6,7,8]] ]
|
68
|
-
assert_equal( o, x )
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_each_by_05
|
72
|
-
x = []
|
73
|
-
[1,2,3,4,5,6].each_by(3){ |*a| x << a }
|
74
|
-
o = [ [[1,2,3]],[[4,5,6]] ]
|
75
|
-
assert_equal( o, x )
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_each_by_06
|
79
|
-
a = [1,2,3,4,5,6]
|
80
|
-
r = []
|
81
|
-
a.each_by(2){ |x,y| r << [x,y] }
|
82
|
-
assert_equal( [[1,2],[3,4],[5,6]], r )
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_each_by_07
|
86
|
-
a = [1,2,3,4,5,6]
|
87
|
-
r = []
|
88
|
-
a.each_by(3){ |*e| r << e }
|
89
|
-
assert_equal( [ [[1,2,3]], [[4,5,6]] ], r )
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_each_pair
|
93
|
-
r = []
|
94
|
-
a = [1,2,3,4]
|
95
|
-
a.each_pair{ |a,b| r << [a,b] }
|
96
|
-
assert_equal( [[1,2],[3,4]], r )
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_each_unique_pair
|
100
|
-
r = []
|
101
|
-
a = [1,2,3,4]
|
102
|
-
a.each_unique_pair{ |a,b| r << [a,b] }
|
103
|
-
assert_equal( [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]], r )
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_eachn
|
107
|
-
x = []
|
108
|
-
[1,2,3,4].eachn{ |a,b| x << [a,b] }
|
109
|
-
o = [[1,2],[3,4]]
|
110
|
-
assert_equal( o, x )
|
111
|
-
|
112
|
-
x = []
|
113
|
-
[1,2,3,4,5].eachn{ |a,b,c| x << [a,b,c] }
|
114
|
-
o = [[1,2,3],[4,5,nil]]
|
115
|
-
assert_equal( o, x )
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_each_combination
|
119
|
-
r = []
|
120
|
-
a = [1,2,3,4]
|
121
|
-
a.each_combination(2){ |a,b| r << [a,b] }
|
122
|
-
assert_equal( [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]], r )
|
123
|
-
end
|
124
|
-
|
125
|
-
|
126
|
-
def test_collect_with_index
|
127
|
-
a = [1,2,3].collect_with_index{ |e,i| e*i }
|
128
|
-
assert_equal( [0,2,6], a )
|
129
|
-
end
|
130
|
-
|
131
|
-
end
|
132
|
-
|
133
|
-
|
134
|
-
|