mll 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +43 -0
- data/Gemfile.lock +29 -0
- data/README.md +71 -3
- data/lib/mll.rb +36 -2
- data/mll.gemspec +1 -1
- data/spec/_spec.rb +197 -23
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66cecae3ebfe3b1589979a8146bb036f5f8a7203
|
4
|
+
data.tar.gz: dd4fd79c9a5684e9cdefa25845a0530c1c897b5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b0b5f12be754586a9e65a437924d5ac6153596c9fc5225da5820948b8f1fb10b49b42db02ac89a089f3872b26aba8d8896b5ae5d6bc4479d41398f3dc4ec18c
|
7
|
+
data.tar.gz: 5fe76c75a56556b8e77e7855e28d006828fb963e1f943b14a7ec7ab4051c691280f365d25a9bbdb3640b82859bf1816b3f6ef44b033c149fcf89504a5af9ec75
|
data/.travis.yml
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.2
|
4
|
+
- 1.9.3
|
5
|
+
- 2.0.0
|
6
|
+
- 2.0.0-p451 # OS X 10.9.4
|
7
|
+
- 2.1.0
|
8
|
+
- 2.1.2
|
9
|
+
- 2.1.3
|
10
|
+
- "2.1"
|
11
|
+
- 2.2.0
|
12
|
+
- "2.2"
|
13
|
+
- ruby-head
|
14
|
+
- jruby-19mode
|
15
|
+
- jruby-head
|
16
|
+
- rbx
|
17
|
+
- rbx-2
|
18
|
+
os:
|
19
|
+
- linux
|
20
|
+
- osx
|
21
|
+
matrix:
|
22
|
+
allow_failures:
|
23
|
+
- rvm: 1.9.2 # "undefined method `lazy' for []:Array"
|
24
|
+
os: linux
|
25
|
+
- rvm: 1.9.2 # "Requested binary installation but no rubies are available to download"
|
26
|
+
os: osx
|
27
|
+
- rvm: 1.9.3 # "undefined method `lazy' for []:Array"
|
28
|
+
- rvm: "2.2" # "Requested binary installation but no rubies are available to download"
|
29
|
+
os: osx
|
30
|
+
- rvm: ruby-head # "undefined method `hexdigest' for #<OpenSSL::Digest:0x007fda73e3b458>"
|
31
|
+
os: osx
|
32
|
+
- rvm: jruby-19mode # "undefined method `lazy' for []:Array"
|
33
|
+
os: linux
|
34
|
+
- rvm: jruby-19mode # "Requested binary installation but no rubies are available to download"
|
35
|
+
os: osx
|
36
|
+
- rvm: jruby-head # 4 failures in #map
|
37
|
+
- rvm: rbx # 5 failures
|
38
|
+
- rvm: rbx-2 # 5 failures
|
39
|
+
env:
|
40
|
+
- rvm_max_time_flag=60
|
41
|
+
before_install:
|
42
|
+
- gem install bundler
|
43
|
+
script: rake spec
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mll (2.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.2.5)
|
10
|
+
rspec (3.1.0)
|
11
|
+
rspec-core (~> 3.1.0)
|
12
|
+
rspec-expectations (~> 3.1.0)
|
13
|
+
rspec-mocks (~> 3.1.0)
|
14
|
+
rspec-core (3.1.7)
|
15
|
+
rspec-support (~> 3.1.0)
|
16
|
+
rspec-expectations (3.1.2)
|
17
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
18
|
+
rspec-support (~> 3.1.0)
|
19
|
+
rspec-mocks (3.1.3)
|
20
|
+
rspec-support (~> 3.1.0)
|
21
|
+
rspec-support (3.1.2)
|
22
|
+
|
23
|
+
PLATFORMS
|
24
|
+
ruby
|
25
|
+
|
26
|
+
DEPENDENCIES
|
27
|
+
bundler (~> 1.7)
|
28
|
+
mll!
|
29
|
+
rspec (~> 3.1.0)
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# MLL (Mathematica Language Library)
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/mll.svg)](http://badge.fury.io/rb/mll)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/mll.svg)](http://badge.fury.io/rb/mll)
|
4
|
+
[![Build Status](https://travis-ci.org/Nakilon/mll.svg)](https://travis-ci.org/Nakilon/mll)
|
4
5
|
|
5
6
|
### What
|
6
7
|
|
@@ -99,7 +100,7 @@ module MLL
|
|
99
100
|
def dimensions
|
100
101
|
lambda do |list, limit = nil|
|
101
102
|
enumerator = Enumerator.new do |e|
|
102
|
-
while list.
|
103
|
+
while list.all?{ |i| i.respond_to? :each } &&
|
103
104
|
# TODO refactor into depth-first yielding
|
104
105
|
def nest_while
|
105
106
|
# TODO finish me
|
@@ -115,7 +116,12 @@ module MLL
|
|
115
116
|
}]].tap do |stack|
|
116
117
|
stack.each do |ai, ri|
|
117
118
|
# TODO try to make #table lazy (Enumerator instead of Array)
|
119
|
+
def grid
|
120
|
+
lambda do |table, **options|
|
121
|
+
# TODO smth with this #.all?
|
122
|
+
# TODO https://reference.wolfram.com/language/ref/Alignment.html
|
118
123
|
# TODO not sure if we need any other kind of Listability except of #range[[Array]]
|
124
|
+
# TODO #power[]
|
119
125
|
```
|
120
126
|
|
121
127
|
#### spec/_spec.rb
|
@@ -127,6 +133,8 @@ module MLL
|
|
127
133
|
# TODO ? let(:fake_lambda){ ->(*args){fail} }
|
128
134
|
# TODO rewrite all Lazy#to_a into Lazy#force (it's not recursive and not documented)
|
129
135
|
# TODO maybe make indexes count from 0 not 1
|
136
|
+
# TODO merge similar examples
|
137
|
+
# TODO deprecate tests that would obviously fail another tests
|
130
138
|
describe MLL do
|
131
139
|
describe "List Manipulation" do
|
132
140
|
describe "Constructing Lists" do
|
@@ -141,7 +149,7 @@ describe MLL do
|
|
141
149
|
# TODO maybe move it to README.md
|
142
150
|
describe "#map" do
|
143
151
|
# TODO we'll need less nested mappings when we implement stop on depths depletion
|
144
|
-
describe "Details
|
152
|
+
describe "Details:" do
|
145
153
|
example "levels n1 though n2" do
|
146
154
|
expect(map[[1,[2,[3,[4,[5,6]]]]], [2,4], ->(i){ [i] }].
|
147
155
|
# TODO smth _<>
|
@@ -161,6 +169,7 @@ describe MLL do
|
|
161
169
|
# TODO move #nest_list and #fold_list and others here?
|
162
170
|
# TODO examples in README.rb
|
163
171
|
describe "#nest_while" do
|
172
|
+
# TODO examples to README.md
|
164
173
|
describe "Details:" do
|
165
174
|
# TODO a lot
|
166
175
|
describe "Scope:" do
|
@@ -175,6 +184,65 @@ describe MLL do
|
|
175
184
|
# TODO example "find the next twin prime after 888" do
|
176
185
|
describe "Properties & Relations:" do
|
177
186
|
# TODO "#nest_while can be expressed in terms of a while loop" do
|
187
|
+
describe "Numerical Data" do
|
188
|
+
describe "#mean" do
|
189
|
+
# TODO examples to README.md
|
190
|
+
describe "Grids & Tables" do
|
191
|
+
describe "#grid" do
|
192
|
+
describe "Details:" do
|
193
|
+
# TODO SpanFromLeft SpanFromAbove SpanFromBoth
|
194
|
+
# TODO The following options can be given
|
195
|
+
# TODO Common settings for Frame
|
196
|
+
# TODO The spec(k) can have the following forms
|
197
|
+
# TODO With ItemSize->Automatic will break elements across multiple lines
|
198
|
+
# TODO "settings can be used for BaselinePosition" do
|
199
|
+
describe "Scope:" do
|
200
|
+
# TODO Draw all the frames in red
|
201
|
+
# TODO Put a frame around the first row and column
|
202
|
+
# TODO Draw different frames with different styles
|
203
|
+
# TODO Put dividers at all horizontal positions
|
204
|
+
# TODO Put dividers at all vertical positions
|
205
|
+
# TODO Put dividers at the third horizontal and second vertical positions
|
206
|
+
# TODO Make the element 4 span the column to its right
|
207
|
+
# TODO Make it span three rows
|
208
|
+
# TODO Span throughout a 2×2 block
|
209
|
+
# TODO Draw the grid with a pink background
|
210
|
+
# TODO Alternating pink and yellow at successive horizontal positions
|
211
|
+
# TODO Alternating pink and yellow at successive vertical positions
|
212
|
+
# TODO Make the grid contents red
|
213
|
+
# TODO "set the horizontal spacing between items" do
|
214
|
+
# TODO "set the horizontal and vertical spacings" do
|
215
|
+
# TODO "grids can be nested" do
|
216
|
+
describe "Options:" do
|
217
|
+
# TODO "align elements around the center of the grid" do
|
218
|
+
# TODO "align numbers on the decimal point" do
|
219
|
+
# TODO draw the grid with a pink background
|
220
|
+
# TODO Pink and gray backgrounds for the first and second columns
|
221
|
+
# TODO An equivalent syntax
|
222
|
+
# TODO Pink and gray backgrounds for the first and second rows
|
223
|
+
# TODO Alternating pink and gray backgrounds
|
224
|
+
# TODO Alternating backgrounds with yellow superimposed in the first and last positions
|
225
|
+
# TODO Set the background for specific items
|
226
|
+
# TODO Set the background for a subregion of the grid
|
227
|
+
# TODO Draw all interior dividers
|
228
|
+
# TODO Draw a divider at every other horizontal position
|
229
|
+
# TODO Include the final position
|
230
|
+
# TODO Draw dividers with specified styles
|
231
|
+
# TODO "frame specific elements" do
|
232
|
+
# TODO "frame a region" do
|
233
|
+
# TODO "make each item a fixed number of character-widths wide" do
|
234
|
+
# TODO "ItemSize->All makes all items the same size" do
|
235
|
+
# TODO "prevent line-wrapping" do
|
236
|
+
# TODO "set one overall style for grid items" do
|
237
|
+
# TODO "style specific elements" do
|
238
|
+
# TODO "style a region" do
|
239
|
+
# TODO "insert no additional space between rows or columns" do
|
240
|
+
# TODO "specify spacing with numeric values" do
|
241
|
+
# TODO "use different spacings at the first vertical divider" do
|
242
|
+
describe "Properties & Relations:" do
|
243
|
+
# TODO "the elements of a Grid can be extracted with #[]" do
|
244
|
+
describe "Neat examples:" do
|
245
|
+
# TODO "a Sudoku grid" do
|
178
246
|
# TODO http://reference.wolfram.com/language/guide/HandlingArraysOfData.html
|
179
247
|
# TODO http://reference.wolfram.com/language/guide/ComputationWithStructuredDatasets.html
|
180
248
|
```
|
data/lib/mll.rb
CHANGED
@@ -7,7 +7,7 @@ module MLL
|
|
7
7
|
list = [list]
|
8
8
|
enumerator = Enumerator.new do |e|
|
9
9
|
# String.size shall not pass
|
10
|
-
while list.
|
10
|
+
while list.all?{ |i| i.respond_to? :each } &&
|
11
11
|
list.map(&:size).uniq.size == 1
|
12
12
|
# TODO refactor into depth-first yielding
|
13
13
|
e << list.first.size
|
@@ -103,7 +103,7 @@ module MLL
|
|
103
103
|
# "undefined method `replace' for #<Enumerator::Lazy: []>"
|
104
104
|
ai.replace ri.first.map{ |i|
|
105
105
|
if ri.size == 1
|
106
|
-
f.call(*ai, i)
|
106
|
+
f.respond_to?(:call) ? f.call(*ai, i) : f
|
107
107
|
else
|
108
108
|
[*ai.dup, i].tap{ |t| stack << [t, ri.drop(1)] }
|
109
109
|
end
|
@@ -114,6 +114,39 @@ module MLL
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
+
# http://www.unicode.org/charts/PDF/U2500.pdf
|
118
|
+
# https://en.wikipedia.org/wiki/Box_Drawing
|
119
|
+
def grid
|
120
|
+
lambda do |table, **options|
|
121
|
+
raise ArgumentError.new("unknown value of :alignment option '#{options[:alignment]}'") unless \
|
122
|
+
alignment = {
|
123
|
+
nil => :center,
|
124
|
+
:center => :center,
|
125
|
+
:left => :ljust,
|
126
|
+
:right => :rjust,
|
127
|
+
}[options[:alignment]]
|
128
|
+
frames = {
|
129
|
+
nil => " ",
|
130
|
+
true => "┃ ┏┓ ┗┛━ ┃━━┃ ",
|
131
|
+
:all => "┃┃┏┓╋┗┛━━┣┳┻┫ ",
|
132
|
+
}[options[:frame]]
|
133
|
+
raise ArgumentError.new("unknown value of :frame option '#{options[:frame]}'") if options[:frame] && !frames
|
134
|
+
# TODO smth with this #.all?
|
135
|
+
table = [table] unless table.all?{ |e| e.respond_to? :each }
|
136
|
+
width = table.map(&:size).max - 1
|
137
|
+
strings = table.map{ |row| row.dup.tap{ |a| a[width] = a[width] }.map(&:to_s) }
|
138
|
+
sizes = strings.transpose.map{ |col| col.map(&:size).max }
|
139
|
+
# TODO https://reference.wolfram.com/language/ref/Alignment.html
|
140
|
+
[
|
141
|
+
[frames[2], sizes.map{ |size| frames[7] * size }.join(frames[10]), frames[3]].join,
|
142
|
+
strings.map{ |row| [frames[0], row.zip(sizes).map{ |str, size| str.method(alignment).call size }.join(frames[1]), frames[0]].join }.join(
|
143
|
+
[?\n, frames[9], sizes.map{ |size| frames[8] * size }.join(frames[4]), frames[12], ?\n].join
|
144
|
+
),
|
145
|
+
[frames[5], sizes.map{ |size| frames[7] * size }.join(frames[11]), frames[6]].join,
|
146
|
+
].join(?\n) + ?\n
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
117
150
|
def define_listable_function name, &block
|
118
151
|
(class << self; self end).class_eval do
|
119
152
|
define_method name do
|
@@ -175,6 +208,7 @@ module MLL
|
|
175
208
|
define_listable_function(:divide) { |*args| raise ArgumentError.new("need two arguments") unless args.size == 2 ; args[0] / args[1] }
|
176
209
|
define_listable_function(:_plus) { |*args| raise ArgumentError.new("need two arguments") unless args.size == 2 ; args[0] + args[1] }
|
177
210
|
define_listable_function(:_times) { |*args| raise ArgumentError.new("need two arguments") unless args.size == 2 ; args[0] * args[1] }
|
211
|
+
# TODO #power[]
|
178
212
|
# define_listable_function (:power) { |*args| raise ArgumentError.new("need two arguments") unless args.size == 2 ; args[0] ** args[1] }
|
179
213
|
|
180
214
|
# http://reference.wolfram.com/language/ref/Orderless.html
|
data/mll.gemspec
CHANGED
data/spec/_spec.rb
CHANGED
@@ -18,6 +18,13 @@ require_relative File.join "..", "lib", "mll"
|
|
18
18
|
|
19
19
|
# TODO maybe make indexes count from 0 not 1
|
20
20
|
|
21
|
+
# TODO merge similar examples
|
22
|
+
# TODO deprecate tests that would obviously fail another tests
|
23
|
+
|
24
|
+
|
25
|
+
# File.read("spec/_spec.rb").scan(/.*\n/).each_with_index{ |e,i| p [i+1,e] if e["\xe2\x80\x90"] || e["\xc3\x97"] }; 0
|
26
|
+
|
27
|
+
|
21
28
|
# http://reference.wolfram.com/language/guide/LanguageOverview.html
|
22
29
|
describe MLL do
|
23
30
|
|
@@ -51,7 +58,7 @@ describe MLL do
|
|
51
58
|
|
52
59
|
describe "Scope:" do
|
53
60
|
|
54
|
-
example "threads element
|
61
|
+
example "threads element-wise over lists" do
|
55
62
|
expect(subtract[[1,2,3,4],0.5]).to be_a Enumerator
|
56
63
|
expect(subtract[[1,2,3,4],0.5].to_a).to eq [0.5,1.5,2.5,3.5]
|
57
64
|
expect(subtract[6,[3,2]]).to be_a Enumerator
|
@@ -92,7 +99,7 @@ describe MLL do
|
|
92
99
|
|
93
100
|
describe "Scope:" do
|
94
101
|
|
95
|
-
example "threads element
|
102
|
+
example "threads element-wise over lists" do
|
96
103
|
expect(divide[[2,3,4,5],2.0]).to be_a Enumerator
|
97
104
|
expect(divide[[2,3,4,5],2.0].to_a).to eq [1,1.5,2,2.5]
|
98
105
|
expect(divide[6,[3,2]]).to be_a Enumerator
|
@@ -140,7 +147,7 @@ describe MLL do
|
|
140
147
|
example "sums numbers" do
|
141
148
|
expect(plus[2,3,4]).to eq 9
|
142
149
|
end
|
143
|
-
example "threads element
|
150
|
+
example "threads element-wise over lists" do
|
144
151
|
# idk why not in Scope
|
145
152
|
expect(plus[[3,4,5],2]).to be_a Enumerator
|
146
153
|
expect(plus[[3,4,5],2].to_a).to eq [5,6,7]
|
@@ -154,7 +161,7 @@ describe MLL do
|
|
154
161
|
|
155
162
|
describe "Scope:" do
|
156
163
|
|
157
|
-
example "threads element
|
164
|
+
example "threads element-wise over lists" do
|
158
165
|
expect(plus[[10,20,30],[1,2,3]]).to be_a Enumerator
|
159
166
|
expect(plus[[10,20,30],[1,2,3]].to_a).to eq [11,22,33]
|
160
167
|
expect(plus[[[1,2],[3,4]],5]).to be_a Enumerator
|
@@ -198,7 +205,7 @@ describe MLL do
|
|
198
205
|
example "multiplies numbers" do
|
199
206
|
expect(times[2,3,4]).to eq 24
|
200
207
|
end
|
201
|
-
example "threads element
|
208
|
+
example "threads element-wise over lists" do
|
202
209
|
expect(times[[3,4,5],2]).to be_a Enumerator
|
203
210
|
expect(times[[3,4,5],2].to_a).to eq [6,8,10]
|
204
211
|
expect(times[2,3,[4,5]]).to be_a Enumerator
|
@@ -211,7 +218,7 @@ describe MLL do
|
|
211
218
|
|
212
219
|
describe "Scope:" do
|
213
220
|
|
214
|
-
example "threads element
|
221
|
+
example "threads element-wise over lists" do
|
215
222
|
expect(times[[2,3],[4,5]]).to be_a Enumerator
|
216
223
|
expect(times[[2,3],[4,5]].to_a).to eq [8,15]
|
217
224
|
expect(times[[[1,2],[3,4]],5]).to be_a Enumerator
|
@@ -257,14 +264,18 @@ describe MLL do
|
|
257
264
|
expect(table[->(i){ i+2 }, [0, 20, 2]]).to be_a Array
|
258
265
|
expect(table[->(i){ i+2 }, [0, 20, 2]]).to eq [2,4,6,8,10,12,14,16,18,20,22]
|
259
266
|
end
|
260
|
-
example "
|
267
|
+
example "a list of 10 x's" do
|
268
|
+
expect(table[?x, 10]).to be_a Array
|
269
|
+
expect(table[?x, 10]).to eq [?x]*10
|
270
|
+
end
|
271
|
+
example "make a 4x3 matrix" do
|
261
272
|
expect(table[->(i,j){ 10*i + j }, 4, 3]).to be_a Array
|
262
273
|
expect(table[->(i,j){ 10*i + j }, 4, 3]).to eq [[11,12,13],[21,22,23],[31,32,33],[41,42,43]]
|
263
274
|
end
|
264
275
|
|
265
276
|
end
|
266
277
|
|
267
|
-
example "table
|
278
|
+
example "table[lambda, n1, min..max, [max, min, -step]]" do
|
268
279
|
expect(table[->(i,j,k){ [i,j,k] }, 3, 2..3, [5, 1, -2]]).to be_a Array
|
269
280
|
expect(table[->(i,j,k){ [i,j,k] }, 3, 2..3, [5, 1, -2]]).to eq \
|
270
281
|
[
|
@@ -289,7 +300,7 @@ describe MLL do
|
|
289
300
|
|
290
301
|
describe "Applications:" do
|
291
302
|
|
292
|
-
example "column table
|
303
|
+
example "column table[binomial, ]" do
|
293
304
|
skip "#binomial and #column are yet to be implemented"
|
294
305
|
end
|
295
306
|
|
@@ -323,15 +334,15 @@ describe MLL do
|
|
323
334
|
|
324
335
|
describe "Basic Examples:" do
|
325
336
|
|
326
|
-
example "range
|
337
|
+
example "range[n]" do
|
327
338
|
expect(range[4]).to be_a Enumerator
|
328
339
|
expect(range[4].to_a).to eq [1,2,3,4]
|
329
340
|
end
|
330
|
-
example "range
|
341
|
+
example "range[n1, n2]" do
|
331
342
|
expect(range[2,5]).to be_a Enumerator
|
332
343
|
expect(range[2,5].to_a).to eq [2,3,4,5]
|
333
344
|
end
|
334
|
-
example "range
|
345
|
+
example "range[min, max, step]" do
|
335
346
|
expect(range[1,2,0.5]).to be_a Enumerator
|
336
347
|
expect(range[1,2,0.5].to_a).to eq [1,1.5,2] # can be precision problems
|
337
348
|
expect(range[2,6,2].to_a).to eq [2,4,6]
|
@@ -341,7 +352,7 @@ describe MLL do
|
|
341
352
|
end
|
342
353
|
|
343
354
|
# NOTE: Wolfram Mathematica can't do this
|
344
|
-
example "range
|
355
|
+
example "range[max, min, -step]" do
|
345
356
|
expect(range[10,-5,-2]).to be_a Enumerator
|
346
357
|
expect(range[10,-5,-2].to_a).to eq [10,8,6,4,2,0,-2,-4]
|
347
358
|
expect(range[3,1,-1].to_a).to eq [3,2,1]
|
@@ -381,7 +392,7 @@ describe MLL do
|
|
381
392
|
|
382
393
|
end
|
383
394
|
|
384
|
-
example "range
|
395
|
+
example "range[min..max]" do
|
385
396
|
expect(range[1..3]).to be_a Enumerator
|
386
397
|
range[1..3].each do |i|
|
387
398
|
expect(i).to be_a Enumerator
|
@@ -446,7 +457,7 @@ describe MLL do
|
|
446
457
|
end
|
447
458
|
|
448
459
|
# NOTE: Wolfram Mathematica can't do this
|
449
|
-
example "subdivide
|
460
|
+
example "subdivide[max, min, n]" do
|
450
461
|
expect(subdivide[1,-1,8]).to be_a Enumerator
|
451
462
|
expect(subdivide[1,-1,8].to_a).to eq [1,0.75,0.5,0.25,0,-0.25,-0.5,-0.75,-1]
|
452
463
|
end
|
@@ -455,7 +466,7 @@ describe MLL do
|
|
455
466
|
|
456
467
|
describe "Properties & Relations:" do
|
457
468
|
|
458
|
-
example "subdivide[xmin,xmax,n] is equivalent to xmin+(xmax-xmin)Range[0,n]/n" do
|
469
|
+
example "subdivide[xmin, xmax, n] is equivalent to xmin+(xmax-xmin)Range[0,n]/n" do
|
459
470
|
expect(subdivide[2,10,4].to_a).to eq plus[2,divide[times[10-2,range[0,4]],4]].to_a
|
460
471
|
end
|
461
472
|
|
@@ -618,7 +629,7 @@ describe MLL do
|
|
618
629
|
|
619
630
|
# TODO we'll need less nested mappings when we implement stop on depths depletion
|
620
631
|
|
621
|
-
describe "Details
|
632
|
+
describe "Details:" do
|
622
633
|
|
623
634
|
example "levels n1 though n2" do
|
624
635
|
expect(map[[1,[2,[3,[4,[5,6]]]]], [2,4], ->(i){ [i] }]).to be_a Enumerator
|
@@ -791,6 +802,8 @@ describe MLL do
|
|
791
802
|
# http://reference.wolfram.com/language/ref/NestWhile.html
|
792
803
|
describe "#nest_while" do
|
793
804
|
|
805
|
+
# TODO examples to README.md
|
806
|
+
|
794
807
|
describe "Details:" do
|
795
808
|
# TODO a lot
|
796
809
|
end
|
@@ -869,12 +882,10 @@ describe MLL do
|
|
869
882
|
expect(tally[[1, 1, 2, 1, 3, 2, 1]]).to be_a Hash
|
870
883
|
expect(tally[[1, 1, 2, 1, 3, 2, 1]]).to eq({1=>4, 2=>2, 3=>1})
|
871
884
|
end
|
872
|
-
|
873
885
|
example "use test argument to count elements with the same class" do
|
874
886
|
expect(tally[[[1,2], [1,2,3,4], 1, [1,2,3,4], 1], ->(i,j){ i.class == j.class }]).to be_a Hash
|
875
887
|
expect(tally[[[1,2], [1,2,3,4], 1, [1,2,3,4], 1], ->(i,j){ i.class == j.class }]).to eq({[1,2]=>3, 1=>2})
|
876
888
|
end
|
877
|
-
|
878
889
|
example "count the instances of randomly generated integers" do
|
879
890
|
expect(( r = Random.new(0); tally[Array.new(50){ r.rand 10 }] )).to be_a Hash
|
880
891
|
expect(( r = Random.new(0); tally[Array.new(50){ r.rand 10 }] )).to eq({5=>4, 0=>6, 3=>10, 7=>7, 9=>5, 2=>4, 4=>3, 6=>2, 8=>5, 1=>4})
|
@@ -887,7 +898,6 @@ describe MLL do
|
|
887
898
|
example "elements with highest frequencies are given by #commonest" do
|
888
899
|
skip "#commonest is yet to be implemented"
|
889
900
|
end
|
890
|
-
|
891
901
|
example "#tally is a discrete analog of #bincounts" do
|
892
902
|
skip "#bincounts is yet to be implemented"
|
893
903
|
end
|
@@ -899,7 +909,9 @@ describe MLL do
|
|
899
909
|
# http://reference.wolfram.com/language/ref/Mean.html
|
900
910
|
describe "#mean" do
|
901
911
|
|
902
|
-
|
912
|
+
# TODO examples to README.md
|
913
|
+
|
914
|
+
describe "Basic Examples:" do
|
903
915
|
|
904
916
|
example "mean of numeric values" do
|
905
917
|
expect(mean[[1.21, 3.4, 2.15, 4, 1.55]]).to eq 2.462
|
@@ -911,7 +923,7 @@ describe MLL do
|
|
911
923
|
|
912
924
|
end
|
913
925
|
|
914
|
-
describe "Applications" do
|
926
|
+
describe "Applications:" do
|
915
927
|
|
916
928
|
example "a 90-day moving mean" do
|
917
929
|
skip "#moving_map is yet to be implemented"
|
@@ -919,7 +931,7 @@ describe MLL do
|
|
919
931
|
|
920
932
|
end
|
921
933
|
|
922
|
-
describe "Properties & Relations" do
|
934
|
+
describe "Properties & Relations:" do
|
923
935
|
|
924
936
|
example "#moving_average is a sequence of means" do
|
925
937
|
skip "#moving_average is yet to be implemented"
|
@@ -931,6 +943,168 @@ describe MLL do
|
|
931
943
|
|
932
944
|
end
|
933
945
|
|
946
|
+
# https://reference.wolfram.com/language/guide/GridsAndTables.html
|
947
|
+
describe "Grids & Tables" do
|
948
|
+
|
949
|
+
# https://reference.wolfram.com/language/ref/Grid.html
|
950
|
+
describe "#grid" do
|
951
|
+
|
952
|
+
describe "Details:" do
|
953
|
+
|
954
|
+
example "#normal[grid] extracts the list of lists that make up a grid" do
|
955
|
+
skip "#normal is yet to be implemented"
|
956
|
+
end
|
957
|
+
example "the lists do not all need to be the same length" do
|
958
|
+
expect(grid[[[1],[2,3]]].to_s).to eq " \n 1 \n \n 2 3 \n \n"
|
959
|
+
end
|
960
|
+
# TODO SpanFromLeft SpanFromAbove SpanFromBoth
|
961
|
+
# TODO The following options can be given
|
962
|
+
# TODO Common settings for Frame
|
963
|
+
# TODO The spec(k) can have the following forms
|
964
|
+
# TODO With ItemSize->Automatic will break elements across multiple lines
|
965
|
+
# TODO "settings can be used for BaselinePosition" do
|
966
|
+
|
967
|
+
end
|
968
|
+
|
969
|
+
describe "Basic examples:" do
|
970
|
+
|
971
|
+
example "display elements in a grid" do
|
972
|
+
expect(grid[[%w{a b c}, %w{x y z}]]).to eq \
|
973
|
+
" \n" \
|
974
|
+
" a b c \n" \
|
975
|
+
" \n" \
|
976
|
+
" x y z \n" \
|
977
|
+
" \n"
|
978
|
+
end
|
979
|
+
example "put a frame around every element" do
|
980
|
+
expect(grid[[%w{a b c}, %w{x y z}], frame: :all]).to eq \
|
981
|
+
"┏━┳━┳━┓\n" \
|
982
|
+
"┃a┃b┃c┃\n" \
|
983
|
+
"┣━╋━╋━┫\n" \
|
984
|
+
"┃x┃y┃z┃\n" \
|
985
|
+
"┗━┻━┻━┛\n"
|
986
|
+
end
|
987
|
+
|
988
|
+
end
|
989
|
+
|
990
|
+
describe "Scope:" do
|
991
|
+
|
992
|
+
example "create a grid with a single row" do
|
993
|
+
expect(grid[fold_list[range[5], times].to_a]).to eq \
|
994
|
+
" \n" \
|
995
|
+
" 1 2 6 24 120 \n" \
|
996
|
+
" \n"
|
997
|
+
end
|
998
|
+
example "put a frame around the whole grid" do
|
999
|
+
expect(grid[table[?x, [3], [7]], frame: true]).to eq \
|
1000
|
+
"┏━━━━━━━━━━━━━┓\n" \
|
1001
|
+
"┃x x x x x x x┃\n" \
|
1002
|
+
"┃ ┃\n" \
|
1003
|
+
"┃x x x x x x x┃\n" \
|
1004
|
+
"┃ ┃\n" \
|
1005
|
+
"┃x x x x x x x┃\n" \
|
1006
|
+
"┗━━━━━━━━━━━━━┛\n"
|
1007
|
+
end
|
1008
|
+
example "put a frame around every element" do
|
1009
|
+
expect(grid[table[?x, [3], [7]], frame: :all]).to eq \
|
1010
|
+
"┏━┳━┳━┳━┳━┳━┳━┓\n" \
|
1011
|
+
"┃x┃x┃x┃x┃x┃x┃x┃\n" \
|
1012
|
+
"┣━╋━╋━╋━╋━╋━╋━┫\n" \
|
1013
|
+
"┃x┃x┃x┃x┃x┃x┃x┃\n" \
|
1014
|
+
"┣━╋━╋━╋━╋━╋━╋━┫\n" \
|
1015
|
+
"┃x┃x┃x┃x┃x┃x┃x┃\n" \
|
1016
|
+
"┗━┻━┻━┻━┻━┻━┻━┛\n"
|
1017
|
+
end
|
1018
|
+
# TODO Draw all the frames in red
|
1019
|
+
# TODO Put a frame around the first row and column
|
1020
|
+
# TODO Draw different frames with different styles
|
1021
|
+
# TODO Put dividers at all horizontal positions
|
1022
|
+
# TODO Put dividers at all vertical positions
|
1023
|
+
# TODO Put dividers at the third horizontal and second vertical positions
|
1024
|
+
# TODO Make the element 4 span the column to its right
|
1025
|
+
# TODO Make it span three rows
|
1026
|
+
# TODO Span throughout a 2×2 block
|
1027
|
+
example "align contents to the left" do
|
1028
|
+
expect(grid[[["a", "bbbb"], ["ccc", "d"]], frame: :all, alignment: :left]).to eq \
|
1029
|
+
"┏━━━┳━━━━┓\n" \
|
1030
|
+
"┃a ┃bbbb┃\n" \
|
1031
|
+
"┣━━━╋━━━━┫\n" \
|
1032
|
+
"┃ccc┃d ┃\n" \
|
1033
|
+
"┗━━━┻━━━━┛\n"
|
1034
|
+
end
|
1035
|
+
example "align contents to the right" do
|
1036
|
+
expect(grid[[["a", "bbbb"], ["ccc", "d"]], frame: :all, alignment: :right]).to eq \
|
1037
|
+
"┏━━━┳━━━━┓\n" \
|
1038
|
+
"┃ a┃bbbb┃\n" \
|
1039
|
+
"┣━━━╋━━━━┫\n" \
|
1040
|
+
"┃ccc┃ d┃\n" \
|
1041
|
+
"┗━━━┻━━━━┛\n"
|
1042
|
+
end
|
1043
|
+
# TODO Draw the grid with a pink background
|
1044
|
+
# TODO Alternating pink and yellow at successive horizontal positions
|
1045
|
+
# TODO Alternating pink and yellow at successive vertical positions
|
1046
|
+
# TODO Make the grid contents red
|
1047
|
+
example "leave the same amount of space for all items" do
|
1048
|
+
skip "#power is yet to be implemented"
|
1049
|
+
expect(grid[table[power, [5, 5]], frame: :all, alignment: :right, itemsize: :all]).to eq \
|
1050
|
+
"┏━━━┳━━━━┓\n" \
|
1051
|
+
"┃ a┃bbbb┃\n" \
|
1052
|
+
"┣━━━╋━━━━┫\n" \
|
1053
|
+
"┃ccc┃ d┃\n" \
|
1054
|
+
"┗━━━┻━━━━┛\n"
|
1055
|
+
end
|
1056
|
+
# TODO "set the horizontal spacing between items" do
|
1057
|
+
# TODO "set the horizontal and vertical spacings" do
|
1058
|
+
# TODO "grids can be nested" do
|
1059
|
+
|
1060
|
+
end
|
1061
|
+
|
1062
|
+
describe "Options:" do
|
1063
|
+
|
1064
|
+
# TODO "align elements around the center of the grid" do
|
1065
|
+
# TODO "align numbers on the decimal point" do
|
1066
|
+
# TODO draw the grid with a pink background
|
1067
|
+
# TODO Pink and gray backgrounds for the first and second columns
|
1068
|
+
# TODO An equivalent syntax
|
1069
|
+
# TODO Pink and gray backgrounds for the first and second rows
|
1070
|
+
# TODO Alternating pink and gray backgrounds
|
1071
|
+
# TODO Alternating backgrounds with yellow superimposed in the first and last positions
|
1072
|
+
# TODO Set the background for specific items
|
1073
|
+
# TODO Set the background for a subregion of the grid
|
1074
|
+
# TODO Draw all interior dividers
|
1075
|
+
# TODO Draw a divider at every other horizontal position
|
1076
|
+
# TODO Include the final position
|
1077
|
+
# TODO Draw dividers with specified styles
|
1078
|
+
# TODO "frame specific elements" do
|
1079
|
+
# TODO "frame a region" do
|
1080
|
+
# TODO "make each item a fixed number of character-widths wide" do
|
1081
|
+
# TODO "ItemSize->All makes all items the same size" do
|
1082
|
+
# TODO "prevent line-wrapping" do
|
1083
|
+
# TODO "set one overall style for grid items" do
|
1084
|
+
# TODO "style specific elements" do
|
1085
|
+
# TODO "style a region" do
|
1086
|
+
# TODO "insert no additional space between rows or columns" do
|
1087
|
+
# TODO "specify spacing with numeric values" do
|
1088
|
+
# TODO "use different spacings at the first vertical divider" do
|
1089
|
+
|
1090
|
+
end
|
1091
|
+
|
1092
|
+
describe "Properties & Relations:" do
|
1093
|
+
|
1094
|
+
# TODO "the elements of a Grid can be extracted with #[]" do
|
1095
|
+
|
1096
|
+
end
|
1097
|
+
|
1098
|
+
describe "Neat examples:" do
|
1099
|
+
|
1100
|
+
# TODO "a Sudoku grid" do
|
1101
|
+
|
1102
|
+
end
|
1103
|
+
|
1104
|
+
end
|
1105
|
+
|
1106
|
+
end
|
1107
|
+
|
934
1108
|
end
|
935
1109
|
|
936
1110
|
# TODO http://reference.wolfram.com/language/guide/HandlingArraysOfData.html
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mll
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -46,7 +46,9 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- .rspec
|
49
|
+
- .travis.yml
|
49
50
|
- Gemfile
|
51
|
+
- Gemfile.lock
|
50
52
|
- README.md
|
51
53
|
- Rakefile
|
52
54
|
- lib/mll.rb
|