Skip to content

Commit dde1123

Browse files
committed
🎨 Standarize code ./spec directory
1 parent f6c890c commit dde1123

23 files changed

+2049
-2103
lines changed

spec/00_nmatrix_spec.rb

+305-304
Large diffs are not rendered by default.

spec/01_enum_spec.rb

+38-39
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
# Enumerator tests for NMatrix. These should load early, as they
2626
# test functionality essential to matrix printing.
2727
#
28-
require 'spec_helper'
28+
require "spec_helper"
2929

3030
describe "NMatrix enumeration for" do
3131
[:dense, :yale, :list].each do |stype|
3232
context stype do
3333
let(:n) { create_rectangular_matrix(stype) }
34-
let(:m) { n[1..4,1..3] }
34+
let(:m) { n[1..4, 1..3] }
3535

3636
if stype == :yale
3737
it "should iterate properly along each row of a slice" do
@@ -41,30 +41,30 @@
4141
jj = []
4242
m.extend NMatrix::YaleFunctions
4343
m.each_row do |row|
44-
row.each_with_indices do |v,i,j|
44+
row.each_with_indices do |v, i, j|
4545
vv << v
4646
ii << i
4747
jj << j
4848
end
4949
end
5050

51-
expect(vv).to eq([7,8,9, 12,13,0, 0,0,0, 0,17,18])
52-
expect(ii).to eq([0]*12)
53-
expect(jj).to eq([0,1,2]*4)
51+
expect(vv).to eq([7, 8, 9, 12, 13, 0, 0, 0, 0, 0, 17, 18])
52+
expect(ii).to eq([0] * 12)
53+
expect(jj).to eq([0, 1, 2] * 4)
5454
end
5555

5656
it "should iterate along diagonal portion of A array" do
5757
pending("not yet implemented for sparse matrices for NMatrix-JRuby") if jruby?
5858
vv = []
5959
ii = []
6060
jj = []
61-
n.send :__yale_stored_diagonal_each_with_indices__ do |v,i,j|
61+
n.send :__yale_stored_diagonal_each_with_indices__ do |v, i, j|
6262
vv << v
6363
ii << i
6464
jj << j
6565
end
66-
expect(vv).to eq([1,7,13,0,19])
67-
expect(ii).to eq([0,1,2,3,4])
66+
expect(vv).to eq([1, 7, 13, 0, 19])
67+
expect(ii).to eq([0, 1, 2, 3, 4])
6868
expect(jj).to eq(ii)
6969
end
7070

@@ -73,31 +73,31 @@
7373
vv = []
7474
ii = []
7575
jj = []
76-
n.send :__yale_stored_nondiagonal_each_with_indices__ do |v,i,j|
76+
n.send :__yale_stored_nondiagonal_each_with_indices__ do |v, i, j|
7777
vv << v
7878
ii << i
7979
jj << j
8080
end
8181

82-
expect(vv).to eq([2,3,4,5, 6,8,9,10, 11,12,14,15, 16,17,18,20])
83-
expect(ii).to eq([[0]*4, [1]*4, [2]*4, [4]*4].flatten)
84-
expect(jj).to eq([1,2,3,4, 0,2,3,5, 0,1,4,5, 0,2,3,5])
82+
expect(vv).to eq([2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 20])
83+
expect(ii).to eq([[0] * 4, [1] * 4, [2] * 4, [4] * 4].flatten)
84+
expect(jj).to eq([1, 2, 3, 4, 0, 2, 3, 5, 0, 1, 4, 5, 0, 2, 3, 5])
8585
end
8686

8787
it "should iterate along a sliced diagonal portion of an A array" do
8888
pending("not yet implemented for sparse matrices for NMatrix-JRuby") if jruby?
89-
m = n[0..3,1..3]
89+
m = n[0..3, 1..3]
9090
vv = []
9191
ii = []
9292
jj = []
93-
m.send :__yale_stored_diagonal_each_with_indices__ do |v,i,j|
93+
m.send :__yale_stored_diagonal_each_with_indices__ do |v, i, j|
9494
vv << v
9595
ii << i
9696
jj << j
9797
end
98-
expect(vv).to eq([7,13,0])
99-
expect(ii).to eq([1,2,3])
100-
expect(jj).to eq([0,1,2])
98+
expect(vv).to eq([7, 13, 0])
99+
expect(ii).to eq([1, 2, 3])
100+
expect(jj).to eq([0, 1, 2])
101101
end
102102

103103
it "should iterate along a sliced non-diagonal portion of a sliced A array" do
@@ -107,80 +107,79 @@
107107
jj = []
108108
n.extend NMatrix::YaleFunctions
109109
m.extend NMatrix::YaleFunctions
110-
m.send :__yale_stored_nondiagonal_each_with_indices__ do |v,i,j|
110+
m.send :__yale_stored_nondiagonal_each_with_indices__ do |v, i, j|
111111
vv << v
112112
ii << i
113113
jj << j
114114
end
115115

