danica 2.7.1 → 2.7.6
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/.circleci/config.yml +71 -0
- data/.gitignore +6 -1
- data/.rubocop.yml +9 -0
- data/.rubocop_todo.yml +123 -0
- data/Dockerfile +22 -0
- data/Gemfile +2 -1
- data/README.md +9 -1
- data/Rakefile +4 -0
- data/config/check_specs.yml +13 -0
- data/config/rubycritc.rb +12 -0
- data/config/yardstick.rb +13 -0
- data/config/yardstick.yml +33 -0
- data/danica.gemspec +16 -9
- data/docker-compose.yml +14 -9
- data/lib/danica.rb +3 -1
- data/lib/danica/base_operations.rb +15 -7
- data/lib/danica/builder.rb +2 -0
- data/lib/danica/common.rb +24 -16
- data/lib/danica/dsl.rb +15 -9
- data/lib/danica/dsl/builder.rb +40 -0
- data/lib/danica/equation.rb +3 -3
- data/lib/danica/equation/builder.rb +2 -0
- data/lib/danica/exception.rb +14 -2
- data/lib/danica/expressable.rb +20 -16
- data/lib/danica/expression.rb +4 -2
- data/lib/danica/expression/gauss.rb +5 -5
- data/lib/danica/formatted.rb +34 -11
- data/lib/danica/function.rb +5 -3
- data/lib/danica/function/name.rb +2 -0
- data/lib/danica/operator.rb +13 -9
- data/lib/danica/operator/addition.rb +4 -7
- data/lib/danica/operator/chained.rb +4 -8
- data/lib/danica/operator/cos.rb +2 -1
- data/lib/danica/operator/division.rb +3 -2
- data/lib/danica/operator/exponential.rb +2 -1
- data/lib/danica/operator/functional.rb +3 -2
- data/lib/danica/operator/multiplication.rb +5 -7
- data/lib/danica/operator/power.rb +4 -3
- data/lib/danica/operator/sin.rb +2 -1
- data/lib/danica/operator/squared_root.rb +2 -1
- data/lib/danica/variables_holder.rb +27 -24
- data/lib/danica/variables_holder/alias_builder.rb +4 -4
- data/lib/danica/variables_holder/calculator.rb +2 -0
- data/lib/danica/variables_holder/store.rb +3 -2
- data/lib/danica/variables_holder/variables_builder.rb +2 -1
- data/lib/danica/version.rb +3 -1
- data/lib/danica/wrapper.rb +17 -9
- data/lib/danica/wrapper/constant.rb +10 -14
- data/lib/danica/wrapper/container.rb +4 -4
- data/lib/danica/wrapper/group.rb +3 -2
- data/lib/danica/wrapper/negative.rb +3 -1
- data/lib/danica/wrapper/number.rb +6 -3
- data/lib/danica/wrapper/plus_minus.rb +3 -1
- data/lib/danica/wrapper/variable.rb +13 -8
- data/scripts/check_readme.sh +6 -0
- data/scripts/rubycritic.sh +10 -0
- data/spec/integration/global/danica/formatted_spec.rb +87 -0
- data/spec/integration/global/danica/operator/addition_spec.rb +32 -0
- data/spec/integration/global/danica/operator/multiplication_spec.rb +106 -0
- data/spec/integration/{power_spec.rb → global/danica/operator/power_spec.rb} +4 -2
- data/spec/integration/global/danica/wrapper/negative_spec.rb +56 -0
- data/spec/integration/{plus_minus_spec.rb → global/danica/wrapper/plus_minus_spec.rb} +5 -4
- data/spec/integration/readme/constant_spec.rb +4 -1
- data/spec/integration/readme/danica/formatted_spec.rb +24 -0
- data/spec/integration/readme/danica_spec.rb +20 -4
- data/spec/integration/readme/equation_spec.rb +4 -2
- data/spec/integration/readme/expression_spec.rb +11 -8
- data/spec/integration/readme/function_spec.rb +11 -7
- data/spec/integration/readme/number_spec.rb +9 -8
- data/spec/integration/readme/operator_spec.rb +3 -1
- data/spec/integration/readme/variables_spec.rb +8 -6
- data/spec/lib/danica/common_spec.rb +79 -8
- data/spec/lib/danica/dsl_spec.rb +21 -18
- data/spec/lib/danica/equation_spec.rb +10 -8
- data/spec/lib/danica/expressable_spec.rb +5 -2
- data/spec/lib/danica/expression/gauss_spec.rb +6 -3
- data/spec/lib/danica/expression_spec.rb +48 -26
- data/spec/lib/danica/formatted_spec.rb +57 -24
- data/spec/lib/danica/function/name_spec.rb +3 -1
- data/spec/lib/danica/function_spec.rb +14 -10
- data/spec/lib/danica/operator/addition_spec.rb +18 -21
- data/spec/lib/danica/operator/cos_spec.rb +9 -8
- data/spec/lib/danica/operator/division_spec.rb +18 -17
- data/spec/lib/danica/operator/exponential_spec.rb +9 -8
- data/spec/lib/danica/operator/multiplication_spec.rb +19 -20
- data/spec/lib/danica/operator/power_spec.rb +17 -16
- data/spec/lib/danica/operator/sin_spec.rb +9 -8
- data/spec/lib/danica/operator/squared_root_spec.rb +9 -8
- data/spec/lib/danica/operator_spec.rb +13 -4
- data/spec/lib/danica/variables_holder/store_spec.rb +19 -13
- data/spec/lib/danica/variables_holder_spec.rb +76 -59
- data/spec/lib/danica/wrapper/constant_spec.rb +9 -2
- data/spec/lib/danica/wrapper/group_spec.rb +4 -1
- data/spec/lib/danica/wrapper/negative_spec.rb +4 -1
- data/spec/lib/danica/wrapper/number_spec.rb +8 -3
- data/spec/lib/danica/wrapper/plus_minus_spec.rb +4 -1
- data/spec/lib/danica/wrapper/variable_spec.rb +6 -3
- data/spec/lib/danica/wrapper_spec.rb +22 -16
- data/spec/lib/danica_spec.rb +6 -5
- data/spec/spec_helper.rb +3 -2
- data/spec/support/models/expression/baskara.rb +3 -3
- data/spec/support/models/expression/parabole.rb +2 -0
- data/spec/support/models/expression/quadratic_sum.rb +3 -1
- data/spec/support/models/expression/spatial.rb +2 -1
- data/spec/support/models/function/my_function.rb +3 -1
- data/spec/support/models/function/parabole.rb +1 -1
- data/spec/support/models/function/quadratic_sum.rb +2 -0
- data/spec/support/models/function/spatial.rb +2 -0
- data/spec/support/models/operator/inverse.rb +3 -1
- data/spec/support/models/operator/my_operator.rb +3 -1
- data/spec/support/models/variables_holder/dummy.rb +3 -1
- data/spec/support/shared_contexts/common.rb +4 -2
- data/spec/support/shared_examples/base_operations.rb +7 -4
- data/spec/support/shared_examples/common.rb +3 -1
- data/spec/support/shared_examples/operator/chained.rb +12 -6
- data/spec/support/shared_examples/operator/dual_term.rb +9 -8
- data/spec/support/shared_examples/operator/single_input.rb +7 -2
- data/spec/support/shared_examples/variable.rb +8 -4
- metadata +115 -30
- data/spec/integration/addition_spec.rb +0 -28
- data/spec/integration/multiplication_spec.rb +0 -44
- data/spec/integration/negative_spec.rb +0 -25
@@ -1,16 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe Danica::VariablesHolder::Store do
|
5
|
+
describe Danica::VariablesHolder::Store do
|
6
|
+
subject do
|
7
|
+
described_class.new(default_variables_hash)
|
8
|
+
end
|
9
|
+
|
4
10
|
let(:default_variables_hash) do
|
5
11
|
{
|
6
12
|
x: Danica::Wrapper::Variable.new(name: :x),
|
7
|
-
y: Danica::Wrapper::Variable.new(
|
13
|
+
y: Danica::Wrapper::Variable.new(latex: '\y'),
|
8
14
|
z: Danica::Wrapper::Number.new(10)
|
9
15
|
}
|
10
16
|
end
|
11
|
-
subject do
|
12
|
-
described_class.new(default_variables_hash)
|
13
|
-
end
|
14
17
|
|
15
18
|
describe '#variables' do
|
16
19
|
context 'when instance has no variables defined' do
|
@@ -18,7 +21,7 @@ describe Danica::VariablesHolder::Store do
|
|
18
21
|
expect(subject.variables).not_to be_empty
|
19
22
|
end
|
20
23
|
|
21
|
-
#it_behaves_like 'an object that returns the default variables'
|
24
|
+
# it_behaves_like 'an object that returns the default variables'
|
22
25
|
end
|
23
26
|
|
24
27
|
context 'when some variables where defined' do
|
@@ -26,12 +29,17 @@ describe Danica::VariablesHolder::Store do
|
|
26
29
|
subject.containers_hash[:y] = Danica::Wrapper::Number.new(1)
|
27
30
|
end
|
28
31
|
|
29
|
-
|
30
|
-
|
32
|
+
let(:expected_variables) do
|
33
|
+
[
|
31
34
|
Danica::Wrapper::Variable.new(name: :x),
|
32
35
|
Danica::Wrapper::Number.new(1),
|
33
36
|
Danica::Wrapper::Number.new(10)
|
34
|
-
]
|
37
|
+
]
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns the default variables and the new set one' do
|
41
|
+
expect(subject.variables)
|
42
|
+
.to eq(expected_variables)
|
35
43
|
end
|
36
44
|
|
37
45
|
it 'does not change the default variables' do
|
@@ -44,7 +52,7 @@ describe Danica::VariablesHolder::Store do
|
|
44
52
|
|
45
53
|
describe '#variables_hash' do
|
46
54
|
context 'when instance has no variables defined' do
|
47
|
-
#it_behaves_like 'an object that returns the default variables hash'
|
55
|
+
# it_behaves_like 'an object that returns the default variables hash'
|
48
56
|
end
|
49
57
|
|
50
58
|
context 'when some variables where defined' do
|
@@ -64,9 +72,7 @@ describe Danica::VariablesHolder::Store do
|
|
64
72
|
|
65
73
|
describe '#containers' do
|
66
74
|
it 'is an array of Containers' do
|
67
|
-
subject.containers.
|
68
|
-
expect(container).to be_a(Danica::Wrapper::Container)
|
69
|
-
end
|
75
|
+
expect(subject.containers).to all(be_a(Danica::Wrapper::Container))
|
70
76
|
end
|
71
77
|
end
|
72
78
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
shared_examples 'an object that returns the default variables hash' do
|
@@ -11,12 +13,16 @@ shared_examples 'an object that returns the default variables hash' do
|
|
11
13
|
end
|
12
14
|
|
13
15
|
shared_examples 'an object that returns the default variables' do
|
14
|
-
|
15
|
-
|
16
|
+
let(:expected_variables) do
|
17
|
+
[
|
16
18
|
Danica::Wrapper::Variable.new(name: :x),
|
17
19
|
Danica::Wrapper::Variable.new(latex: '\y'),
|
18
20
|
Danica::Wrapper::Number.new(10)
|
19
|
-
]
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns the default variables hash' do
|
25
|
+
expect(subject.variables).to eq(expected_variables)
|
20
26
|
end
|
21
27
|
end
|
22
28
|
|
@@ -24,20 +30,20 @@ shared_examples 'an variable set that does not change the class variables' do
|
|
24
30
|
it 'does not change the the class variables' do
|
25
31
|
expect do
|
26
32
|
subject.variables = variables
|
27
|
-
end.not_to change
|
33
|
+
end.not_to change(clazz, :variables_hash)
|
28
34
|
end
|
29
35
|
end
|
30
36
|
|
31
37
|
shared_examples 'a class with mapped variables' do
|
32
38
|
context 'when initializing with an array' do
|
33
|
-
subject { clazz.new(1,2,3) }
|
39
|
+
subject { clazz.new(1, 2, 3) }
|
34
40
|
|
35
41
|
it 'initialize variables in order of declaration' do
|
36
|
-
expect(subject.variables_hash).to eq(
|
42
|
+
expect(subject.variables_hash).to eq(
|
37
43
|
x: Danica::Wrapper::Number.new(1),
|
38
44
|
y: Danica::Wrapper::Number.new(2),
|
39
45
|
z: Danica::Wrapper::Number.new(3)
|
40
|
-
|
46
|
+
)
|
41
47
|
end
|
42
48
|
end
|
43
49
|
|
@@ -45,55 +51,56 @@ shared_examples 'a class with mapped variables' do
|
|
45
51
|
subject { clazz.new(z: 1, y: 2) }
|
46
52
|
|
47
53
|
it 'initialize variables with the map given' do
|
48
|
-
expect(subject.variables_hash).to eq(
|
54
|
+
expect(subject.variables_hash).to eq(
|
49
55
|
x: Danica::Wrapper::Variable.new(name: :x),
|
50
56
|
y: Danica::Wrapper::Number.new(2),
|
51
57
|
z: Danica::Wrapper::Number.new(1)
|
52
|
-
|
58
|
+
)
|
53
59
|
end
|
54
60
|
end
|
55
61
|
|
56
62
|
context 'when initializing with hashes' do
|
57
63
|
subject do
|
58
64
|
clazz.new(
|
59
|
-
{name: :xis, value: 1},
|
60
|
-
{name: :yps, value: 2},
|
61
|
-
|
65
|
+
{ name: :xis, value: 1 },
|
66
|
+
{ name: :yps, value: 2 },
|
67
|
+
name: :zes, value: 3
|
62
68
|
)
|
63
69
|
end
|
64
70
|
|
65
71
|
it 'initialize variables with the maps given' do
|
66
|
-
expect(subject.variables_hash).to eq(
|
72
|
+
expect(subject.variables_hash).to eq(
|
67
73
|
x: Danica::Wrapper::Variable.new(name: :xis, value: 1),
|
68
74
|
y: Danica::Wrapper::Variable.new(name: :yps, value: 2),
|
69
75
|
z: Danica::Wrapper::Variable.new(name: :zes, value: 3)
|
70
|
-
|
76
|
+
)
|
71
77
|
end
|
72
78
|
end
|
73
79
|
|
74
80
|
context 'when initializing with array of hashes' do
|
75
81
|
subject do
|
76
82
|
clazz.new([
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
83
|
+
{ name: :xis, value: 1 },
|
84
|
+
{ name: :yps, value: 2 },
|
85
|
+
{ name: :zes, value: 3 }
|
86
|
+
])
|
81
87
|
end
|
82
88
|
|
83
89
|
it 'initialize variables with the maps given' do
|
84
|
-
expect(subject.variables_hash).to eq(
|
90
|
+
expect(subject.variables_hash).to eq(
|
85
91
|
x: Danica::Wrapper::Variable.new(name: :xis, value: 1),
|
86
92
|
y: Danica::Wrapper::Variable.new(name: :yps, value: 2),
|
87
93
|
z: Danica::Wrapper::Variable.new(name: :zes, value: 3)
|
88
|
-
|
94
|
+
)
|
89
95
|
end
|
90
96
|
end
|
91
97
|
end
|
92
98
|
|
93
99
|
describe Danica::VariablesHolder do
|
94
|
-
let(:clazz) { described_class::Dummy }
|
95
100
|
subject { clazz.new }
|
96
101
|
|
102
|
+
let(:clazz) { described_class::Dummy }
|
103
|
+
|
97
104
|
describe '#initialize' do
|
98
105
|
context 'when using a symbolized key definition' do
|
99
106
|
it_behaves_like 'a class with mapped variables'
|
@@ -101,18 +108,24 @@ describe Danica::VariablesHolder do
|
|
101
108
|
|
102
109
|
context 'when using a string key definition' do
|
103
110
|
let(:clazz) { described_class::DummyString }
|
111
|
+
|
104
112
|
it_behaves_like 'a class with mapped variables'
|
105
113
|
end
|
106
114
|
end
|
107
115
|
|
108
116
|
describe 'variables assignement' do
|
109
|
-
it 'creates setters
|
110
|
-
%i
|
111
|
-
expect(subject).to respond_to(var)
|
117
|
+
it 'creates setters for the variables' do
|
118
|
+
%i[x y z].each do |var|
|
112
119
|
expect(subject).to respond_to("#{var}=")
|
113
120
|
end
|
114
121
|
end
|
115
122
|
|
123
|
+
it 'creates getters for the variables' do
|
124
|
+
%i[x y z].each do |var|
|
125
|
+
expect(subject).to respond_to(var)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
116
129
|
it 'accepts variable assignment' do
|
117
130
|
expect do
|
118
131
|
subject.x = 1
|
@@ -134,14 +147,14 @@ describe Danica::VariablesHolder do
|
|
134
147
|
|
135
148
|
describe '.variables_names' do
|
136
149
|
it 'returns the list of variables pre configured' do
|
137
|
-
expect(clazz.variables_names).to eq(%i
|
150
|
+
expect(clazz.variables_names).to eq(%i[x y z])
|
138
151
|
end
|
139
152
|
|
140
153
|
context 'when variables are defined in super class' do
|
141
154
|
let(:clazz) { described_class::DummyChild }
|
142
155
|
|
143
156
|
it 'returns the list of variables of both classes merged' do
|
144
|
-
expect(clazz.variables_names).to eq(%i
|
157
|
+
expect(clazz.variables_names).to eq(%i[x y z k])
|
145
158
|
end
|
146
159
|
end
|
147
160
|
|
@@ -149,7 +162,7 @@ describe Danica::VariablesHolder do
|
|
149
162
|
let(:clazz) { described_class::DummyOverwrite }
|
150
163
|
|
151
164
|
it 'returns the list of variables of both classes merged' do
|
152
|
-
expect(clazz.variables_names).to eq(%i
|
165
|
+
expect(clazz.variables_names).to eq(%i[k z])
|
153
166
|
end
|
154
167
|
end
|
155
168
|
end
|
@@ -159,7 +172,7 @@ describe Danica::VariablesHolder do
|
|
159
172
|
let(:clazz) { described_class::DummyAlias }
|
160
173
|
|
161
174
|
it 'returns the list of variables of both classes merged' do
|
162
|
-
expect(clazz.variables_names).to eq(%i
|
175
|
+
expect(clazz.variables_names).to eq(%i[a y z])
|
163
176
|
end
|
164
177
|
|
165
178
|
context 'when original variable is set' do
|
@@ -175,9 +188,7 @@ describe Danica::VariablesHolder do
|
|
175
188
|
|
176
189
|
context 'when changing the new alias value' do
|
177
190
|
it do
|
178
|
-
expect
|
179
|
-
subject.a = 20
|
180
|
-
end.to change { subject.x.content }
|
191
|
+
expect { subject.a = 20 }.to(change { subject.x.content })
|
181
192
|
end
|
182
193
|
end
|
183
194
|
end
|
@@ -195,9 +206,8 @@ describe Danica::VariablesHolder do
|
|
195
206
|
|
196
207
|
context 'when changing the original variable value' do
|
197
208
|
it do
|
198
|
-
expect
|
199
|
-
subject.
|
200
|
-
end.to change { subject.a.content }
|
209
|
+
expect { subject.x = 20 }
|
210
|
+
.to(change { subject.a.content })
|
201
211
|
end
|
202
212
|
end
|
203
213
|
end
|
@@ -208,21 +218,25 @@ describe Danica::VariablesHolder do
|
|
208
218
|
context 'when changing the variables of the object' do
|
209
219
|
context 'when all the variables are set with value' do
|
210
220
|
let(:variables) { [1, 2, 3] }
|
221
|
+
|
211
222
|
it_behaves_like 'an variable set that does not change the class variables'
|
212
223
|
end
|
213
224
|
|
214
|
-
context 'setting the variables through a hash' do
|
225
|
+
context 'when setting the variables through a hash' do
|
215
226
|
let(:variables) { { x: 1, y: 2, z: 3 } }
|
227
|
+
|
216
228
|
it_behaves_like 'an variable set that does not change the class variables'
|
217
229
|
end
|
218
230
|
|
219
231
|
context 'when none of the variables are set with values' do
|
220
232
|
let(:variables) { [] }
|
233
|
+
|
221
234
|
it_behaves_like 'an variable set that does not change the class variables'
|
222
235
|
end
|
223
236
|
|
224
237
|
context 'when the variables are set through an empty hash' do
|
225
238
|
let(:variables) { {} }
|
239
|
+
|
226
240
|
it_behaves_like 'an variable set that does not change the class variables'
|
227
241
|
end
|
228
242
|
end
|
@@ -231,14 +245,16 @@ describe Danica::VariablesHolder do
|
|
231
245
|
before do
|
232
246
|
subject.variables = variables
|
233
247
|
end
|
248
|
+
|
234
249
|
let(:variables) { [1, 2, 3] }
|
235
250
|
|
236
251
|
it 'changes the values of the variables' do
|
237
252
|
expect(subject.x).to eq(Danica::Wrapper::Number.new(1))
|
238
253
|
end
|
239
254
|
|
240
|
-
context '
|
255
|
+
context 'when the array is empty' do
|
241
256
|
let(:variables) { [] }
|
257
|
+
|
242
258
|
it_behaves_like 'an object that returns the default variables hash'
|
243
259
|
end
|
244
260
|
end
|
@@ -254,8 +270,9 @@ describe Danica::VariablesHolder do
|
|
254
270
|
expect(subject.x).to eq(Danica::Wrapper::Number.new(1))
|
255
271
|
end
|
256
272
|
|
257
|
-
context '
|
273
|
+
context 'when the hash is empty' do
|
258
274
|
let(:variables) { {} }
|
275
|
+
|
259
276
|
it_behaves_like 'an object that returns the default variables hash'
|
260
277
|
end
|
261
278
|
end
|
@@ -277,10 +294,10 @@ describe Danica::VariablesHolder do
|
|
277
294
|
|
278
295
|
it 'returns the default variables and the new set one' do
|
279
296
|
expect(subject.variables).to eq([
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
297
|
+
Danica::Wrapper::Variable.new(name: :x),
|
298
|
+
Danica::Wrapper::Number.new(1),
|
299
|
+
Danica::Wrapper::Number.new(10)
|
300
|
+
])
|
284
301
|
end
|
285
302
|
|
286
303
|
it 'does not change the class variables' do
|
@@ -314,7 +331,7 @@ describe Danica::VariablesHolder do
|
|
314
331
|
describe '#variables_value_hash' do
|
315
332
|
context 'when instance has no variables defined' do
|
316
333
|
it 'returns the default value' do
|
317
|
-
expect(subject.variables_value_hash).to eq(
|
334
|
+
expect(subject.variables_value_hash).to eq(x: nil, y: nil, z: 10)
|
318
335
|
end
|
319
336
|
end
|
320
337
|
|
@@ -324,7 +341,7 @@ describe Danica::VariablesHolder do
|
|
324
341
|
end
|
325
342
|
|
326
343
|
it 'returns the values' do
|
327
|
-
expect(subject.variables_value_hash).to eq(
|
344
|
+
expect(subject.variables_value_hash).to eq(x: nil, y: 1, z: 10)
|
328
345
|
end
|
329
346
|
end
|
330
347
|
end
|
@@ -338,24 +355,24 @@ describe Danica::VariablesHolder do
|
|
338
355
|
let(:containers) { subject.containers }
|
339
356
|
|
340
357
|
it 'changes the variables in the containers' do
|
341
|
-
expect
|
342
|
-
|
343
|
-
end.to change { containers.map(&:content) }
|
358
|
+
expect { subject.x = 2 }
|
359
|
+
.to(change { containers.map(&:content) })
|
344
360
|
end
|
345
361
|
end
|
346
362
|
end
|
347
363
|
|
348
364
|
describe '#extract_variables' do
|
349
365
|
let(:clazz) { described_class::DummyChild }
|
366
|
+
|
350
367
|
context 'when holder has straight variables' do
|
351
368
|
it 'returns the variables hash' do
|
352
|
-
expect(subject.extract_variables).to eq(subject.containers.as_hash([
|
369
|
+
expect(subject.extract_variables).to eq(subject.containers.as_hash(%i[x y zeta k]))
|
353
370
|
end
|
354
371
|
|
355
|
-
context '
|
372
|
+
context 'when one of them is a number' do
|
356
373
|
let(:clazz) { described_class::Dummy }
|
357
374
|
let(:expected) do
|
358
|
-
subject.containers_hash.reject { |k,
|
375
|
+
subject.containers_hash.reject { |k, _v| k == :z }
|
359
376
|
end
|
360
377
|
|
361
378
|
it 'returns only the variables' do
|
@@ -368,7 +385,7 @@ describe Danica::VariablesHolder do
|
|
368
385
|
let(:subject) { clazz.new(x: :xis, y: :lambda, z: :zeta, k: :key) }
|
369
386
|
|
370
387
|
it 'returns the names as keys' do
|
371
|
-
expect(subject.extract_variables.keys).to eq(%i
|
388
|
+
expect(subject.extract_variables.keys).to eq(%i[xis lambda zeta key])
|
372
389
|
end
|
373
390
|
end
|
374
391
|
|
@@ -378,8 +395,8 @@ describe Danica::VariablesHolder do
|
|
378
395
|
clazz.new(z: inner)
|
379
396
|
end
|
380
397
|
let(:expected) do
|
381
|
-
subject.containers_hash.reject { |k,
|
382
|
-
|
398
|
+
subject.containers_hash.reject { |k, _v| k == :z }
|
399
|
+
.merge(inner.containers_hash)
|
383
400
|
end
|
384
401
|
|
385
402
|
it 'returns the ineer variables of the inner holder as well' do
|
@@ -389,7 +406,7 @@ describe Danica::VariablesHolder do
|
|
389
406
|
context 'when inner holder has the same variables' do
|
390
407
|
let(:inner) { clazz.new }
|
391
408
|
let(:expected) do
|
392
|
-
inner.containers.as_hash([
|
409
|
+
inner.containers.as_hash(%i[x y zeta k])
|
393
410
|
end
|
394
411
|
|
395
412
|
it 'merges them together in favor of the inner variables' do
|
@@ -406,7 +423,7 @@ describe Danica::VariablesHolder do
|
|
406
423
|
expect { subject.calculate }.to raise_error(Danica::Exception::NotDefined)
|
407
424
|
end
|
408
425
|
|
409
|
-
context '
|
426
|
+
context 'when it does not complete the values' do
|
410
427
|
it do
|
411
428
|
expect { subject.calculate(2) }.to raise_error(Danica::Exception::NotDefined)
|
412
429
|
end
|
@@ -414,7 +431,7 @@ describe Danica::VariablesHolder do
|
|
414
431
|
end
|
415
432
|
|
416
433
|
context 'when passing the values' do
|
417
|
-
context '
|
434
|
+
context 'when values are a list' do
|
418
435
|
it do
|
419
436
|
expect { subject.calculate(2, 4) }.not_to raise_error
|
420
437
|
end
|
@@ -423,7 +440,7 @@ describe Danica::VariablesHolder do
|
|
423
440
|
expect(subject.calculate(2, 4)).to eq(26)
|
424
441
|
end
|
425
442
|
|
426
|
-
context '
|
443
|
+
context 'when replacing all the values' do
|
427
444
|
it do
|
428
445
|
expect { subject.calculate(2, 4, 5) }.not_to raise_error
|
429
446
|
end
|
@@ -434,8 +451,8 @@ describe Danica::VariablesHolder do
|
|
434
451
|
end
|
435
452
|
end
|
436
453
|
|
437
|
-
context '
|
438
|
-
context '
|
454
|
+
context 'when the values are hash' do
|
455
|
+
context 'when it completes the values' do
|
439
456
|
it do
|
440
457
|
expect { subject.calculate(x: 2, y: 4) }.not_to raise_error
|
441
458
|
end
|
@@ -445,7 +462,7 @@ describe Danica::VariablesHolder do
|
|
445
462
|
end
|
446
463
|
end
|
447
464
|
|
448
|
-
context '
|
465
|
+
context 'when it does not complete the values' do
|
449
466
|
it do
|
450
467
|
expect { subject.calculate(x: 2, z: 4) }.to raise_error(Danica::Exception::NotDefined)
|
451
468
|
end
|