daru_lite 0.3.4 → 0.4.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 +4 -4
- data/History.md +84 -0
- data/README.md +16 -1
- data/lib/daru_lite/category.rb +1 -1
- data/lib/daru_lite/core/group_by.rb +0 -4
- data/lib/daru_lite/core/merge.rb +2 -2
- data/lib/daru_lite/data_frame/calculatable.rb +12 -6
- data/lib/daru_lite/data_frame/duplicatable.rb +0 -14
- data/lib/daru_lite/data_frame/iterable.rb +2 -2
- data/lib/daru_lite/data_frame/missable.rb +0 -9
- data/lib/daru_lite/dataframe.rb +34 -9
- data/lib/daru_lite/date_time/index.rb +4 -4
- data/lib/daru_lite/index/multi_index.rb +1 -2
- data/lib/daru_lite/maths/statistics/dataframe.rb +2 -4
- data/lib/daru_lite/maths/statistics/vector.rb +3 -8
- data/lib/daru_lite/monkeys/array.rb +4 -0
- data/lib/daru_lite/monkeys/hash.rb +3 -0
- data/lib/daru_lite/monkeys/matrix.rb +3 -0
- data/lib/daru_lite/monkeys/range.rb +4 -0
- data/lib/daru_lite/vector/missable.rb +0 -55
- data/lib/daru_lite/vector/sortable.rb +2 -2
- data/lib/daru_lite/vector.rb +3 -9
- data/lib/daru_lite/version.rb +1 -1
- data/lib/daru_lite.rb +8 -10
- metadata +54 -287
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- data/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- data/.github/dependabot.yml +0 -11
- data/.github/workflows/ci.yml +0 -33
- data/.gitignore +0 -10
- data/.rspec +0 -2
- data/.rubocop.yml +0 -27
- data/.rubocop_todo.yml +0 -139
- data/CONTRIBUTING.md +0 -47
- data/Gemfile +0 -2
- data/Rakefile +0 -69
- data/ReleasePolicy.md +0 -20
- data/benchmarks/TradeoffData.csv +0 -65
- data/benchmarks/csv_reading.rb +0 -22
- data/benchmarks/dataframe_creation.rb +0 -39
- data/benchmarks/db_loading.rb +0 -33
- data/benchmarks/duplicating.rb +0 -45
- data/benchmarks/group_by.rb +0 -32
- data/benchmarks/joining.rb +0 -52
- data/benchmarks/row_access.rb +0 -41
- data/benchmarks/row_assign.rb +0 -36
- data/benchmarks/sorting.rb +0 -51
- data/benchmarks/statistics.rb +0 -28
- data/benchmarks/vector_access.rb +0 -31
- data/benchmarks/vector_assign.rb +0 -42
- data/benchmarks/where_clause.rb +0 -48
- data/benchmarks/where_vs_filter.rb +0 -28
- data/daru_lite.gemspec +0 -54
- data/daru_lite_test-shm +0 -0
- data/daru_lite_test-wal +0 -0
- data/images/README.md +0 -5
- data/images/con0.png +0 -0
- data/images/con1.png +0 -0
- data/images/init0.png +0 -0
- data/images/init1.png +0 -0
- data/images/man0.png +0 -0
- data/images/man1.png +0 -0
- data/images/man2.png +0 -0
- data/images/man3.png +0 -0
- data/images/man4.png +0 -0
- data/images/man5.png +0 -0
- data/images/man6.png +0 -0
- data/lib/daru_lite/accessors/mdarray_wrapper.rb +0 -7
- data/lib/daru_lite/monkeys/m_d_array.rb +0 -7
- data/lib/daru_lite/monkeys/object.rb +0 -7
- data/profile/_base.rb +0 -23
- data/profile/df_to_a.rb +0 -10
- data/profile/filter.rb +0 -13
- data/profile/joining.rb +0 -13
- data/profile/sorting.rb +0 -12
- data/profile/vector_each_with_index.rb +0 -9
- data/profile/vector_new.rb +0 -9
- data/spec/accessors/array_wrapper_spec.rb +0 -3
- data/spec/category_spec.rb +0 -1767
- data/spec/core/group_by_spec.rb +0 -655
- data/spec/core/merge_spec.rb +0 -179
- data/spec/core/query_spec.rb +0 -347
- data/spec/daru_lite_spec.rb +0 -22
- data/spec/data_frame/aggregatable_example.rb +0 -65
- data/spec/data_frame/buildable_example.rb +0 -109
- data/spec/data_frame/calculatable_example.rb +0 -135
- data/spec/data_frame/convertible_example.rb +0 -180
- data/spec/data_frame/duplicatable_example.rb +0 -134
- data/spec/data_frame/fetchable_example.rb +0 -510
- data/spec/data_frame/filterable_example.rb +0 -456
- data/spec/data_frame/indexable_example.rb +0 -221
- data/spec/data_frame/iterable_example.rb +0 -481
- data/spec/data_frame/joinable_example.rb +0 -131
- data/spec/data_frame/missable_example.rb +0 -47
- data/spec/data_frame/pivotable_example.rb +0 -297
- data/spec/data_frame/queryable_example.rb +0 -92
- data/spec/data_frame/setable_example.rb +0 -513
- data/spec/data_frame/sortable_example.rb +0 -368
- data/spec/dataframe_spec.rb +0 -1342
- data/spec/date_time/data_spec.rb +0 -197
- data/spec/date_time/date_time_index_helper_spec.rb +0 -72
- data/spec/date_time/index_spec.rb +0 -588
- data/spec/date_time/offsets_spec.rb +0 -465
- data/spec/extensions/which_dsl_spec.rb +0 -38
- data/spec/fixtures/bank2.dat +0 -200
- data/spec/fixtures/boolean_converter_test.csv +0 -5
- data/spec/fixtures/countries.json +0 -7794
- data/spec/fixtures/duplicates.csv +0 -32
- data/spec/fixtures/eciresults.html +0 -394
- data/spec/fixtures/empties.dat +0 -2
- data/spec/fixtures/empty_rows_test.csv +0 -17
- data/spec/fixtures/macau.html +0 -3691
- data/spec/fixtures/macd_data.csv +0 -150
- data/spec/fixtures/matrix_test.csv +0 -100
- data/spec/fixtures/moneycontrol.html +0 -6812
- data/spec/fixtures/music_data.tsv +0 -2501
- data/spec/fixtures/repeated_fields.csv +0 -7
- data/spec/fixtures/sales-funnel.csv +0 -18
- data/spec/fixtures/scientific_notation.csv +0 -4
- data/spec/fixtures/string_converter_test.csv +0 -5
- data/spec/fixtures/strings.dat +0 -2
- data/spec/fixtures/test_xls.xls +0 -0
- data/spec/fixtures/test_xls_2.xls +0 -0
- data/spec/fixtures/url_test.txt~ +0 -0
- data/spec/fixtures/valid_markup.html +0 -62
- data/spec/fixtures/wiki_climate.html +0 -1243
- data/spec/fixtures/wiki_table_info.html +0 -631
- data/spec/formatters/table_formatter_spec.rb +0 -137
- data/spec/helpers_spec.rb +0 -8
- data/spec/index/categorical_index_spec.rb +0 -289
- data/spec/index/index_spec.rb +0 -438
- data/spec/index/multi_index_spec.rb +0 -752
- data/spec/io/io_spec.rb +0 -357
- data/spec/io/sql_data_source_spec.rb +0 -48
- data/spec/iruby/dataframe_spec.rb +0 -170
- data/spec/iruby/helpers_spec.rb +0 -49
- data/spec/iruby/multi_index_spec.rb +0 -37
- data/spec/iruby/vector_spec.rb +0 -105
- data/spec/maths/arithmetic/dataframe_spec.rb +0 -148
- data/spec/maths/arithmetic/vector_spec.rb +0 -165
- data/spec/maths/statistics/dataframe_spec.rb +0 -191
- data/spec/maths/statistics/vector_spec.rb +0 -756
- data/spec/monkeys_spec.rb +0 -42
- data/spec/shared/vector_display_spec.rb +0 -213
- data/spec/spec_helper.rb +0 -87
- data/spec/support/database_helper.rb +0 -29
- data/spec/support/matchers.rb +0 -5
- data/spec/vector/aggregatable_example.rb +0 -27
- data/spec/vector/calculatable_example.rb +0 -82
- data/spec/vector/convertible_example.rb +0 -126
- data/spec/vector/duplicatable_example.rb +0 -48
- data/spec/vector/fetchable_example.rb +0 -463
- data/spec/vector/filterable_example.rb +0 -165
- data/spec/vector/indexable_example.rb +0 -201
- data/spec/vector/iterable_example.rb +0 -111
- data/spec/vector/joinable_example.rb +0 -25
- data/spec/vector/missable_example.rb +0 -88
- data/spec/vector/queryable_example.rb +0 -91
- data/spec/vector/setable_example.rb +0 -300
- data/spec/vector/sortable_example.rb +0 -242
- data/spec/vector_spec.rb +0 -599
data/spec/index/index_spec.rb
DELETED
|
@@ -1,438 +0,0 @@
|
|
|
1
|
-
require 'spec_helper.rb'
|
|
2
|
-
|
|
3
|
-
describe DaruLite::Index do
|
|
4
|
-
let(:index) { described_class.new(keys) }
|
|
5
|
-
let(:keys) { ['one', 'two', 'three'] }
|
|
6
|
-
|
|
7
|
-
context ".new" do
|
|
8
|
-
it "creates an Index object if Index-like data is supplied" do
|
|
9
|
-
i = DaruLite::Index.new [:one, 'one', 1, 2, :two]
|
|
10
|
-
expect(i.class).to eq(DaruLite::Index)
|
|
11
|
-
expect(i.to_a) .to eq([:one, 'one', 1, 2, :two])
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "creates a MultiIndex if tuples are supplied" do
|
|
15
|
-
i = DaruLite::Index.new([
|
|
16
|
-
[:b,:one,:bar],
|
|
17
|
-
[:b,:two,:bar],
|
|
18
|
-
[:b,:two,:baz],
|
|
19
|
-
[:b,:one,:foo]
|
|
20
|
-
])
|
|
21
|
-
|
|
22
|
-
expect(i.class).to eq(DaruLite::MultiIndex)
|
|
23
|
-
expect(i.levels).to eq([[:b], [:one, :two], [:bar, :baz, :foo]])
|
|
24
|
-
expect(i.labels).to eq([[0,0,0,0],[0,1,1,0],[0,0,1,2]])
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it "creates DateTimeIndex if date-like objects specified" do
|
|
28
|
-
i = DaruLite::Index.new([
|
|
29
|
-
DateTime.new(2012,2,4), DateTime.new(2012,2,5), DateTime.new(2012,2,6)])
|
|
30
|
-
expect(i.class).to eq(DaruLite::DateTimeIndex)
|
|
31
|
-
expect(i.to_a).to eq([DateTime.new(2012,2,4), DateTime.new(2012,2,5), DateTime.new(2012,2,6)])
|
|
32
|
-
expect(i.frequency).to eq('D')
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
context "create an Index with name" do
|
|
36
|
-
context 'if no name is set' do
|
|
37
|
-
subject { DaruLite::Index.new [:a, :b, :c] }
|
|
38
|
-
its(:name) { is_expected.to be_nil }
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
context 'correctly return the index name' do
|
|
42
|
-
subject { DaruLite::Index.new [:a, :b, :c], name: 'index_name' }
|
|
43
|
-
its(:name) { is_expected.to eq 'index_name' }
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
context "set new index name" do
|
|
47
|
-
subject {
|
|
48
|
-
DaruLite::Index.new([:a, :b, :c], name: 'index_name') }
|
|
49
|
-
before { subject.name = 'new_name'}
|
|
50
|
-
its(:name) { is_expected.to eq 'new_name' }
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
context "#initialize" do
|
|
56
|
-
it "creates an Index from Array" do
|
|
57
|
-
idx = DaruLite::Index.new ['speaker', 'mic', 'guitar', 'amp']
|
|
58
|
-
|
|
59
|
-
expect(idx.to_a).to eq(['speaker', 'mic', 'guitar', 'amp'])
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it "creates an Index from Range" do
|
|
63
|
-
idx = DaruLite::Index.new 1..5
|
|
64
|
-
|
|
65
|
-
expect(idx).to eq(DaruLite::Index.new [1, 2, 3, 4, 5])
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it "raises ArgumentError on invalid input type" do
|
|
69
|
-
expect { DaruLite::Index.new 'foo' }.to raise_error ArgumentError
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it "accepts all sorts of objects for Indexing" do
|
|
73
|
-
idx = DaruLite::Index.new [:a, 'a', :hello, '23', 23]
|
|
74
|
-
|
|
75
|
-
expect(idx.to_a).to eq([:a, 'a', :hello, '23', 23])
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
context '#key' do
|
|
80
|
-
subject(:idx) { DaruLite::Index.new ['speaker', 'mic', 'guitar', 'amp'] }
|
|
81
|
-
|
|
82
|
-
it 'returns key by position' do
|
|
83
|
-
expect(idx.key(2)).to eq 'guitar'
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
it 'returns nil on too large pos' do
|
|
87
|
-
expect(idx.key(20)).to be_nil
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
it 'returns nil on wrong arg type' do
|
|
91
|
-
expect(idx.key(nil)).to be_nil
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
context '#sort' do
|
|
96
|
-
let(:asc) { index.sort }
|
|
97
|
-
let(:desc) { index.sort(ascending: false) }
|
|
98
|
-
|
|
99
|
-
context 'string index' do
|
|
100
|
-
let(:index) { DaruLite::Index.new ['mic', 'amp', 'guitar', 'speaker'] }
|
|
101
|
-
specify { expect(asc).to eq DaruLite::Index.new ['amp', 'guitar', 'mic',
|
|
102
|
-
'speaker'] }
|
|
103
|
-
specify { expect(desc).to eq DaruLite::Index.new ['speaker', 'mic', 'guitar',
|
|
104
|
-
'amp'] }
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
context 'number index' do
|
|
108
|
-
let(:index) { DaruLite::Index.new [100, 99, 101, 1, 2] }
|
|
109
|
-
specify { expect(asc).to eq DaruLite::Index.new [1, 2, 99, 100, 101] }
|
|
110
|
-
specify { expect(desc).to eq DaruLite::Index.new [101, 100, 99, 2, 1] }
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
context "#size" do
|
|
115
|
-
it "correctly returns the size of the index" do
|
|
116
|
-
idx = DaruLite::Index.new ['speaker', 'mic', 'guitar', 'amp']
|
|
117
|
-
|
|
118
|
-
expect(idx.size).to eq(4)
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
context "#valid?" do
|
|
123
|
-
let(:idx) { DaruLite::Index.new [:a, :b, :c] }
|
|
124
|
-
|
|
125
|
-
context "single index" do
|
|
126
|
-
it { expect(idx.valid? 2).to eq true }
|
|
127
|
-
it { expect(idx.valid? :d).to eq false }
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
context "multiple indexes" do
|
|
131
|
-
it { expect(idx.valid? :a, 1).to eq true }
|
|
132
|
-
it { expect(idx.valid? :a, 3).to eq false }
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
context '#inspect' do
|
|
137
|
-
context 'small index' do
|
|
138
|
-
subject { DaruLite::Index.new ['one', 'two', 'three'] }
|
|
139
|
-
its(:inspect) { is_expected.to eq "#<DaruLite::Index(3): {one, two, three}>" }
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
context 'large index' do
|
|
143
|
-
subject { DaruLite::Index.new ('a'..'z').to_a }
|
|
144
|
-
its(:inspect) { is_expected.to eq "#<DaruLite::Index(26): {a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t ... z}>" }
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
context 'index with name' do
|
|
148
|
-
subject { DaruLite::Index.new ['one', 'two', 'three'], name: 'number' }
|
|
149
|
-
its(:inspect) { is_expected.to eq "#<DaruLite::Index(3): number {one, two, three}>" }
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
describe "#to_a" do
|
|
154
|
-
subject { index.to_a }
|
|
155
|
-
|
|
156
|
-
it { is_expected.to eq(keys) }
|
|
157
|
-
|
|
158
|
-
it 'the returns array is not a variable of the index' do
|
|
159
|
-
expect { subject << 'four' }.not_to change { index.to_a }
|
|
160
|
-
end
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
context "#&" do
|
|
164
|
-
before :each do
|
|
165
|
-
@left = DaruLite::Index.new [:miles, :geddy, :eric]
|
|
166
|
-
@right = DaruLite::Index.new [:geddy, :richie, :miles]
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
it "intersects 2 indexes and returns an Index" do
|
|
170
|
-
expect(@left & @right).to eq([:miles, :geddy].to_index)
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
it "intersects an Index and an Array to return an Index" do
|
|
174
|
-
expect(@left & [:bob, :geddy, :richie]).to eq([:geddy].to_index)
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
context "#|" do
|
|
179
|
-
before :each do
|
|
180
|
-
@left = DaruLite::Index.new [:miles, :geddy, :eric]
|
|
181
|
-
@right = DaruLite::Index.new [:bob, :jimi, :richie]
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
it "unions 2 indexes and returns an Index" do
|
|
185
|
-
expect(@left | @right).to eq([:miles, :geddy, :eric, :bob, :jimi, :richie].to_index)
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
it "unions an Index and an Array to return an Index" do
|
|
189
|
-
expect(@left | [:bob, :jimi, :richie]).to eq([:miles, :geddy, :eric,
|
|
190
|
-
:bob, :jimi, :richie].to_index)
|
|
191
|
-
end
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
context "#[]" do
|
|
195
|
-
before do
|
|
196
|
-
@id = DaruLite::Index.new [:one, :two, :three, :four, :five, :six, :seven]
|
|
197
|
-
@mixed_id = DaruLite::Index.new ['a','b','c',:d,:a,8,3,5]
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
it "works with ranges" do
|
|
201
|
-
expect(@id[:two..:five]).to eq([1, 2, 3, 4])
|
|
202
|
-
|
|
203
|
-
expect(@mixed_id['a'..'c']).to eq([0, 1, 2])
|
|
204
|
-
|
|
205
|
-
# returns nil if first index is invalid
|
|
206
|
-
expect(@mixed_id.slice('d', 5)).to be_nil
|
|
207
|
-
|
|
208
|
-
# returns positions till the end if first index is present
|
|
209
|
-
expect(@mixed_id.slice('c', 6)).to eq([2, 3, 4, 5, 6, 7])
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
it "returns multiple keys if specified multiple indices" do
|
|
213
|
-
expect(@id[:one, :two, :four, :five]).to eq([0, 1, 3, 4])
|
|
214
|
-
expect(@mixed_id[0,5,3,2]).to eq([nil, 7, 6, nil])
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
it "returns nil for invalid indexes" do
|
|
218
|
-
expect(@id[:four]).to eq(3)
|
|
219
|
-
expect(@id[3]).to be_nil
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
it "returns correct index position for mixed index" do
|
|
223
|
-
expect(@mixed_id[8]).to eq(5)
|
|
224
|
-
expect(@mixed_id['c']).to eq(2)
|
|
225
|
-
end
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
context "#pos" do
|
|
229
|
-
let(:idx) { described_class.new [:a, :b, 1, 2] }
|
|
230
|
-
|
|
231
|
-
context "single index" do
|
|
232
|
-
it { expect(idx.pos :a).to eq 0 }
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
context "multiple indexes" do
|
|
236
|
-
subject { idx.pos :a, 1 }
|
|
237
|
-
|
|
238
|
-
it { is_expected.to be_a Array }
|
|
239
|
-
its(:size) { is_expected.to eq 2 }
|
|
240
|
-
it { is_expected.to eq [0, 2] }
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
context "single positional index" do
|
|
244
|
-
it { expect(idx.pos 0).to eq 0 }
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
context "multiple positional index" do
|
|
248
|
-
subject { idx.pos 0, 3 }
|
|
249
|
-
|
|
250
|
-
it { is_expected.to be_a Array }
|
|
251
|
-
its(:size) { is_expected.to eq 2 }
|
|
252
|
-
it { is_expected.to eq [0, 3] }
|
|
253
|
-
end
|
|
254
|
-
|
|
255
|
-
context "range" do
|
|
256
|
-
subject { idx.pos 1..3 }
|
|
257
|
-
|
|
258
|
-
it { is_expected.to be_a Array }
|
|
259
|
-
its(:size) { is_expected.to eq 3 }
|
|
260
|
-
it { is_expected.to eq [1, 2, 3] }
|
|
261
|
-
end
|
|
262
|
-
end
|
|
263
|
-
|
|
264
|
-
context "#subset" do
|
|
265
|
-
let(:idx) { described_class.new [:a, :b, 1, 2] }
|
|
266
|
-
|
|
267
|
-
context "multiple indexes" do
|
|
268
|
-
subject { idx.subset :a, 1 }
|
|
269
|
-
|
|
270
|
-
it { is_expected.to be_a described_class }
|
|
271
|
-
its(:size) { is_expected.to eq 2 }
|
|
272
|
-
its(:to_a) { is_expected.to eq [:a, 1] }
|
|
273
|
-
end
|
|
274
|
-
|
|
275
|
-
context "multiple positional indexes" do
|
|
276
|
-
subject { idx.subset 0, 3 }
|
|
277
|
-
|
|
278
|
-
it { is_expected.to be_a described_class }
|
|
279
|
-
its(:size) { is_expected.to eq 2 }
|
|
280
|
-
its(:to_a) { is_expected.to eq [:a, 2] }
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
context "range" do
|
|
284
|
-
subject { idx.subset 1..3 }
|
|
285
|
-
|
|
286
|
-
it { is_expected.to be_a described_class }
|
|
287
|
-
its(:size) { is_expected.to eq 3 }
|
|
288
|
-
its(:to_a) { is_expected.to eq [:b, 1, 2] }
|
|
289
|
-
end
|
|
290
|
-
end
|
|
291
|
-
|
|
292
|
-
context "#at" do
|
|
293
|
-
let(:idx) { described_class.new [:a, :b, 1 ] }
|
|
294
|
-
|
|
295
|
-
context "single position" do
|
|
296
|
-
it { expect(idx.at 1).to eq :b }
|
|
297
|
-
end
|
|
298
|
-
|
|
299
|
-
context "multiple positions" do
|
|
300
|
-
subject { idx.at 1, 2 }
|
|
301
|
-
|
|
302
|
-
it { is_expected.to be_a described_class }
|
|
303
|
-
its(:size) { is_expected.to eq 2 }
|
|
304
|
-
its(:to_a) { is_expected.to eq [:b, 1] }
|
|
305
|
-
end
|
|
306
|
-
|
|
307
|
-
context "range" do
|
|
308
|
-
subject { idx.at 1..2 }
|
|
309
|
-
|
|
310
|
-
it { is_expected.to be_a described_class }
|
|
311
|
-
its(:size) { is_expected.to eq 2 }
|
|
312
|
-
its(:to_a) { is_expected.to eq [:b, 1] }
|
|
313
|
-
end
|
|
314
|
-
|
|
315
|
-
context "range with negative integer" do
|
|
316
|
-
subject { idx.at 1..-1 }
|
|
317
|
-
|
|
318
|
-
it { is_expected.to be_a described_class }
|
|
319
|
-
its(:size) { is_expected.to eq 2 }
|
|
320
|
-
its(:to_a) { is_expected.to eq [:b, 1] }
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
context "rangle with single element" do
|
|
324
|
-
subject { idx.at 1..1 }
|
|
325
|
-
|
|
326
|
-
it { is_expected.to be_a described_class }
|
|
327
|
-
its(:size) { is_expected.to eq 1 }
|
|
328
|
-
its(:to_a) { is_expected.to eq [:b] }
|
|
329
|
-
end
|
|
330
|
-
|
|
331
|
-
context "invalid position" do
|
|
332
|
-
it { expect { idx.at 3 }.to raise_error IndexError }
|
|
333
|
-
end
|
|
334
|
-
|
|
335
|
-
context "invalid positions" do
|
|
336
|
-
it { expect { idx.at 2, 3 }.to raise_error IndexError }
|
|
337
|
-
end
|
|
338
|
-
end
|
|
339
|
-
|
|
340
|
-
# This context validate DaruLite::Index is like an enumerable.
|
|
341
|
-
# #map and #select are samples and we do not need tests all
|
|
342
|
-
# enumerable methods.
|
|
343
|
-
context "Enumerable" do
|
|
344
|
-
let(:idx) { DaruLite::Index.new ['speaker', 'mic', 'guitar', 'amp'] }
|
|
345
|
-
|
|
346
|
-
context "#map" do
|
|
347
|
-
it { expect(idx.map(&:upcase)).to eq(['SPEAKER', 'MIC', 'GUITAR', 'AMP']) }
|
|
348
|
-
end
|
|
349
|
-
|
|
350
|
-
context "select" do
|
|
351
|
-
it { expect(idx.select {|w| w[0] == 'g' }).to eq(['guitar']) }
|
|
352
|
-
end
|
|
353
|
-
end
|
|
354
|
-
|
|
355
|
-
context "#is_values" do
|
|
356
|
-
let(:klass) { DaruLite::Vector }
|
|
357
|
-
let(:idx) { described_class.new [:one, 'one', 1, 2, 'two', nil, [1, 2]] }
|
|
358
|
-
|
|
359
|
-
context "no arguments" do
|
|
360
|
-
let(:answer) { [false, false, false, false, false, false, false] }
|
|
361
|
-
it { expect(idx.is_values).to eq klass.new(answer) }
|
|
362
|
-
end
|
|
363
|
-
|
|
364
|
-
context "single arguments" do
|
|
365
|
-
let(:answer) { [false, true, false, false, false, false, false] }
|
|
366
|
-
it { expect(idx.is_values 'one').to eq klass.new(answer) }
|
|
367
|
-
end
|
|
368
|
-
|
|
369
|
-
context "multiple arguments" do
|
|
370
|
-
context "symbol and number as argument" do
|
|
371
|
-
subject { idx.is_values 2, :one }
|
|
372
|
-
let(:answer) { [true, false, false, true, false, false, false] }
|
|
373
|
-
it { is_expected.to be_a DaruLite::Vector }
|
|
374
|
-
its(:size) { is_expected.to eq 7 }
|
|
375
|
-
it { is_expected.to eq klass.new(answer) }
|
|
376
|
-
end
|
|
377
|
-
|
|
378
|
-
context "string and number as argument" do
|
|
379
|
-
subject { idx.is_values('one', 1)}
|
|
380
|
-
let(:answer) { [false, true, true, false, false, false, false] }
|
|
381
|
-
it { is_expected.to be_a DaruLite::Vector }
|
|
382
|
-
its(:size) { is_expected.to eq 7 }
|
|
383
|
-
it { is_expected.to eq klass.new(answer) }
|
|
384
|
-
end
|
|
385
|
-
|
|
386
|
-
context "nil is present in arguments" do
|
|
387
|
-
subject { idx.is_values('two', nil)}
|
|
388
|
-
let(:answer) { [false, false, false, false, true, true, false] }
|
|
389
|
-
it { is_expected.to be_a DaruLite::Vector }
|
|
390
|
-
its(:size) { is_expected.to eq 7 }
|
|
391
|
-
it { is_expected.to eq klass.new(answer) }
|
|
392
|
-
end
|
|
393
|
-
|
|
394
|
-
context "subarray is present in arguments" do
|
|
395
|
-
subject { idx.is_values([1, 2])}
|
|
396
|
-
let(:answer) { [false, false, false, false, false, false, true] }
|
|
397
|
-
it { is_expected.to be_a DaruLite::Vector }
|
|
398
|
-
its(:size) { is_expected.to eq 7 }
|
|
399
|
-
it { is_expected.to eq klass.new(answer) }
|
|
400
|
-
end
|
|
401
|
-
end
|
|
402
|
-
|
|
403
|
-
end
|
|
404
|
-
|
|
405
|
-
describe '#delete_at' do
|
|
406
|
-
subject { index.delete_at(1) }
|
|
407
|
-
|
|
408
|
-
let(:index) { described_class.new([:a, :b, 1, 2]) }
|
|
409
|
-
|
|
410
|
-
it { is_expected.to eq(described_class.new([:a, 1, 2])) }
|
|
411
|
-
end
|
|
412
|
-
|
|
413
|
-
context '#to_df' do
|
|
414
|
-
let(:idx) do
|
|
415
|
-
DaruLite::Index.new(['speaker', 'mic', 'guitar', 'amp'],
|
|
416
|
-
name: 'instruments')
|
|
417
|
-
end
|
|
418
|
-
subject { idx.to_df }
|
|
419
|
-
|
|
420
|
-
it { is_expected.to eq DaruLite::DataFrame.new(
|
|
421
|
-
'instruments' => ['speaker', 'mic', 'guitar', 'amp']
|
|
422
|
-
)
|
|
423
|
-
}
|
|
424
|
-
end
|
|
425
|
-
|
|
426
|
-
context "#dup" do
|
|
427
|
-
let(:idx) do
|
|
428
|
-
DaruLite::Index.new(['speaker', 'mic', 'guitar', 'amp'],
|
|
429
|
-
name: 'instruments')
|
|
430
|
-
end
|
|
431
|
-
subject { idx.dup }
|
|
432
|
-
|
|
433
|
-
it { is_expected.to eq idx }
|
|
434
|
-
it 'have same names' do
|
|
435
|
-
expect(subject.name).to eq idx.name
|
|
436
|
-
end
|
|
437
|
-
end
|
|
438
|
-
end
|