daru_lite 0.3.4 → 0.3.5
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 +60 -0
- data/README.md +1 -1
- data/lib/daru_lite/category.rb +1 -1
- data/lib/daru_lite/date_time/index.rb +2 -2
- data/lib/daru_lite/maths/statistics/vector.rb +1 -1
- data/lib/daru_lite/version.rb +1 -1
- data/lib/daru_lite.rb +1 -0
- metadata +54 -284
- 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/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
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
describe DaruLite::Formatters::Table do
|
|
2
|
-
let(:options) { {} }
|
|
3
|
-
subject {
|
|
4
|
-
DaruLite::Formatters::Table
|
|
5
|
-
.format(data, options.merge(headers: headers, row_headers: row_headers))
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
let(:data) { [[1,2,3], [4,5,6], [7,8,9]] }
|
|
9
|
-
let(:headers) { [:col1, :col2, :col3] }
|
|
10
|
-
let(:row_headers) { [:row1, :row2, :row3] }
|
|
11
|
-
|
|
12
|
-
context 'simple table' do
|
|
13
|
-
it { is_expected.to eq %Q{
|
|
14
|
-
| col1 col2 col3
|
|
15
|
-
| row1 1 2 3
|
|
16
|
-
| row2 4 5 6
|
|
17
|
-
| row3 7 8 9
|
|
18
|
-
}.unindent}
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
context 'with nils' do
|
|
22
|
-
let(:data) { [[1,nil,3], [4,5,nil], [7,8,9]] }
|
|
23
|
-
let(:headers) { [:col1, :col2, nil] }
|
|
24
|
-
let(:row_headers) { [:row1, nil, :row3] }
|
|
25
|
-
|
|
26
|
-
it { is_expected.to eq %Q{
|
|
27
|
-
| col1 col2 |
|
|
28
|
-
| row1 1 nil 3|
|
|
29
|
-
| 4 5 nil|
|
|
30
|
-
| row3 7 8 9|
|
|
31
|
-
}.unindent}
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
context 'with multivalue row headers' do
|
|
35
|
-
let(:row_headers) { [[:row,1], [:row,2], [:row,3]] }
|
|
36
|
-
it { is_expected.to eq %Q{
|
|
37
|
-
| col1 col2 col3
|
|
38
|
-
| row 1 1 2 3
|
|
39
|
-
| row 2 4 5 6
|
|
40
|
-
| row 3 7 8 9
|
|
41
|
-
}.unindent}
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
context 'with multivalue column headers' do
|
|
45
|
-
let(:headers) { [[:col,1], [:col,2], [:col,3]] }
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
context 'rows only' do
|
|
49
|
-
let(:data) { [] }
|
|
50
|
-
let(:headers) { nil }
|
|
51
|
-
it { is_expected.to eq %Q{
|
|
52
|
-
| row1
|
|
53
|
-
| row2
|
|
54
|
-
| row3
|
|
55
|
-
}.unindent}
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
context 'columns only' do
|
|
59
|
-
let(:data) { [] }
|
|
60
|
-
let(:row_headers) { nil }
|
|
61
|
-
it { is_expected.to eq %Q{
|
|
62
|
-
| col1 col2 col3
|
|
63
|
-
}.unindent}
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
context 'wide values' do
|
|
67
|
-
let(:options) { {spacing: 2} }
|
|
68
|
-
|
|
69
|
-
it { is_expected.to eq %Q{
|
|
70
|
-
| co co co
|
|
71
|
-
| ro 1 2 3
|
|
72
|
-
| ro 4 5 6
|
|
73
|
-
| ro 7 8 9
|
|
74
|
-
}.unindent}
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
context 'with empty data' do
|
|
78
|
-
let(:data) { [] }
|
|
79
|
-
let(:headers) { [] }
|
|
80
|
-
let(:row_headers) { [] }
|
|
81
|
-
|
|
82
|
-
it { is_expected.to eq '' }
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
context '<more> threshold' do
|
|
87
|
-
let(:options) { {threshold: threshold} }
|
|
88
|
-
context 'lower than data size' do
|
|
89
|
-
let(:threshold) { 2 }
|
|
90
|
-
it { is_expected.to eq %Q{
|
|
91
|
-
| col1 col2 col3
|
|
92
|
-
| row1 1 2 3
|
|
93
|
-
| row2 4 5 6
|
|
94
|
-
| ... ... ... ...
|
|
95
|
-
}.unindent}
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
context 'greater than data size' do
|
|
99
|
-
let(:threshold) { 5 }
|
|
100
|
-
it { is_expected.to eq %Q{
|
|
101
|
-
| col1 col2 col3
|
|
102
|
-
| row1 1 2 3
|
|
103
|
-
| row2 4 5 6
|
|
104
|
-
| row3 7 8 9
|
|
105
|
-
}.unindent}
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
context 'no row and column headers' do
|
|
110
|
-
let(:headers) { nil }
|
|
111
|
-
let(:row_headers) { nil }
|
|
112
|
-
it { is_expected.to eq %Q{
|
|
113
|
-
| 1 2 3
|
|
114
|
-
| 4 5 6
|
|
115
|
-
| 7 8 9
|
|
116
|
-
}.unindent }
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
context 'row headers only' do
|
|
120
|
-
let(:headers) { nil }
|
|
121
|
-
it { is_expected.to eq %Q{
|
|
122
|
-
| row1 1 2 3
|
|
123
|
-
| row2 4 5 6
|
|
124
|
-
| row3 7 8 9
|
|
125
|
-
}.unindent }
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
context 'column headers only' do
|
|
129
|
-
let(:row_headers) { nil }
|
|
130
|
-
it { is_expected.to eq %Q{
|
|
131
|
-
| col1 col2 col3
|
|
132
|
-
| 1 2 3
|
|
133
|
-
| 4 5 6
|
|
134
|
-
| 7 8 9
|
|
135
|
-
}.unindent }
|
|
136
|
-
end
|
|
137
|
-
end
|
data/spec/helpers_spec.rb
DELETED
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
require 'spec_helper.rb'
|
|
2
|
-
|
|
3
|
-
describe DaruLite::CategoricalIndex do
|
|
4
|
-
let(:index) { described_class.new(keys) }
|
|
5
|
-
let(:keys) { [:a, :b, :a, :a, :c] }
|
|
6
|
-
|
|
7
|
-
describe "#to_a" do
|
|
8
|
-
subject { index.to_a }
|
|
9
|
-
|
|
10
|
-
it { is_expected.to eq(keys) }
|
|
11
|
-
|
|
12
|
-
it 'the returns array is not a variable of the index' do
|
|
13
|
-
expect { subject << 'four' }.not_to change { index.to_a }
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
context "#pos" do
|
|
18
|
-
context "when the category is non-numeric" do
|
|
19
|
-
context "single category" do
|
|
20
|
-
subject { index.pos :a }
|
|
21
|
-
|
|
22
|
-
it { is_expected.to eq [0, 2, 3] }
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
context "multiple categories" do
|
|
26
|
-
subject { index.pos :a, :c }
|
|
27
|
-
|
|
28
|
-
it { is_expected.to eq [0, 2, 3, 4] }
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
context "invalid category" do
|
|
32
|
-
it { expect { index.pos :e }.to raise_error IndexError }
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
context "label range argument" do
|
|
36
|
-
it { expect { index.pos :a..:c }.to raise_error ArgumentError }
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
context "positional (integer) range argument" do
|
|
40
|
-
it { expect(index.pos(0..2)).to eq [0, 1, 2] }
|
|
41
|
-
|
|
42
|
-
context "when the range extends past the end" do
|
|
43
|
-
it { expect(index.pos(0..99)).to eq [0, 1, 2, 3, 4] }
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
context "when a category is itself a Range" do
|
|
48
|
-
let(:index) { described_class.new [(1..2), (3..4), (1..2)] }
|
|
49
|
-
|
|
50
|
-
it { expect(index.pos(1..2)).to eq [0, 2] }
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
context "positional index" do
|
|
54
|
-
it { expect(index.pos 0).to eq 0 }
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
context "invalid positional index" do
|
|
58
|
-
it { expect { index.pos 5 }.to raise_error IndexError }
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
context "multiple positional indexes" do
|
|
62
|
-
subject { index.pos 0, 1, 2 }
|
|
63
|
-
|
|
64
|
-
it { is_expected.to be_a Array }
|
|
65
|
-
its(:size) { is_expected.to eq 3 }
|
|
66
|
-
it { is_expected.to eq [0, 1, 2] }
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
context "when the category is numeric" do
|
|
71
|
-
let(:idx) { described_class.new [0, 1, 0, 0, 2] }
|
|
72
|
-
|
|
73
|
-
context "first preference to category" do
|
|
74
|
-
subject { idx.pos 0 }
|
|
75
|
-
|
|
76
|
-
it { is_expected.to be_a Array }
|
|
77
|
-
its(:size) { is_expected.to eq 3 }
|
|
78
|
-
it { is_expected.to eq [0, 2, 3] }
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
context "second preference to positional index" do
|
|
82
|
-
subject { idx.pos 3 }
|
|
83
|
-
|
|
84
|
-
it { is_expected.to eq 3 }
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
describe "#[]" do
|
|
90
|
-
context "when the category occurs once" do
|
|
91
|
-
subject { index[:b] }
|
|
92
|
-
|
|
93
|
-
it { is_expected.to eq 1 }
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
context "when the category occurs multiple times" do
|
|
97
|
-
subject { index[:a] }
|
|
98
|
-
|
|
99
|
-
it { is_expected.to eq [0, 2, 3] }
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
context "when given a positional index" do
|
|
103
|
-
subject { index[0] }
|
|
104
|
-
|
|
105
|
-
it { is_expected.to eq 0 }
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
context "when given multiple categories" do
|
|
109
|
-
subject { index[:a, :c] }
|
|
110
|
-
|
|
111
|
-
it { is_expected.to eq [0, 2, 3, 4] }
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
context "when the category is absent" do
|
|
115
|
-
subject { index[:z] }
|
|
116
|
-
|
|
117
|
-
it { is_expected.to be_nil }
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
context "when given a label range" do
|
|
121
|
-
it { expect { index[:a..:c] }.to raise_error ArgumentError }
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
context "when given a positional (integer) range" do
|
|
125
|
-
subject { index[0..2] }
|
|
126
|
-
|
|
127
|
-
it { is_expected.to eq [0, 1, 2] }
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
context "when a category is itself a Range" do
|
|
131
|
-
let(:index) { described_class.new [(1..2), (3..4), (1..2)] }
|
|
132
|
-
|
|
133
|
-
it { expect(index[1..2]).to eq [0, 2] }
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
describe "#key" do
|
|
138
|
-
context "when given a position" do
|
|
139
|
-
subject { index.key(1) }
|
|
140
|
-
|
|
141
|
-
it { is_expected.to eq :b }
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
context "when the position holds a duplicated category" do
|
|
145
|
-
subject { index.key(3) }
|
|
146
|
-
|
|
147
|
-
it { is_expected.to eq :a }
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
context "when the position is out of range" do
|
|
151
|
-
subject { index.key(99) }
|
|
152
|
-
|
|
153
|
-
it { is_expected.to be_nil }
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
context "when given a non-numeric value" do
|
|
157
|
-
subject { index.key(:a) }
|
|
158
|
-
|
|
159
|
-
it { is_expected.to be_nil }
|
|
160
|
-
end
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
describe "#slice" do
|
|
164
|
-
it { expect { index.slice(:a, :c) }.to raise_error ArgumentError }
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
describe "#subset_slice" do
|
|
168
|
-
it { expect { index.subset_slice(:a, :c) }.to raise_error ArgumentError }
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
context "#subset" do
|
|
172
|
-
let(:idx) { described_class.new [:a, 1, :a, 1, :c] }
|
|
173
|
-
|
|
174
|
-
context "single index" do
|
|
175
|
-
context "multiple instances" do
|
|
176
|
-
subject { idx.subset :a }
|
|
177
|
-
|
|
178
|
-
it { is_expected.to be_a described_class }
|
|
179
|
-
its(:size) { is_expected.to eq 2 }
|
|
180
|
-
its(:to_a) { is_expected.to eq [:a, :a] }
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
context "multiple indexes" do
|
|
185
|
-
subject { idx.subset :a, 1 }
|
|
186
|
-
|
|
187
|
-
it { is_expected.to be_a described_class }
|
|
188
|
-
its(:size) { is_expected.to eq 4 }
|
|
189
|
-
its(:to_a) { is_expected.to eq [:a, 1, :a, 1] }
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
context "multiple positional indexes" do
|
|
193
|
-
subject { idx.subset 0, 2 }
|
|
194
|
-
|
|
195
|
-
it { is_expected.to be_a described_class }
|
|
196
|
-
its(:size) { is_expected.to eq 2 }
|
|
197
|
-
its(:to_a) { is_expected.to eq [:a, :a] }
|
|
198
|
-
end
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
context "#at" do
|
|
202
|
-
let(:idx) { described_class.new [:a, :a, :a, 1, :c] }
|
|
203
|
-
|
|
204
|
-
context "single position" do
|
|
205
|
-
it { expect(idx.at 1).to eq :a }
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
context "multiple positions" do
|
|
209
|
-
subject { idx.at 0, 2, 3 }
|
|
210
|
-
|
|
211
|
-
it { is_expected.to be_a described_class }
|
|
212
|
-
its(:size) { is_expected.to eq 3 }
|
|
213
|
-
its(:to_a) { is_expected.to eq [:a, :a, 1] }
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
context "range" do
|
|
217
|
-
subject { idx.at 2..3 }
|
|
218
|
-
|
|
219
|
-
it { is_expected.to be_a described_class }
|
|
220
|
-
its(:size) { is_expected.to eq 2 }
|
|
221
|
-
its(:to_a) { is_expected.to eq [:a, 1] }
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
context "range with negative integers" do
|
|
225
|
-
subject { idx.at 2..-2 }
|
|
226
|
-
|
|
227
|
-
it { is_expected.to be_a described_class }
|
|
228
|
-
its(:size) { is_expected.to eq 2 }
|
|
229
|
-
its(:to_a) { is_expected.to eq [:a, 1] }
|
|
230
|
-
end
|
|
231
|
-
|
|
232
|
-
context "rangle with single element" do
|
|
233
|
-
subject { idx.at 2..2 }
|
|
234
|
-
|
|
235
|
-
it { is_expected.to be_a described_class }
|
|
236
|
-
its(:size) { is_expected.to eq 1 }
|
|
237
|
-
its(:to_a) { is_expected.to eq [:a] }
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
context "invalid position" do
|
|
241
|
-
it { expect { idx.at 5 }.to raise_error IndexError }
|
|
242
|
-
end
|
|
243
|
-
|
|
244
|
-
context "invalid positions" do
|
|
245
|
-
it { expect { idx.at 2, 5 }.to raise_error IndexError }
|
|
246
|
-
end
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
context "#add" do
|
|
250
|
-
let(:idx) { described_class.new [:a, 1, :a, 1] }
|
|
251
|
-
|
|
252
|
-
context "single index" do
|
|
253
|
-
subject { idx.add :c }
|
|
254
|
-
|
|
255
|
-
its(:to_a) { is_expected.to eq [:a, 1, :a, 1, :c] }
|
|
256
|
-
its(:categories) { is_expected.to eq [:a, 1, :c] }
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
context "multiple indexes" do
|
|
260
|
-
subject { idx.add :c, :d }
|
|
261
|
-
|
|
262
|
-
its(:to_a) { is_expected.to eq [:a, 1, :a, 1, :c, :d] }
|
|
263
|
-
its(:categories) { is_expected.to eq [:a, 1, :c, :d] }
|
|
264
|
-
end
|
|
265
|
-
end
|
|
266
|
-
|
|
267
|
-
context "#valid?" do
|
|
268
|
-
let(:idx) { described_class.new [:a, 1, :a, 1] }
|
|
269
|
-
|
|
270
|
-
context "single index" do
|
|
271
|
-
it { expect(idx.valid? :a).to eq true }
|
|
272
|
-
it { expect(idx.valid? 2).to eq true }
|
|
273
|
-
it { expect(idx.valid? 4).to eq false }
|
|
274
|
-
end
|
|
275
|
-
|
|
276
|
-
context "multiple indexes" do
|
|
277
|
-
it { expect(idx.valid? :a, 1).to eq true }
|
|
278
|
-
it { expect(idx.valid? :a, 1, 5).to eq false }
|
|
279
|
-
end
|
|
280
|
-
end
|
|
281
|
-
|
|
282
|
-
describe '#delete_at' do
|
|
283
|
-
subject { index.delete_at(3) }
|
|
284
|
-
|
|
285
|
-
let(:index) { described_class.new([:a, 1, :a, 1, 'c']) }
|
|
286
|
-
|
|
287
|
-
it { is_expected.to eq(described_class.new([:a, 1, :a, 'c'])) }
|
|
288
|
-
end
|
|
289
|
-
end
|