rupture 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -0
- data/Rakefile +2 -10
- data/VERSION +1 -1
- data/init.rb +1 -0
- data/lib/rupture/array_seq.rb +65 -0
- data/lib/rupture/cons.rb +18 -0
- data/lib/rupture/core_ext.rb +21 -0
- data/lib/rupture/fn.rb +88 -0
- data/lib/rupture/function.rb +114 -0
- data/lib/rupture/lazy_seq.rb +35 -0
- data/lib/rupture/list.rb +31 -0
- data/lib/rupture/lookup.rb +24 -0
- data/lib/rupture/meta.rb +22 -0
- data/lib/rupture/rails_ext.rb +38 -0
- data/lib/rupture/reader.rb +110 -0
- data/lib/rupture/seq.rb +62 -0
- data/lib/rupture/sequence.rb +274 -0
- data/lib/rupture/symbol.rb +32 -0
- data/lib/rupture/utils.rb +7 -0
- data/lib/rupture.rb +20 -0
- data/rupture.gemspec +28 -6
- data/test/fn_test.rb +41 -0
- data/test/list_test.rb +20 -0
- data/test/meta_test.rb +43 -0
- data/test/seq_test.rb +255 -0
- data/test/test_helper.rb +11 -0
- metadata +29 -8
- data/README.rdoc +0 -0
data/test/seq_test.rb
ADDED
@@ -0,0 +1,255 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class SeqTest < Test::Unit::TestCase
|
4
|
+
empty_seqs = [nil, [], Rupture::Seq.empty, F.lazy_seq{nil}, F.lazy_seq{[]}]
|
5
|
+
|
6
|
+
def numbers(i)
|
7
|
+
F.lazy_seq { F.cons(i, numbers(i.inc))}
|
8
|
+
end
|
9
|
+
|
10
|
+
should "empty seqs" do
|
11
|
+
empty_seqs.each do |s|
|
12
|
+
assert_nil s.seq
|
13
|
+
assert_nil s.seq.first
|
14
|
+
assert s.seq.rest
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
should "empty lazy_seqs" do
|
19
|
+
empty_seqs.each do |s|
|
20
|
+
assert_nil F.lazy_seq{s}.seq
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
should "convert enumerables into seq" do
|
25
|
+
assert_equal [20,21,22].seq, (-22..22).seq.drop(42)
|
26
|
+
assert_equal [101,102].seq, (1..200).seq.drop(100).take(2)
|
27
|
+
assert_equal "bbq", ("bar".."foo").seq.drop(25).first
|
28
|
+
end
|
29
|
+
|
30
|
+
should "cons" do
|
31
|
+
empty_seqs.each do |cdr|
|
32
|
+
cons = F.cons(1,cdr)
|
33
|
+
assert cons.seq
|
34
|
+
assert_equal 1, cons.first
|
35
|
+
assert cons.rest
|
36
|
+
assert_nil cons.next
|
37
|
+
assert_nil cons.rest.seq
|
38
|
+
|
39
|
+
cons = F.cons(2, cons)
|
40
|
+
assert cons.seq
|
41
|
+
assert_equal 2, cons.first
|
42
|
+
assert cons.rest
|
43
|
+
assert cons.next
|
44
|
+
assert cons.rest.seq
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
should "conj" do
|
49
|
+
assert_equal [1,2,3,4].seq, [2,3,4].seq.conj(1)
|
50
|
+
assert_equal [1].seq, [].seq.conj(1)
|
51
|
+
end
|
52
|
+
|
53
|
+
should "into" do
|
54
|
+
assert_equal [1,2,3,4].seq, [3,4].seq.into([2,1])
|
55
|
+
assert_equal [1,2,3,4].seq, [].seq.into([4,3,2,1])
|
56
|
+
end
|
57
|
+
|
58
|
+
should "reverse and rseq" do
|
59
|
+
assert_equal [1,2,3,4].seq, [4,3,2,1].seq.reverse
|
60
|
+
assert_equal [1,2,3,4].seq, [4,3,2,1].rseq
|
61
|
+
assert_equal Rupture::Seq.empty, [].seq.reverse
|
62
|
+
end
|
63
|
+
|
64
|
+
should "count" do
|
65
|
+
assert_equal 0, nil.count
|
66
|
+
assert_equal 4, [1,1,1,1].seq.count
|
67
|
+
assert_equal 4, [1,1,1,1].rseq.count
|
68
|
+
assert_equal 6, F.list(1,2,3,4,5,6).count
|
69
|
+
assert_equal 2, F.cons(1, F.cons(2, nil)).count
|
70
|
+
end
|
71
|
+
|
72
|
+
should "destructuring" do
|
73
|
+
a,b = [1,2].seq
|
74
|
+
assert_equal 1, a
|
75
|
+
assert_equal 2, b
|
76
|
+
end
|
77
|
+
|
78
|
+
should "map" do
|
79
|
+
assert_equal [9,12,15].seq, F.map([1,2,3],[3,4,5],[5,6,7]) {|a,b,c| a + b + c}
|
80
|
+
assert_equal [9,12,15].seq, [3,4,5].seq.map {|a| a * 3}
|
81
|
+
end
|
82
|
+
|
83
|
+
should "concat" do
|
84
|
+
assert_equal [1,2,3,4,5,6].seq, F.concat([1,2],[3,4,5],[6])
|
85
|
+
assert_equal [1,2,3,4,5,6].seq, [1,2].seq.concat([3,4,5],[6])
|
86
|
+
end
|
87
|
+
|
88
|
+
should "mapcat" do
|
89
|
+
assert_equal [1,3,5,2,4,6,3,5,7].seq, F.mapcat([1,2,3],[3,4,5],[5,6,7]) {|a,b,c| [a,b,c]}
|
90
|
+
assert_equal [1,1,2,3,2,1,2,3].seq, [1,2].seq.mapcat {|a| [a,1,2,3]}
|
91
|
+
end
|
92
|
+
|
93
|
+
should "zip" do
|
94
|
+
assert_equal [[1,5],[2,6],[3,nil],[4,nil]].seq, F.zip([1,2,3,4],[5,6])
|
95
|
+
end
|
96
|
+
|
97
|
+
should "reduce" do
|
98
|
+
assert_equal 10, [1,2,3,4].seq.reduce(:+)
|
99
|
+
assert_equal 240, [1,2,3,4].seq.reduce(:*, 10)
|
100
|
+
end
|
101
|
+
|
102
|
+
should "foldr" do
|
103
|
+
assert_equal F.list(1,2,3,4), [1,2,3,4].seq.foldr(F[:cons], nil)
|
104
|
+
end
|
105
|
+
|
106
|
+
should "take" do
|
107
|
+
nums = [1,2,3,4,5,6,7,8,9,10].seq
|
108
|
+
|
109
|
+
assert_equal nums, numbers(1).take(10)
|
110
|
+
assert_equal Rupture::LazySeq, nums.take(10).class
|
111
|
+
assert_equal nums, nums.take(10)
|
112
|
+
|
113
|
+
assert nums.take(0) # lazy-seq, not nil
|
114
|
+
end
|
115
|
+
|
116
|
+
should "drop" do
|
117
|
+
nums = [101,102,103,104,105,106,107,108,109,110].seq
|
118
|
+
|
119
|
+
assert_equal nums, numbers(1).drop(100).take(10)
|
120
|
+
assert_equal [110].seq, nums.drop(9)
|
121
|
+
assert_equal [1,2,3].seq, [1,2,3].seq.drop(0)
|
122
|
+
|
123
|
+
assert nums.drop(100)
|
124
|
+
end
|
125
|
+
|
126
|
+
should "take_last" do
|
127
|
+
nums = [101,102,103,104,105,106,107,108,109,110].seq
|
128
|
+
|
129
|
+
assert_equal [109,110].seq, nums.take_last(2)
|
130
|
+
assert_equal [110].seq, nums.take_last(1)
|
131
|
+
assert_equal nil, nums.take_last(0).seq
|
132
|
+
end
|
133
|
+
|
134
|
+
should "drop_last" do
|
135
|
+
nums = [101,102,103,104,105,106,107,108,109,110].seq
|
136
|
+
|
137
|
+
assert_equal [101,102].seq, nums.drop_last(8)
|
138
|
+
assert_equal [101].seq, nums.drop_last(9)
|
139
|
+
assert_equal nil, nums.drop_last(10).seq
|
140
|
+
end
|
141
|
+
|
142
|
+
should "last" do
|
143
|
+
assert_equal 110, [101,102,103,104,105,106,107,108,109,110].last
|
144
|
+
assert_equal nil, [].last
|
145
|
+
end
|
146
|
+
|
147
|
+
should "every?" do
|
148
|
+
assert_equal true, [2,4,6,8,10].seq.every?(:even?)
|
149
|
+
assert_equal false, [2,4,6,8,11].seq.every?(:even?)
|
150
|
+
assert_equal true, [2,4,8].seq.every?
|
151
|
+
assert_equal false, [2,nil,4,8].seq.every?
|
152
|
+
end
|
153
|
+
|
154
|
+
should "some" do
|
155
|
+
assert_equal true, [2,4,6,8,11].seq.some(:even?)
|
156
|
+
assert_equal nil, [2,4,6,8,10].seq.some(:odd?)
|
157
|
+
assert_equal 2, [2,4,8].seq.some
|
158
|
+
assert_equal nil, [false,false,nil].seq.some
|
159
|
+
end
|
160
|
+
|
161
|
+
should "split_at" do
|
162
|
+
assert_equal [[1,2,3].seq,[4,5,6].seq], [1,2,3,4,5,6].seq.split_at(3)
|
163
|
+
end
|
164
|
+
|
165
|
+
should "take_while" do
|
166
|
+
nums = [1,2,3,4,5,6,7].seq
|
167
|
+
|
168
|
+
assert_equal nums, numbers(1).take_while {|i| i < 8}
|
169
|
+
assert_equal Rupture::LazySeq, nums.take_while {|i| i < 3}.class
|
170
|
+
assert_equal [1,2].seq, nums.take_while {|i| i < 3}
|
171
|
+
end
|
172
|
+
|
173
|
+
should "drop_while" do
|
174
|
+
nums = [11,12,13,14,15,16,17].seq
|
175
|
+
|
176
|
+
assert_equal nums, numbers(1).drop_while {|i| i < 11}.take(7)
|
177
|
+
assert_equal Rupture::LazySeq, nums.drop_while {|i| i < 16}.class
|
178
|
+
assert_equal [16,17].seq, nums.drop_while {|i| i < 16}
|
179
|
+
end
|
180
|
+
|
181
|
+
should "split_with" do
|
182
|
+
assert_equal [[1,2,3].seq,[4,5,6].seq], [1,2,3,4,5,6].seq.split_with {|i| i < 4}
|
183
|
+
end
|
184
|
+
|
185
|
+
should "==" do
|
186
|
+
a = F.cons(1, F.cons(2, nil))
|
187
|
+
b = F.cons(1, nil)
|
188
|
+
c = F.list(1, 2)
|
189
|
+
|
190
|
+
assert_equal a, c
|
191
|
+
assert_not_equal a, b
|
192
|
+
assert_not_equal b, c
|
193
|
+
end
|
194
|
+
|
195
|
+
should "filter" do
|
196
|
+
assert_equal [2,4,6].seq, [1,2,3,4,5,6].seq.filter(:even?)
|
197
|
+
end
|
198
|
+
|
199
|
+
should "remove" do
|
200
|
+
assert_equal [1,3,5].seq, [1,2,3,4,5,6].seq.remove(:even?)
|
201
|
+
end
|
202
|
+
|
203
|
+
should "separate" do
|
204
|
+
assert_equal [[2,4,6].seq,[1,3,5].seq], [1,2,3,4,5,6].seq.separate(:even?)
|
205
|
+
end
|
206
|
+
|
207
|
+
should "flatten" do
|
208
|
+
base = [1,3,5].seq
|
209
|
+
assert_equal base, base.flatten
|
210
|
+
assert_equal base, [[1,3,[[5]]]].seq.flatten
|
211
|
+
end
|
212
|
+
|
213
|
+
should "iterate" do
|
214
|
+
assert_equal [1024, 2048].seq, F.iterate(1) {|x| x * 2}.drop(10).take(2)
|
215
|
+
assert_equal [11, 12, 13].seq, F.iterate(:inc, 1).drop(10).take(3)
|
216
|
+
end
|
217
|
+
|
218
|
+
should "repeat" do
|
219
|
+
assert_equal [1,1,1].seq, F.repeat(1).take(3)
|
220
|
+
assert_equal [:foo, :foo].seq, F.repeat(2,:foo)
|
221
|
+
assert_equal nil, F.repeat(0,:foo).seq
|
222
|
+
assert_equal nil, F.repeat(-1,:foo).seq
|
223
|
+
end
|
224
|
+
|
225
|
+
should "repeatedly" do
|
226
|
+
i = 0
|
227
|
+
f = lambda {i += 1}
|
228
|
+
|
229
|
+
assert_equal [1,2,3].seq, F.repeatedly(f).take(3)
|
230
|
+
assert_equal [4,5].seq, F.repeatedly(2,f)
|
231
|
+
assert_equal nil, F.repeatedly(0,f).seq
|
232
|
+
assert_equal nil, F.repeatedly(-1,f).seq
|
233
|
+
end
|
234
|
+
|
235
|
+
should "partition" do
|
236
|
+
assert_equal [[1,2],[3,4]].seq.map(:seq), [1,2,3,4,5].seq.partition(2)
|
237
|
+
assert_equal [[1,2],[2,3],[3,4]].seq.map(:seq), [1,2,3,4].seq.partition(2,1)
|
238
|
+
assert_equal [[1,2],[4,5]].seq.map(:seq), [1,2,3,4,5].seq.partition(2,3)
|
239
|
+
assert_equal [[1,2],[3,4],[5,6]].seq.map(:seq), [1,2,3,4,5].seq.partition(2,2,[6,6,6])
|
240
|
+
end
|
241
|
+
|
242
|
+
should "partition_all" do
|
243
|
+
assert_equal [[1,2],[3,4],[5]].seq.map(:seq), [1,2,3,4,5].seq.partition_all(2)
|
244
|
+
assert_equal [[1,2],[2,3],[3]].seq.map(:seq), [1,2,3].seq.partition_all(2,1)
|
245
|
+
end
|
246
|
+
|
247
|
+
should "partition_by" do
|
248
|
+
assert_equal [[1,3,5,3,9]].seq.map(:seq), [1,3,5,3,9].seq.partition_by {|i| i.odd?}
|
249
|
+
assert_equal [[1,3], [2,4], [3], [4,8]].seq.map(:seq), [1,3,2,4,3,4,8].seq.partition_by {|i| i.odd?}
|
250
|
+
end
|
251
|
+
|
252
|
+
should "partition_between" do
|
253
|
+
assert_equal [[1], [nil, 4, 3], [nil, 8]].seq.map(:seq), [1,nil,4,3,nil,8].seq.partition_between {|a,b| b == nil}
|
254
|
+
end
|
255
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rupture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.0
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Justin Balthrop
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-09-09 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -27,14 +27,35 @@ extensions: []
|
|
27
27
|
|
28
28
|
extra_rdoc_files:
|
29
29
|
- LICENSE
|
30
|
-
- README.
|
30
|
+
- README.md
|
31
31
|
files:
|
32
32
|
- LICENSE
|
33
|
-
- README.
|
33
|
+
- README.md
|
34
34
|
- Rakefile
|
35
35
|
- VERSION
|
36
|
+
- init.rb
|
37
|
+
- lib/rupture.rb
|
38
|
+
- lib/rupture/array_seq.rb
|
39
|
+
- lib/rupture/cons.rb
|
40
|
+
- lib/rupture/core_ext.rb
|
41
|
+
- lib/rupture/fn.rb
|
42
|
+
- lib/rupture/function.rb
|
43
|
+
- lib/rupture/lazy_seq.rb
|
44
|
+
- lib/rupture/list.rb
|
45
|
+
- lib/rupture/lookup.rb
|
46
|
+
- lib/rupture/meta.rb
|
47
|
+
- lib/rupture/rails_ext.rb
|
48
|
+
- lib/rupture/reader.rb
|
36
49
|
- lib/rupture/seq.rb
|
50
|
+
- lib/rupture/sequence.rb
|
51
|
+
- lib/rupture/symbol.rb
|
52
|
+
- lib/rupture/utils.rb
|
37
53
|
- rupture.gemspec
|
54
|
+
- test/fn_test.rb
|
55
|
+
- test/list_test.rb
|
56
|
+
- test/meta_test.rb
|
57
|
+
- test/seq_test.rb
|
58
|
+
- test/test_helper.rb
|
38
59
|
has_rdoc: true
|
39
60
|
homepage: http://github.com/flatland/rupture
|
40
61
|
licenses: []
|
@@ -65,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
86
|
requirements: []
|
66
87
|
|
67
88
|
rubyforge_project:
|
68
|
-
rubygems_version: 1.
|
89
|
+
rubygems_version: 1.3.7
|
69
90
|
signing_key:
|
70
91
|
specification_version: 3
|
71
92
|
summary: Clojure sequence functions for Ruby.
|
data/README.rdoc
DELETED
File without changes
|