rubyvis 0.6.1 → 0.7.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.
- checksums.yaml +5 -5
- data/.travis.yml +6 -6
- data/Gemfile +1 -1
- data/Gemfile.lock +27 -21
- data/History.txt +10 -0
- data/lib/rubyvis.rb +1 -4
- data/lib/rubyvis/mark/panel.rb +1 -1
- data/lib/rubyvis/scene/svg_line.rb +0 -1
- data/lib/rubyvis/scene/svg_panel.rb +3 -0
- data/lib/rubyvis/scene/svg_rule.rb +0 -1
- data/lib/rubyvis/sceneelement.rb +1 -0
- data/lib/rubyvis/version.rb +6 -0
- data/rubyvis.gemspec +1 -2
- data/spec/anchor_spec.rb +11 -11
- data/spec/area_spec.rb +10 -10
- data/spec/bar_spec.rb +13 -13
- data/spec/color_spec.rb +24 -24
- data/spec/dom_spec.rb +77 -77
- data/spec/dot_spec.rb +3 -3
- data/spec/flatten_spec.rb +2 -2
- data/spec/histogram_spec.rb +5 -5
- data/spec/image_spec.rb +2 -2
- data/spec/internal_spec.rb +58 -58
- data/spec/javascript_behaviour_spec.rb +14 -14
- data/spec/label_spec.rb +9 -9
- data/spec/layout_arc_spec.rb +5 -5
- data/spec/layout_cluster_spec.rb +4 -4
- data/spec/layout_grid_spec.rb +5 -5
- data/spec/layout_horizon_spec.rb +5 -5
- data/spec/layout_indent_spec.rb +3 -3
- data/spec/layout_matrix_spec.rb +6 -6
- data/spec/layout_pack_spec.rb +2 -2
- data/spec/layout_partition_spec.rb +4 -4
- data/spec/layout_stack_spec.rb +11 -11
- data/spec/layout_tree_spec.rb +4 -4
- data/spec/layout_treemap_spec.rb +2 -2
- data/spec/line_spec.rb +14 -14
- data/spec/mark_spec.rb +7 -7
- data/spec/nest_spec.rb +3 -3
- data/spec/panel_spec.rb +10 -10
- data/spec/readme_spec.rb +6 -6
- data/spec/ruby_api_spec.rb +4 -4
- data/spec/rule_spec.rb +3 -3
- data/spec/scale_linear_datetime_spec.rb +23 -23
- data/spec/scale_linear_spec.rb +37 -37
- data/spec/scale_log_spec.rb +28 -28
- data/spec/scale_ordinal_spec.rb +21 -21
- data/spec/scale_spec.rb +2 -2
- data/spec/spec_helper.rb +6 -5
- data/spec/vector_spec.rb +8 -8
- data/spec/wedge_spec.rb +4 -4
- data/web/build_site.rb +1 -1
- metadata +4 -4
data/spec/dom_spec.rb
CHANGED
@@ -11,12 +11,12 @@ describe Rubyvis::Dom do
|
|
11
11
|
dom_map=Rubyvis::Dom.new(map)
|
12
12
|
|
13
13
|
root=dom_map.root.sort {|a,b| a.node_name.to_s<=>b.node_name.to_s}
|
14
|
-
root.nodes.
|
15
|
-
root.nodes.size.
|
14
|
+
expect(root.nodes).to be_instance_of Array
|
15
|
+
expect(root.nodes.size).to eq 8
|
16
16
|
ar=root.nodes.map do |n|
|
17
17
|
[n.node_name, n.node_value]
|
18
18
|
end
|
19
|
-
ar.
|
19
|
+
expect(ar).to eq [[nil, nil], [:a, nil], [:aa, 1], [:ab, nil], [:aba, 2], [:b, 4], [:c, nil], [:ca, 5]]
|
20
20
|
end
|
21
21
|
it "should treemap example works right" do
|
22
22
|
flare={:a=>{:aa=>1,:ab=>1,:ac=>1},:b=>{:ba=>1,:bb=>1},:c=>3}
|
@@ -42,7 +42,7 @@ describe Rubyvis::Dom do
|
|
42
42
|
root.visit_before {|n,i|
|
43
43
|
ar.push [n.node_name, n.size]
|
44
44
|
}
|
45
|
-
ar.
|
45
|
+
expect(ar).to eq [["flare", 8.0], [:b, 2.0], [:ba, 1.0], [:bb, 1.0], [:a, 3.0], [:aa, 1.0], [:ab, 1.0], [:ac, 1.0], [:c, 3.0]]
|
46
46
|
end
|
47
47
|
describe Rubyvis::Dom::Node do
|
48
48
|
before do
|
@@ -55,44 +55,44 @@ describe Rubyvis::Dom do
|
|
55
55
|
end
|
56
56
|
subject {@n}
|
57
57
|
it "should have node_value" do
|
58
|
-
@n.node_value.
|
58
|
+
expect(@n.node_value).to eq :a
|
59
59
|
end
|
60
|
-
it {
|
61
|
-
it {
|
62
|
-
it {
|
63
|
-
it {
|
64
|
-
it {
|
65
|
-
it {
|
66
|
-
it {
|
60
|
+
it {is_expected.to respond_to :parent_node}
|
61
|
+
it {is_expected.to respond_to :first_child}
|
62
|
+
it {is_expected.to respond_to :last_child}
|
63
|
+
it {is_expected.to respond_to :previous_sibling}
|
64
|
+
it {is_expected.to respond_to :next_sibling}
|
65
|
+
it {is_expected.to respond_to :node_name}
|
66
|
+
it {is_expected.to respond_to :child_nodes}
|
67
67
|
it "should child_nodes be empty" do
|
68
68
|
@n.child_nodes.size==0
|
69
69
|
end
|
70
70
|
it "method append_child" do
|
71
|
-
@n.append_child(@n2).
|
72
|
-
@n.child_nodes.
|
73
|
-
@n2.parent_node.
|
74
|
-
@n.first_child.
|
75
|
-
@n.last_child.
|
71
|
+
expect(@n.append_child(@n2)).to eq @n2
|
72
|
+
expect(@n.child_nodes).to eq [@n2]
|
73
|
+
expect(@n2.parent_node).to eq @n
|
74
|
+
expect(@n.first_child).to eq @n2
|
75
|
+
expect(@n.last_child).to eq @n2
|
76
76
|
|
77
77
|
@n.append_child(@n3)
|
78
|
-
@n.child_nodes.
|
79
|
-
@n3.parent_node.
|
80
|
-
@n.first_child.
|
81
|
-
@n.last_child.
|
82
|
-
@n2.previous_sibling.
|
83
|
-
@n2.next_sibling.
|
84
|
-
@n3.previous_sibling.
|
85
|
-
@n3.next_sibling.
|
78
|
+
expect(@n.child_nodes).to eq [@n2,@n3]
|
79
|
+
expect(@n3.parent_node).to eq @n
|
80
|
+
expect(@n.first_child).to eq @n2
|
81
|
+
expect(@n.last_child).to eq @n3
|
82
|
+
expect(@n2.previous_sibling).to be_nil
|
83
|
+
expect(@n2.next_sibling).to eq @n3
|
84
|
+
expect(@n3.previous_sibling).to eq @n2
|
85
|
+
expect(@n3.next_sibling).to be_nil
|
86
86
|
|
87
87
|
@n.append_child(@n4)
|
88
|
-
@n.last_child.
|
89
|
-
@n2.next_sibling.
|
90
|
-
@n3.next_sibling.
|
91
|
-
@n4.next_sibling.
|
88
|
+
expect(@n.last_child).to eq @n4
|
89
|
+
expect(@n2.next_sibling).to eq @n3
|
90
|
+
expect(@n3.next_sibling).to eq @n4
|
91
|
+
expect(@n4.next_sibling).to be_nil
|
92
92
|
|
93
|
-
@n4.previous_sibling.
|
94
|
-
@n3.previous_sibling.
|
95
|
-
@n2.previous_sibling.
|
93
|
+
expect(@n4.previous_sibling).to eq @n3
|
94
|
+
expect(@n3.previous_sibling).to eq @n2
|
95
|
+
expect(@n2.previous_sibling).to be_nil
|
96
96
|
|
97
97
|
end
|
98
98
|
it "method remove_child" do
|
@@ -100,42 +100,42 @@ describe Rubyvis::Dom do
|
|
100
100
|
@n.append_child(@n3)
|
101
101
|
@n.append_child(@n4)
|
102
102
|
|
103
|
-
@n.remove_child(@n3).
|
103
|
+
expect(@n.remove_child(@n3)).to eq @n3
|
104
104
|
|
105
|
-
@n3.next_sibling.
|
106
|
-
@n3.previous_sibling.
|
107
|
-
@n3.parent_node.
|
105
|
+
expect(@n3.next_sibling).to be_nil
|
106
|
+
expect(@n3.previous_sibling).to be_nil
|
107
|
+
expect(@n3.parent_node).to be_nil
|
108
108
|
|
109
|
-
@n2.next_sibling.
|
110
|
-
@n4.previous_sibling.
|
109
|
+
expect(@n2.next_sibling).to eq @n4
|
110
|
+
expect(@n4.previous_sibling).to eq @n2
|
111
111
|
|
112
112
|
@n.remove_child(@n4)
|
113
|
-
@n2.next_sibling.
|
114
|
-
@n.first_child.
|
115
|
-
@n.last_child.
|
113
|
+
expect(@n2.next_sibling).to be_nil
|
114
|
+
expect(@n.first_child).to eq @n2
|
115
|
+
expect(@n.last_child).to eq @n2
|
116
116
|
end
|
117
117
|
|
118
118
|
it "method insert_before" do
|
119
119
|
@n.append_child(@n2)
|
120
120
|
@n.append_child(@n4)
|
121
121
|
@n.insert_before(@n3,@n4)
|
122
|
-
@n.child_nodes.size.
|
122
|
+
expect(@n.child_nodes.size).to eq 3
|
123
123
|
|
124
|
-
@n.first_child.
|
125
|
-
@n.last_child.
|
126
|
-
@n2.next_sibling.
|
127
|
-
@n3.next_sibling.
|
128
|
-
@n4.next_sibling.
|
124
|
+
expect(@n.first_child).to eq @n2
|
125
|
+
expect(@n.last_child).to eq @n4
|
126
|
+
expect(@n2.next_sibling).to eq @n3
|
127
|
+
expect(@n3.next_sibling).to eq @n4
|
128
|
+
expect(@n4.next_sibling).to be_nil
|
129
129
|
|
130
|
-
@n2.previous_sibling.
|
131
|
-
@n3.previous_sibling.
|
132
|
-
@n4.previous_sibling.
|
130
|
+
expect(@n2.previous_sibling).to be_nil
|
131
|
+
expect(@n3.previous_sibling).to eq @n2
|
132
|
+
expect(@n4.previous_sibling).to eq @n3
|
133
133
|
|
134
134
|
|
135
135
|
|
136
|
-
@n.child_nodes[0].
|
137
|
-
@n.child_nodes[1].
|
138
|
-
@n.child_nodes[2].
|
136
|
+
expect(@n.child_nodes[0]).to eq @n2
|
137
|
+
expect(@n.child_nodes[1]).to eq @n3
|
138
|
+
expect(@n.child_nodes[2]).to eq @n4
|
139
139
|
|
140
140
|
end
|
141
141
|
it "method replace_child" do
|
@@ -143,20 +143,20 @@ describe Rubyvis::Dom do
|
|
143
143
|
@n.append_child(@n3)
|
144
144
|
@n.replace_child(@n4,@n3)
|
145
145
|
|
146
|
-
@n.child_nodes.size.
|
146
|
+
expect(@n.child_nodes.size).to eq 2
|
147
147
|
|
148
|
-
@n.child_nodes[0].
|
149
|
-
@n.child_nodes[1].
|
148
|
+
expect(@n.child_nodes[0]).to eq @n2
|
149
|
+
expect(@n.child_nodes[1]).to eq @n4
|
150
150
|
|
151
|
-
@n2.next_sibling.
|
152
|
-
@n4.next_sibling.
|
151
|
+
expect(@n2.next_sibling).to eq @n4
|
152
|
+
expect(@n4.next_sibling).to eq nil
|
153
153
|
|
154
|
-
@n2.previous_sibling.
|
155
|
-
@n4.previous_sibling.
|
154
|
+
expect(@n2.previous_sibling).to be_nil
|
155
|
+
expect(@n4.previous_sibling).to eq @n2
|
156
156
|
|
157
157
|
|
158
|
-
@n.first_child.
|
159
|
-
@n.last_child.
|
158
|
+
expect(@n.first_child).to eq @n2
|
159
|
+
expect(@n.last_child).to eq @n4
|
160
160
|
end
|
161
161
|
describe "visit methods" do
|
162
162
|
before do
|
@@ -172,21 +172,21 @@ describe Rubyvis::Dom do
|
|
172
172
|
@n.visit_before {|n,d|
|
173
173
|
@a.push([n.node_value,d])
|
174
174
|
}
|
175
|
-
@a.
|
175
|
+
expect(@a).to eq [[:a, 0], [:b, 1], [:e, 2], [:c, 1], [:d, 2]]
|
176
176
|
end
|
177
177
|
|
178
178
|
it "method visit_after" do
|
179
179
|
@n.visit_after {|n,d|
|
180
180
|
@a.push([n.node_value,d])
|
181
181
|
}
|
182
|
-
@a.
|
182
|
+
expect(@a).to eq [[:e, 2], [:b, 1], [:d, 2], [:c, 1], [:a, 0]]
|
183
183
|
end
|
184
184
|
it "method each_child" do
|
185
185
|
@n.append_child(@n5)
|
186
186
|
@n.each_child {|d|
|
187
187
|
@a.push(d.node_value)
|
188
188
|
}
|
189
|
-
@a.
|
189
|
+
expect(@a).to eq [:b, :c,:e]
|
190
190
|
end
|
191
191
|
end
|
192
192
|
it "should sort correctly" do
|
@@ -197,20 +197,20 @@ describe Rubyvis::Dom do
|
|
197
197
|
|
198
198
|
@n.sort {|a,b| a.node_value.to_s<=>b.node_value.to_s}
|
199
199
|
|
200
|
-
@n.child_nodes.
|
200
|
+
expect(@n.child_nodes).to eq [@n2,@n3,@n4,@n5]
|
201
201
|
|
202
|
-
@n.first_child.
|
203
|
-
@n.last_child.
|
202
|
+
expect(@n.first_child).to eq @n2
|
203
|
+
expect(@n.last_child).to eq @n5
|
204
204
|
|
205
|
-
@n2.next_sibling.
|
206
|
-
@n3.next_sibling.
|
207
|
-
@n4.next_sibling.
|
208
|
-
@n5.next_sibling.
|
205
|
+
expect(@n2.next_sibling).to eq @n3
|
206
|
+
expect(@n3.next_sibling).to eq @n4
|
207
|
+
expect(@n4.next_sibling).to eq @n5
|
208
|
+
expect(@n5.next_sibling).to be_nil
|
209
209
|
|
210
|
-
@n2.previous_sibling.
|
211
|
-
@n3.previous_sibling.
|
212
|
-
@n4.previous_sibling.
|
213
|
-
@n5.previous_sibling.
|
210
|
+
expect(@n2.previous_sibling).to be_nil
|
211
|
+
expect(@n3.previous_sibling).to eq @n2
|
212
|
+
expect(@n4.previous_sibling).to eq @n3
|
213
|
+
expect(@n5.previous_sibling).to eq @n4
|
214
214
|
end
|
215
215
|
it "should reverse correctly" do
|
216
216
|
@n.append_child(@n3)
|
@@ -218,7 +218,7 @@ describe Rubyvis::Dom do
|
|
218
218
|
@n.append_child(@n2)
|
219
219
|
@n.append_child(@n4)
|
220
220
|
@n.reverse
|
221
|
-
@n.child_nodes.
|
221
|
+
expect(@n.child_nodes).to eq [@n4,@n2,@n5,@n3]
|
222
222
|
end
|
223
223
|
|
224
224
|
end
|
data/spec/dot_spec.rb
CHANGED
@@ -4,10 +4,10 @@ require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
|
|
4
4
|
it "should have correct properties" do
|
5
5
|
props=[:antialias, :bottom, :cursor, :data, :events, :fill_style, :id, :left, :line_width, :reverse, :right, :shape, :shape_angle, :shape_radius, :shape_size, :stroke_style, :title, :top, :visible].inject({}) {|ac, v| ac[v]=true; ac}
|
6
6
|
|
7
|
-
Rubyvis::Dot.properties.
|
7
|
+
expect(Rubyvis::Dot.properties).to eq(props)
|
8
8
|
end
|
9
9
|
it "Rubyvis.Dot be the same as Rubyvis::Dot" do
|
10
|
-
Rubyvis.Dot.
|
10
|
+
expect(Rubyvis.Dot).to eql Rubyvis::Dot
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should render correctly 'dot-anchor' example" do
|
@@ -34,7 +34,7 @@ require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
|
|
34
34
|
vis.render()
|
35
35
|
|
36
36
|
pv_out=fixture_svg_read("dot_anchor.svg")
|
37
|
-
vis.to_svg.
|
37
|
+
expect(vis.to_svg).to have_same_svg_elements(pv_out)
|
38
38
|
end
|
39
39
|
|
40
40
|
|
data/spec/flatten_spec.rb
CHANGED
@@ -37,11 +37,11 @@ describe Rubyvis::Flatten do
|
|
37
37
|
}
|
38
38
|
expected=[{"band"=>"Genesis", "type"=>"Live", "album"=>"Genesis Live", "year"=>1973}, {"band"=>"Genesis", "type"=>"Live", "album"=>"Seconds Out", "year"=>1977}, {"band"=>"Genesis", "type"=>"Studio", "album"=>"Nursery Cryme", "year"=>1971}, {"band"=>"Genesis", "type"=>"Studio", "album"=>"Foxtrot", "year"=>1972}, {"band"=>"Rush", "type"=>"Studio", "album"=>"Permanent Waves", "year"=>1980}, {"band"=>"Rush", "type"=>"Studio", "album"=>"Moving Pictures", "year"=>1981}, {"band"=>"Rush", "type"=>"Live", "album"=>"Exit...Stage Left", "year"=>1981}, {"band"=>"Rush", "type"=>"Live", "album"=>"A Show of Hands", "year"=>1989}].sort(&sorting)
|
39
39
|
|
40
|
-
@flatten.array.sort(&sorting).
|
40
|
+
expect(@flatten.array.sort(&sorting)).to eq expected
|
41
41
|
end
|
42
42
|
it "other example" do
|
43
43
|
@flatten.leaf(lambda {|f| f.is_a? Numeric})
|
44
44
|
expected=[{:keys=>["Genesis", "Live", "Genesis Live"], :value=>1973}, {:keys=>["Genesis", "Live", "Seconds Out"], :value=>1977}, {:keys=>["Genesis", "Studio", "Nursery Cryme"], :value=>1971}, {:keys=>["Genesis", "Studio", "Foxtrot"], :value=>1972}, {:keys=>["Rush", "Studio", "Permanent Waves"], :value=>1980}, {:keys=>["Rush", "Studio", "Moving Pictures"], :value=>1981}, {:keys=>["Rush", "Live", "Exit...Stage Left"], :value=>1981}, {:keys=>["Rush", "Live", "A Show of Hands"], :value=>1989}]
|
45
|
-
@flatten.array.
|
45
|
+
expect(@flatten.array).to eql expected
|
46
46
|
end
|
47
47
|
end
|
data/spec/histogram_spec.rb
CHANGED
@@ -9,20 +9,20 @@ describe Rubyvis::Histogram do
|
|
9
9
|
@bins=@hist.bins
|
10
10
|
end
|
11
11
|
it "size should be correct" do
|
12
|
-
@bins.size.
|
12
|
+
expect(@bins.size).to eq 8
|
13
13
|
end
|
14
14
|
it "bin.x should be correct" do
|
15
|
-
@bins.map {|b| b.x}.
|
15
|
+
expect(@bins.map {|b| b.x}).to eq [-0.8, -0.6, -0.4, -0.2, 0, 0.2,0.4, 0.6]
|
16
16
|
end
|
17
17
|
it "bin.dx should be correct" do
|
18
|
-
@bins.map {|b| b.dx}.
|
18
|
+
expect(@bins.map {|b| b.dx}).to eq [0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2]
|
19
19
|
end
|
20
20
|
it "bin.y should be correct" do
|
21
|
-
@bins.map {|b| b.y}.
|
21
|
+
expect(@bins.map {|b| b.y}).to eq [19,5,6,7,8,8,11,36]
|
22
22
|
end
|
23
23
|
it "bin.y should be correct using frequency=false" do
|
24
24
|
@hist.frequency=false
|
25
|
-
@hist.bins.map {|b| b.y}.
|
25
|
+
expect(@hist.bins.map {|b| b.y}).to eq [0.19,0.05,0.06,0.07,0.08,0.08,0.11,0.36]
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
data/spec/image_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe Rubyvis::Image do
|
|
4
4
|
include Rubyvis::GeneralSpec
|
5
5
|
|
6
6
|
it "Rubyvis.Image be the same as Rubyvis::Image" do
|
7
|
-
Rubyvis.Image.
|
7
|
+
expect(Rubyvis.Image).to eql Rubyvis::Image
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should render correctly" do
|
@@ -21,7 +21,7 @@ describe Rubyvis::Image do
|
|
21
21
|
vis.render()
|
22
22
|
|
23
23
|
pv_out=fixture_svg_read("image.svg")
|
24
|
-
vis.to_svg.
|
24
|
+
expect(vis.to_svg).to have_same_svg_elements(pv_out)
|
25
25
|
end
|
26
26
|
|
27
27
|
end
|
data/spec/internal_spec.rb
CHANGED
@@ -4,22 +4,22 @@ describe "Rubyvis module methods" do
|
|
4
4
|
it "method identify should always return the same value" do
|
5
5
|
f=Rubyvis.identity
|
6
6
|
a="a"
|
7
|
-
f.js_call(a, 5).
|
7
|
+
expect(f.js_call(a, 5)).to eq(5)
|
8
8
|
end
|
9
9
|
it "method index should return index method from a object" do
|
10
10
|
o1=Rubyvis.o_index(1)
|
11
11
|
o2=Rubyvis.o_index(10)
|
12
|
-
Rubyvis.index.js_call(o1,1,2).
|
13
|
-
Rubyvis.index.js_call(o2,1,2).
|
12
|
+
expect(Rubyvis.index.js_call(o1,1,2)).to eq(1)
|
13
|
+
expect(Rubyvis.index.js_call(o2,1,2)).to eq(10)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
describe "from pv-internal.js" do
|
17
17
|
it "should create a infinite succesion with id" do
|
18
18
|
f=Rubyvis.id
|
19
|
-
Rubyvis.id.
|
19
|
+
expect(Rubyvis.id).to eq(f+1)
|
20
20
|
end
|
21
21
|
it "should return a lambda with functor" do
|
22
|
-
Rubyvis.functor(5).call.
|
22
|
+
expect(Rubyvis.functor(5).call).to eq(5)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
describe "from data/Arrays.js" do
|
@@ -27,123 +27,123 @@ describe "Rubyvis module methods" do
|
|
27
27
|
f=lambda {|d| "#{self.index}-#{d}"}
|
28
28
|
i=%w{a b c}
|
29
29
|
o=%w{0-a 1-b 2-c}
|
30
|
-
Rubyvis.map(i).
|
31
|
-
Rubyvis.map(i,f).
|
30
|
+
expect(Rubyvis.map(i)).to eq(i)
|
31
|
+
expect(Rubyvis.map(i,f)).to eq(o)
|
32
32
|
end
|
33
33
|
it "repeat method should repeat the specified array n times" do
|
34
|
-
Rubyvis.repeat([1,2]).
|
35
|
-
Rubyvis.repeat([1,2],3).
|
34
|
+
expect(Rubyvis.repeat([1,2])).to eq([1,2,1,2])
|
35
|
+
expect(Rubyvis.repeat([1,2],3)).to eq([1,2,1,2,1,2])
|
36
36
|
end
|
37
37
|
it "cross method should return an array of all posible pairs of element" do
|
38
|
-
Rubyvis.cross([1,2],[3,4]).
|
38
|
+
expect(Rubyvis.cross([1,2],[3,4])).to eq([[1,3],[1,4],[2,3],[2,4]])
|
39
39
|
end
|
40
40
|
it "blend method should concatenates the arrays into a single array" do
|
41
|
-
Rubyvis.blend([[1,2,3],[4,5,6],[7,8,9]]).
|
41
|
+
expect(Rubyvis.blend([[1,2,3],[4,5,6],[7,8,9]])).to eq((1..9).to_a)
|
42
42
|
end
|
43
43
|
it "transpose method should returns a transposed array of arrays" do
|
44
|
-
Rubyvis.transpose([[1,2,3],[4,5,6]]).
|
44
|
+
expect(Rubyvis.transpose([[1,2,3],[4,5,6]])).to eq([[1,4],[2,5],[3,6]])
|
45
45
|
end
|
46
46
|
it "normalize method should returns a normalized copy of array" do
|
47
|
-
Rubyvis.normalize([1,1,3]).
|
47
|
+
expect(Rubyvis.normalize([1,1,3])).to eq([0.2,0.2,0.6])
|
48
48
|
a=%w{aa ccc ddddd}
|
49
49
|
f=lambda {|e| e.size}
|
50
|
-
Rubyvis.normalize(a,f).
|
50
|
+
expect(Rubyvis.normalize(a,f)).to eq([0.2,0.3,0.5])
|
51
51
|
end
|
52
52
|
it "permute method allows to permute the order of elements" do
|
53
|
-
Rubyvis.permute(%w{a b c},[1,2,0]).
|
53
|
+
expect(Rubyvis.permute(%w{a b c},[1,2,0])).to eq(%w{b c a})
|
54
54
|
f=lambda {|e| [self.index,e]}
|
55
|
-
Rubyvis.permute(%w{a b c},[1,2,0],f).
|
55
|
+
expect(Rubyvis.permute(%w{a b c},[1,2,0],f)).to eq([[1,"b"],[2,"c"],[0,"a"]])
|
56
56
|
end
|
57
57
|
it "numerate should map from key to index for the specified keys array" do
|
58
|
-
Rubyvis.numerate(["a", "b", "c"]).
|
58
|
+
expect(Rubyvis.numerate(["a", "b", "c"])).to eq({"a"=>0,"b"=>1,"c"=>2})
|
59
59
|
end
|
60
60
|
it "method uniq returns the unique elements in the specified array" do
|
61
|
-
Rubyvis.uniq(["a", "b", "c","c"]).
|
62
|
-
Rubyvis.uniq(["a", "b", "c","c"], lambda{|e| e*2}).
|
61
|
+
expect(Rubyvis.uniq(["a", "b", "c","c"])).to eq(["a","b","c"])
|
62
|
+
expect(Rubyvis.uniq(["a", "b", "c","c"], lambda{|e| e*2})).to eq(["aa","bb","cc"])
|
63
63
|
end
|
64
64
|
it "method search should return correct values" do
|
65
65
|
a=(0..9).to_a
|
66
|
-
Rubyvis.search(a,1).
|
67
|
-
Rubyvis.search(a,20).
|
68
|
-
Rubyvis.search(a,5.5).
|
66
|
+
expect(Rubyvis.search(a,1)).to eq(1)
|
67
|
+
expect(Rubyvis.search(a,20)).to eq(-11)
|
68
|
+
expect(Rubyvis.search(a,5.5)).to eq(-7)
|
69
69
|
end
|
70
70
|
it "method search_index should return correct values" do
|
71
71
|
a=(0..9).to_a
|
72
|
-
Rubyvis.search_index(a,1).
|
73
|
-
Rubyvis.search_index(a,20).
|
74
|
-
Rubyvis.search_index(a,5.5).
|
72
|
+
expect(Rubyvis.search_index(a,1)).to eq(1)
|
73
|
+
expect(Rubyvis.search_index(a,20)).to eq(10)
|
74
|
+
expect(Rubyvis.search_index(a,5.5)).to eq(6)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
describe "from data/Numbers.js" do
|
78
78
|
it "method range should create range of numbers" do
|
79
|
-
Rubyvis.range(1,10).
|
80
|
-
Rubyvis.range(1,10,0.5).
|
81
|
-
Rubyvis.range(1,10,3).
|
82
|
-
|
79
|
+
expect(Rubyvis.range(1,10)).to eq([1,2,3,4,5,6,7,8,9])
|
80
|
+
expect(Rubyvis.range(1,10,0.5)).to eq([1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6.5,7,7.5,8,8.5,9,9.5])
|
81
|
+
expect(Rubyvis.range(1,10,3)).to eq([1,4,7])
|
82
|
+
expect {Rubyvis.range(1,10,0)}.to raise_exception
|
83
83
|
end
|
84
84
|
it "method random returns a random number between values" do
|
85
85
|
srand(10)
|
86
|
-
100.times.map{ Rubyvis.random(5)}.uniq.sort.
|
87
|
-
100.times.map{ Rubyvis.random(1,5)}.uniq.sort.
|
88
|
-
100.times.map{ Rubyvis.random(1,3,0.5)}.uniq.sort.
|
86
|
+
expect(100.times.map{ Rubyvis.random(5)}.uniq.sort).to eq((0..4).to_a)
|
87
|
+
expect(100.times.map{ Rubyvis.random(1,5)}.uniq.sort).to eq((1..4).to_a)
|
88
|
+
expect(100.times.map{ Rubyvis.random(1,3,0.5)}.uniq.sort).to eq([1.0,1.5,2.0,2.5])
|
89
89
|
end
|
90
90
|
it "methods sum returns a sum" do
|
91
|
-
Rubyvis.sum([1,2,3,4]).
|
92
|
-
Rubyvis.sum(%w{1 4 3 2 5}, lambda {|v| v.to_i * self.index}).
|
91
|
+
expect(Rubyvis.sum([1,2,3,4])).to eq(1+2+3+4)
|
92
|
+
expect(Rubyvis.sum(%w{1 4 3 2 5}, lambda {|v| v.to_i * self.index})).to eq(4*1 + 3*2 + 2*3 + 5*4)
|
93
93
|
end
|
94
94
|
it "method max returns maximum value" do
|
95
|
-
Rubyvis.max([1,2,3,4]).
|
96
|
-
Rubyvis.max([1,2,3,4], Rubyvis.index).
|
97
|
-
Rubyvis.max(%w{1 4 3 2 5}, lambda {|v| v.to_i * self.index}).
|
95
|
+
expect(Rubyvis.max([1,2,3,4])).to eq(4)
|
96
|
+
expect(Rubyvis.max([1,2,3,4], Rubyvis.index)).to eq(3)
|
97
|
+
expect(Rubyvis.max(%w{1 4 3 2 5}, lambda {|v| v.to_i * self.index})).to eq(20)
|
98
98
|
end
|
99
99
|
it "method max_index returns maximum value index" do
|
100
|
-
Rubyvis.max_index([1,2,4,3]).
|
101
|
-
Rubyvis.max_index(%w{1 4 3 2 5}, lambda {|v| v.to_i * self.index}).
|
100
|
+
expect(Rubyvis.max_index([1,2,4,3])).to eq(2)
|
101
|
+
expect(Rubyvis.max_index(%w{1 4 3 2 5}, lambda {|v| v.to_i * self.index})).to eq(4)
|
102
102
|
end
|
103
103
|
it "method min returns minimum value" do
|
104
|
-
Rubyvis.min([1,2,3,4]).
|
105
|
-
Rubyvis.min([1,2,3,4], Rubyvis.index).
|
106
|
-
Rubyvis.min(%w{2 0 3 2 5}, lambda {|v| v.to_i + self.index}).
|
104
|
+
expect(Rubyvis.min([1,2,3,4])).to eq(1)
|
105
|
+
expect(Rubyvis.min([1,2,3,4], Rubyvis.index)).to eq(0)
|
106
|
+
expect(Rubyvis.min(%w{2 0 3 2 5}, lambda {|v| v.to_i + self.index})).to eq(1)
|
107
107
|
end
|
108
108
|
it "method min_index returns minimum value index" do
|
109
|
-
Rubyvis.min_index([1,2,4,-1]).
|
110
|
-
Rubyvis.min_index(%w{1 4 3 2 5}, lambda {|v| v.to_i * self.index}).
|
109
|
+
expect(Rubyvis.min_index([1,2,4,-1])).to eq(3)
|
110
|
+
expect(Rubyvis.min_index(%w{1 4 3 2 5}, lambda {|v| v.to_i * self.index})).to eq(0)
|
111
111
|
end
|
112
112
|
it "method mean returns mean of values" do
|
113
113
|
a,b,c,d=rand,rand,rand,rand
|
114
114
|
#Rubyvis.mean([a,b,c,d]).should==(a+b+c+d).quo(4)
|
115
|
-
Rubyvis.mean([a,b,c,d].map {|x| x.to_s}, lambda {|v| v.to_f+1}).
|
115
|
+
expect(Rubyvis.mean([a,b,c,d].map {|x| x.to_s}, lambda {|v| v.to_f+1})).to eq((a+b+c+d).quo(4)+1)
|
116
116
|
end
|
117
117
|
it "method median returns median of values" do
|
118
|
-
Rubyvis.median([1,2,4,3]).
|
119
|
-
Rubyvis.median([1,3,2,5,3]).
|
120
|
-
Rubyvis.median([1,3,2,5,3].map {|v| v.to_s}, lambda {|v| v.to_f}).
|
118
|
+
expect(Rubyvis.median([1,2,4,3])).to eq(2.5)
|
119
|
+
expect(Rubyvis.median([1,3,2,5,3])).to eq(3)
|
120
|
+
expect(Rubyvis.median([1,3,2,5,3].map {|v| v.to_s}, lambda {|v| v.to_f})).to eq(3)
|
121
121
|
end
|
122
122
|
it "method variance returns sum of squares" do
|
123
|
-
Rubyvis.variance([5,7,9,11]).
|
124
|
-
Rubyvis.variance([5,7,9,11], lambda {|x| x+self.index}).
|
123
|
+
expect(Rubyvis.variance([5,7,9,11])).to eq(20)
|
124
|
+
expect(Rubyvis.variance([5,7,9,11], lambda {|x| x+self.index})).to eq(45)
|
125
125
|
end
|
126
126
|
it "method deviation returns standard deviation" do
|
127
|
-
Rubyvis.deviation([5,7,9,11]).
|
127
|
+
expect(Rubyvis.deviation([5,7,9,11])).to be_within( 0.001).of(2.581)
|
128
128
|
end
|
129
129
|
it "method log" do
|
130
|
-
Rubyvis.log(5,4).
|
130
|
+
expect(Rubyvis.log(5,4)).to be_within( 0.001).of(1.16)
|
131
131
|
end
|
132
132
|
it "method log_symmetric" do
|
133
|
-
Rubyvis.log_symmetric(-5,4).
|
133
|
+
expect(Rubyvis.log_symmetric(-5,4)).to be_within( 0.001).of(-1.16)
|
134
134
|
end
|
135
135
|
it "method log_adjusted" do
|
136
|
-
Rubyvis.log_adjusted(6,10).
|
136
|
+
expect(Rubyvis.log_adjusted(6,10)).to be_within( 0.001).of(0.806)
|
137
137
|
end
|
138
138
|
it "method log_floor" do
|
139
|
-
Rubyvis.log_floor(-5,4).
|
139
|
+
expect(Rubyvis.log_floor(-5,4)).to be_within( 0.001).of(16)
|
140
140
|
end
|
141
141
|
it "method log_ceil" do
|
142
|
-
Rubyvis.log_ceil(-5,4).
|
142
|
+
expect(Rubyvis.log_ceil(-5,4)).to be_within( 0.001).of(-4)
|
143
143
|
end
|
144
144
|
it "method dict" do
|
145
|
-
Rubyvis.dict(["one", "three", "seventeen"], lambda {|s| s.size}).
|
146
|
-
Rubyvis.dict(["one", "three", nil, "seventeen"], lambda {|s| s.size}).
|
145
|
+
expect(Rubyvis.dict(["one", "three", "seventeen"], lambda {|s| s.size})).to eq({"one"=> 3, "three"=> 5, "seventeen"=> 9})
|
146
|
+
expect(Rubyvis.dict(["one", "three", nil, "seventeen"], lambda {|s| s.size})).to eq({"one"=> 3, "three"=> 5, "seventeen"=> 9})
|
147
147
|
|
148
148
|
end
|
149
149
|
end
|