Skip to content

Commit 2d7588d

Browse files
committed
Support running specs without gsl or nmatrix installed
1 parent 3ac3d15 commit 2d7588d

File tree

5 files changed

+31
-36
lines changed

5 files changed

+31
-36
lines changed

spec/dataframe_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,7 +2415,7 @@
24152415
end
24162416

24172417
context "#recast" do
2418-
it "recasts underlying vectors" do
2418+
it "recasts underlying vectors", :nmatrix do
24192419
@data_frame.recast a: :nmatrix, c: :nmatrix
24202420

24212421
expect(@data_frame.a.dtype).to eq(:nmatrix)
@@ -2875,7 +2875,7 @@
28752875
end
28762876
end
28772877

2878-
context "#to_nmatrix" do
2878+
context "#to_nmatrix", :nmatrix do
28792879
before do
28802880
@df = Daru::DataFrame.new({b: [11,12,13,14,15], a: [1,2,3,4,5],
28812881
c: [11,22,33,44,55], d: [5,4,nil,2,1], e: ['this', 'has', 'string','data','too']},
@@ -3274,7 +3274,7 @@
32743274
end
32753275
end
32763276

3277-
context "#to_gsl" do
3277+
context "#to_gsl", :gsl do
32783278
it "converts to GSL::Matrix" do
32793279
rows = [[1,2,3,4,5],[11,12,13,14,15],[11,22,33,44,55]].transpose
32803280
mat = GSL::Matrix.alloc *rows

spec/io/io_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@
525525

526526
context "#save" do
527527
ALL_DTYPES.each do |dtype|
528-
it "saves to a file and returns the same Vector of type #{dtype}" do
528+
it "saves to a file and returns the same Vector of type #{dtype}", dtype do
529529
vector = Daru::Vector.new(
530530
[5, 5, 5, 5, 5, 6, 6, 7, 8, 9, 10, 1, 2, 3, 4, 11, -99, -99],
531531
dtype: dtype)

spec/maths/statistics/vector_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
describe Daru::Vector do
22
[:array, :gsl].each do |dtype| #nmatrix still unstable
3-
describe dtype do
3+
describe dtype.to_s, dtype do
44
before do
55
@dv = Daru::Vector.new [323, 11, 555, 666, 234, 21, 666, 343, 1, 2], dtype: dtype
66
@dv_with_nils = Daru::Vector.new [323, 11, 555, nil, 666, 234, 21, 666, 343, nil, 1, 2]

spec/spec_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ def expect_correct_df_in_delta df1, df2, delta
5555
end
5656
end
5757

58+
RSpec.configure do |c|
59+
c.filter_run_excluding(:gsl) unless Daru.has_gsl?
60+
c.filter_run_excluding(:nmatrix) unless Daru.has_nmatrix?
61+
end
62+
5863
RSpec::Matchers.define :be_all_within do |delta|
5964
match do |actual|
6065
expect(@expected).to_not be_nil

spec/vector_spec.rb

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe Daru::Vector do
44
ALL_DTYPES.each do |dtype|
5-
describe dtype.to_s do
5+
describe dtype.to_s, dtype do
66
before do
77
@common_all_dtypes = Daru::Vector.new(
88
[5, 5, 5, 5, 5, 6, 6, 7, 8, 9, 10, 1, 2, 3, 4, 11, -99, -99],
@@ -84,7 +84,7 @@
8484
expect(dv.index.to_a).to eq(['a', 'b', :r, 0])
8585
end
8686

87-
it "initializes array with nils with dtype NMatrix" do
87+
it "initializes array with nils with dtype NMatrix", :nmatrix do
8888
dv = Daru::Vector.new [2, nil], dtype: :nmatrix
8989
expect(dv.to_a).to eq([2, nil])
9090
expect(dv.index.to_a).to eq([0, 1])
@@ -1064,7 +1064,7 @@
10641064

10651065
context "#cast" do
10661066
ALL_DTYPES.each do |new_dtype|
1067-
it "casts from #{dtype} to #{new_dtype}" do
1067+
it "casts from #{dtype} to #{new_dtype}", new_dtype do
10681068
v = Daru::Vector.new [1,2,3,4], dtype: dtype
10691069
v.cast(dtype: new_dtype)
10701070
expect(v.dtype).to eq(new_dtype)
@@ -1360,18 +1360,13 @@
13601360
expect(a.dtype).to eq(:array)
13611361
end
13621362

1363-
it "maps and returns a vector of dtype gsl" do
1364-
a = @common_all_dtypes.recode(:gsl) { |v| v == -99 ? 1 : 0 }
1365-
exp = Daru::Vector.new [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], dtype: :gsl
1366-
expect(a).to eq(exp)
1367-
expect(a.dtype).to eq(:gsl)
1368-
end
1369-
1370-
it "maps and returns a vector of dtype nmatrix" do
1371-
a = @common_all_dtypes.recode(:nmatrix) { |v| v == -99 ? 1 : 0 }
1372-
exp = Daru::Vector.new [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], dtype: :nmatrix
1373-
expect(a).to eq(exp)
1374-
expect(a.dtype).to eq(:nmatrix)
1363+
ALL_DTYPES.each do |dtype|
1364+
it "maps and returns a vector of dtype #{dtype}", dtype do
1365+
a = @common_all_dtypes.recode(dtype) { |v| v == -99 ? 1 : 0 }
1366+
exp = Daru::Vector.new [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], dtype: dtype
1367+
expect(a).to eq(exp)
1368+
expect(a.dtype).to eq(exp.dtype)
1369+
end
13751370
end
13761371
end
13771372

@@ -1389,18 +1384,13 @@
13891384
expect(@vector.dtype).to eq(dtype)
13901385
end
13911386

1392-
it "destructively maps and returns a vector of dtype gsl" do
1393-
@vector.recode!(:gsl) { |v| v == -99 ? 1 : 0 }
1394-
exp = Daru::Vector.new [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], dtype: :gsl
1395-
expect(@vector).to eq(exp)
1396-
expect(@vector.dtype).to eq(exp.dtype)
1397-
end
1398-
1399-
it "destructively maps and returns a vector of dtype nmatrix" do
1400-
@vector.recode!(:nmatrix) { |v| v == -99 ? 1 : 0 }
1401-
exp = Daru::Vector.new [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], dtype: :nmatrix
1402-
expect(@vector).to eq(exp)
1403-
expect(@vector.dtype).to eq(exp.dtype)
1387+
ALL_DTYPES.each do |dtype|
1388+
it "destructively maps and returns a vector of dtype #{dtype}", dtype do
1389+
@vector.recode!(dtype) { |v| v == -99 ? 1 : 0 }
1390+
exp = Daru::Vector.new [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], dtype: dtype
1391+
expect(@vector).to eq(exp)
1392+
expect(@vector.dtype).to eq(exp.dtype)
1393+
end
14041394
end
14051395
end
14061396

@@ -1593,7 +1583,7 @@
15931583
its(:'index.to_a') { is_expected.to eq [] }
15941584
end
15951585

1596-
context 'works for gsl' do
1586+
context 'works for gsl', :gsl do
15971587
let(:dv) { Daru::Vector.new [1, 2, 3, Float::NAN], dtype: :gsl,
15981588
index: 11..14 }
15991589
subject { dv.reject_values Float::NAN }
@@ -1857,7 +1847,7 @@
18571847
expect(@multi.type).to eq(:object)
18581848
end
18591849

1860-
it "tells NMatrix data type in case of NMatrix wrapper" do
1850+
it "tells NMatrix data type in case of NMatrix wrapper", :nmatrix do
18611851
nm = Daru::Vector.new([1,2,3,4,5], dtype: :nmatrix)
18621852
expect(nm.type).to eq(:int32)
18631853
end
@@ -1908,7 +1898,7 @@
19081898
end
19091899
end
19101900

1911-
context '#to_nmatrix' do
1901+
context '#to_nmatrix', :nmatrix do
19121902
let(:dv) { Daru::Vector.new [1, 2, 3, 4, 5] }
19131903

19141904
context 'horizontal axis' do
@@ -1945,7 +1935,7 @@
19451935
end
19461936
end
19471937

1948-
context "#to_gsl" do
1938+
context "#to_gsl", :gsl do
19491939
it "returns a GSL::Vector of non-nil data" do
19501940
vector = Daru::Vector.new [1,2,3,4,nil,6,nil]
19511941
expect(vector.to_gsl).to eq(GSL::Vector.alloc(1,2,3,4,6))

0 commit comments

Comments
 (0)