116-
expect(ii).to eq([0,0, 1, 3,3 ])
117-
expect(jj).to eq([1,2, 0, 1,2 ])
118-
expect(vv).to eq([8,9, 12, 17,18])
116+
expect(ii).to eq([0, 0, 1, 3, 3])
117+
expect(jj).to eq([1, 2, 0, 1, 2])
118+
expect(vv).to eq([8, 9, 12, 17, 18])
119119
end
120120

121121
it "should visit each stored element of the matrix in order by indices" do
122122
pending("not yet implemented for sparse matrices for NMatrix-JRuby") if jruby?
123123
vv = []
124124
ii = []
125125
jj = []
126-
n.each_ordered_stored_with_indices do |v,i,j|
126+
n.each_ordered_stored_with_indices do |v, i, j|
127127
vv << v
128128
ii << i
129129
jj << j
130130
end
131131

132132
expect(vv).to eq([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 16, 17, 18, 19, 20])
133-
expect(ii).to eq([[0]*5, [1]*5, [2]*5, [3]*1, [4]*5].flatten)
134-
expect(jj).to eq([0,1,2,3,4, 0,1,2,3,5, 0,1,2,4,5, 3, 0,2,3,4,5])
133+
expect(ii).to eq([[0] * 5, [1] * 5, [2] * 5, [3] * 1, [4] * 5].flatten)
134+
expect(jj).to eq([0, 1, 2, 3, 4, 0, 1, 2, 3, 5, 0, 1, 2, 4, 5, 3, 0, 2, 3, 4, 5])
135135
end
136136

137137
it "should visit each stored element of the slice in order by indices" do
138138
pending("not yet implemented for sparse matrices for NMatrix-JRuby") if jruby?
139139
vv = []
140140
ii = []
141141
jj = []
142-
m.each_ordered_stored_with_indices do |v,i,j|
142+
m.each_ordered_stored_with_indices do |v, i, j|
143143
vv << v
144144
ii << i
145145
jj << j
146146
end
147-
expect(ii).to eq([0,0,0, 1,1, 2, 3,3 ])
148-
expect(jj).to eq([0,1,2, 0,1, 2, 1,2 ])
149-
expect(vv).to eq([7,8,9, 12,13, 0, 17,18 ])
147+
expect(ii).to eq([0, 0, 0, 1, 1, 2, 3, 3])
148+
expect(jj).to eq([0, 1, 2, 0, 1, 2, 1, 2])
149+
expect(vv).to eq([7, 8, 9, 12, 13, 0, 17, 18])
150150
end
151151
end
152152

153153
it "should visit each cell in the matrix as if dense, making indices available" do
154154
vv = []
155155
ii = []
156156
jj = []
157-
n.each_with_indices do |v,i,j|
157+
n.each_with_indices do |v, i, j|
158158
vv << v
159159
ii << i
160160
jj << j
161161
end
162162

163-
expect(vv).to eq([1,2,3,4,5,0,6,7,8,9,0,10,11,12,13,0,14,15,0,0,0,0,0,0,16,0,17,18,19,20])
164-
expect(ii).to eq([[0]*6, [1]*6, [2]*6, [3]*6, [4]*6].flatten)
165-
expect(jj).to eq([0,1,2,3,4,5]*5)
163+
expect(vv).to eq([1, 2, 3, 4, 5, 0, 6, 7, 8, 9, 0, 10, 11, 12, 13, 0, 14, 15, 0, 0, 0, 0, 0, 0, 16, 0, 17, 18, 19, 20])
164+
expect(ii).to eq([[0] * 6, [1] * 6, [2] * 6, [3] * 6, [4] * 6].flatten)
165+
expect(jj).to eq([0, 1, 2, 3, 4, 5] * 5)
166166
end
167167

168168
it "should visit each cell in the slice as if dense, making indices available" do
169169
vv = []
170170
ii = []
171171
jj = []
172-
m.each_with_indices do |v,i,j|
172+
m.each_with_indices do |v, i, j|
173173
vv << v
174174
ii << i
175175
jj << j
176176
end
177-
expect(jj).to eq([0,1,2]*4)
178-
expect(ii).to eq([[0]*3, [1]*3, [2]*3, [3]*3].flatten)
179-
expect(vv).to eq([7,8,9,12,13,0,0,0,0,0,17,18])
180-
177+
expect(jj).to eq([0, 1, 2] * 4)
178+
expect(ii).to eq([[0] * 3, [1] * 3, [2] * 3, [3] * 3].flatten)
179+
expect(vv).to eq([7, 8, 9, 12, 13, 0, 0, 0, 0, 0, 17, 18])
181180
end
182181

183-
if stype == :list or stype == :dense then
182+
if (stype == :list) || (stype == :dense)
184183
it "should correctly map to a matrix with a single element" do
185184
nm = N.new([1], [2.0], stype: stype)
186185
expect(nm.map { |e| e**2 }).to eq N.new([1], [4.0], stype: stype)

0 commit comments

Comments
 (0)