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
data/spec/lib/danica/dsl_spec.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
|
5
|
+
shared_examples 'a class with alias to a clazz' do |aliaz, clazz, *variables|
|
4
6
|
it do
|
5
7
|
expect(subject).to respond_to(aliaz)
|
6
8
|
end
|
@@ -10,29 +12,29 @@ shared_context 'a class with alias to a clazz' do |aliaz, clazz, *variables|
|
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
13
|
-
|
15
|
+
shared_examples 'a class with mapped dsl' do
|
14
16
|
{
|
15
|
-
addition:
|
16
|
-
sum:
|
17
|
+
addition: Danica::Operator::Addition,
|
18
|
+
sum: Danica::Operator::Addition,
|
17
19
|
multiplication: Danica::Operator::Multiplication,
|
18
|
-
product:
|
19
|
-
division:
|
20
|
-
power:
|
20
|
+
product: Danica::Operator::Multiplication,
|
21
|
+
division: Danica::Operator::Division,
|
22
|
+
power: Danica::Operator::Power
|
21
23
|
}.each do |aliaz, clazz|
|
22
24
|
it_behaves_like 'a class with alias to a clazz', aliaz, clazz, 2, 3
|
23
25
|
end
|
24
26
|
{
|
25
|
-
squared_root:
|
26
|
-
sqrt:
|
27
|
-
exponential:
|
28
|
-
sin:
|
29
|
-
cos:
|
30
|
-
group:
|
31
|
-
negative:
|
32
|
-
number:
|
33
|
-
num:
|
34
|
-
plus_minus:
|
35
|
-
constant:
|
27
|
+
squared_root: Danica::Operator::SquaredRoot,
|
28
|
+
sqrt: Danica::Operator::SquaredRoot,
|
29
|
+
exponential: Danica::Operator::Exponential,
|
30
|
+
sin: Danica::Operator::Sin,
|
31
|
+
cos: Danica::Operator::Cos,
|
32
|
+
group: Danica::Wrapper::Group,
|
33
|
+
negative: Danica::Wrapper::Negative,
|
34
|
+
number: Danica::Wrapper::Number,
|
35
|
+
num: Danica::Wrapper::Number,
|
36
|
+
plus_minus: Danica::Wrapper::PlusMinus,
|
37
|
+
constant: Danica::Wrapper::Constant
|
36
38
|
}.each do |aliaz, clazz|
|
37
39
|
it_behaves_like 'a class with alias to a clazz', aliaz, clazz, 9
|
38
40
|
end
|
@@ -44,6 +46,7 @@ describe Danica::DSL do
|
|
44
46
|
end
|
45
47
|
|
46
48
|
let(:subject) { described_class::Dummy.new }
|
49
|
+
|
47
50
|
it_behaves_like 'a class with mapped dsl'
|
48
51
|
|
49
52
|
describe '.build' do
|
@@ -1,22 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Danica::Equation do
|
6
|
+
subject do
|
7
|
+
clazz.new
|
8
|
+
end
|
9
|
+
|
4
10
|
let(:clazz) do
|
5
11
|
described_class.build(:x, :y) do
|
6
12
|
left { y }
|
7
|
-
right { x
|
13
|
+
right { x**2 }
|
8
14
|
end
|
9
15
|
end
|
10
16
|
|
11
|
-
subject do
|
12
|
-
clazz.new
|
13
|
-
end
|
14
|
-
|
15
17
|
it_behaves_like 'an object that respond to basic_methods'
|
16
18
|
|
17
19
|
describe '.build' do
|
18
20
|
it 'returns a class that is also an equation' do
|
19
|
-
expect(subject).to be_a(
|
21
|
+
expect(subject).to be_a(described_class)
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
@@ -24,12 +26,12 @@ describe Danica::Equation do
|
|
24
26
|
subject do
|
25
27
|
described_class.create(:x, :y) do
|
26
28
|
left { y }
|
27
|
-
right { x
|
29
|
+
right { x**2 }
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
33
|
it 'returns a class that is also an equation' do
|
32
|
-
expect(subject).to be_a(
|
34
|
+
expect(subject).to be_a(described_class)
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
class Danica::Expressable::Dummy
|
@@ -9,12 +11,13 @@ class Danica::Expressable::Dummy
|
|
9
11
|
end
|
10
12
|
|
11
13
|
describe Danica::Expressable do
|
12
|
-
let(:clazz) { described_class::Dummy }
|
13
14
|
subject do
|
14
15
|
clazz.create(:x) { x }
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
|
+
let(:clazz) { described_class::Dummy }
|
19
|
+
|
20
|
+
it_behaves_like 'an object that respond to basic_methods', ignore: %i[valued? container? is_grouped? priority]
|
18
21
|
|
19
22
|
describe '.build' do
|
20
23
|
it 'responds to build' do
|
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Danica::Expression::Gauss do
|
6
|
+
subject { described_class::Gauss.new(variables) }
|
7
|
+
|
4
8
|
let(:variables) do
|
5
9
|
{
|
6
10
|
x: :x,
|
@@ -9,12 +13,11 @@ describe Danica::Expression::Gauss do
|
|
9
13
|
}
|
10
14
|
end
|
11
15
|
|
12
|
-
subject { described_class::Gauss.new(variables) }
|
13
16
|
it_behaves_like 'an object that respond to basic_methods'
|
14
17
|
|
15
18
|
describe '#to_tex' do
|
16
19
|
context 'when creating the spatial operator for constantly accelerated movement' do
|
17
|
-
let(:expected) { '\frac{1}{\theta \cdot \sqrt{2 \cdot \pi}} \cdot e^{-\frac{\left(x -u\right)^{2}}{2 \cdot \theta^{2}}}'
|
20
|
+
let(:expected) { '\frac{1}{\theta \cdot \sqrt{2 \cdot \pi}} \cdot e^{-\frac{\left(x -u\right)^{2}}{2 \cdot \theta^{2}}}' }
|
18
21
|
|
19
22
|
it 'return the latex format CAM' do
|
20
23
|
expect(subject.to_tex).to eq(expected)
|
@@ -36,7 +39,7 @@ describe Danica::Expression::Gauss do
|
|
36
39
|
subject { described_class::Gauss.new }
|
37
40
|
|
38
41
|
describe '#to_tex' do
|
39
|
-
let(:expected) { '\frac{1}{\sigma \cdot \sqrt{2 \cdot \pi}} \cdot e^{-\frac{\left(x -\mu\right)^{2}}{2 \cdot \sigma^{2}}}'
|
42
|
+
let(:expected) { '\frac{1}{\sigma \cdot \sqrt{2 \cdot \pi}} \cdot e^{-\frac{\left(x -\mu\right)^{2}}{2 \cdot \sigma^{2}}}' }
|
40
43
|
|
41
44
|
it 'rely on default variables definition' do
|
42
45
|
expect(subject.to_tex).to eq(expected)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
shared_examples 'a generically generated expression' do
|
@@ -25,18 +27,20 @@ shared_examples 'a generically generated expression' do
|
|
25
27
|
end
|
26
28
|
|
27
29
|
describe Danica::Expression do
|
28
|
-
|
30
|
+
subject { expression }
|
31
|
+
|
32
|
+
let(:variables) { %i[x y] }
|
29
33
|
let(:expression_class) do
|
30
34
|
described_class.build(*variables) do
|
31
35
|
Danica::Operator::Power.new(x, y)
|
32
36
|
end
|
33
37
|
end
|
34
|
-
subject { expression }
|
35
38
|
|
36
39
|
describe '.build' do
|
37
40
|
let(:expression) do
|
38
41
|
expression_class.new
|
39
42
|
end
|
43
|
+
|
40
44
|
it_behaves_like 'an object with basic operation'
|
41
45
|
it_behaves_like 'an object that respond to basic_methods'
|
42
46
|
it_behaves_like 'a generically generated expression'
|
@@ -84,7 +88,7 @@ describe Danica::Expression do
|
|
84
88
|
it_behaves_like 'an object that respond to basic_methods'
|
85
89
|
|
86
90
|
it 'has the defined variables on class definition' do
|
87
|
-
expect(expression_class.variables_names).to eq([
|
91
|
+
expect(expression_class.variables_names).to eq(%i[x y])
|
88
92
|
end
|
89
93
|
|
90
94
|
it 'has the defined variables' do
|
@@ -114,12 +118,15 @@ describe Danica::Expression do
|
|
114
118
|
Danica::Operator::Power.new(x, y)
|
115
119
|
end
|
116
120
|
end
|
121
|
+
|
117
122
|
it_behaves_like 'an object with basic operation'
|
118
123
|
it_behaves_like 'an object that respond to basic_methods'
|
119
124
|
it_behaves_like 'a generically generated expression'
|
120
125
|
end
|
121
126
|
|
122
127
|
describe 'spatial' do
|
128
|
+
subject { described_class::Spatial.new(variables) }
|
129
|
+
|
123
130
|
let(:variables) do
|
124
131
|
{
|
125
132
|
time: :t,
|
@@ -129,13 +136,12 @@ describe Danica::Expression do
|
|
129
136
|
}
|
130
137
|
end
|
131
138
|
|
132
|
-
subject { described_class::Spatial.new(variables) }
|
133
139
|
it_behaves_like 'an object with basic operation'
|
134
140
|
it_behaves_like 'an object that respond to basic_methods'
|
135
141
|
|
136
142
|
describe '#to_tex' do
|
137
143
|
context 'when creating the spatial operator for constantly accelerated movement' do
|
138
|
-
let(:expected) { 'S_0 + V_0 \cdot t + \frac{a \cdot t^{2}}{2}'
|
144
|
+
let(:expected) { 'S_0 + V_0 \cdot t + \frac{a \cdot t^{2}}{2}' }
|
139
145
|
|
140
146
|
it 'return the latex format CAM' do
|
141
147
|
expect(subject.to_tex).to eq(expected)
|
@@ -145,7 +151,7 @@ describe Danica::Expression do
|
|
145
151
|
|
146
152
|
describe '#to_gnu' do
|
147
153
|
context 'when creating the spatial operator for constantly accelerated movement' do
|
148
|
-
let(:expected) { 'S0 + V0 * t + (a * t**(2))/(2)'
|
154
|
+
let(:expected) { 'S0 + V0 * t + (a * t**(2))/(2)' }
|
149
155
|
|
150
156
|
it 'return the latex format CAM' do
|
151
157
|
expect(subject.to_gnu).to eq(expected)
|
@@ -158,13 +164,14 @@ describe Danica::Expression do
|
|
158
164
|
{
|
159
165
|
time: Danica::Wrapper::Variable.new(name: :t),
|
160
166
|
acceleration: Danica::Wrapper::Variable.new(name: 'a'),
|
161
|
-
initial_space: Danica::Wrapper::Variable.new(
|
162
|
-
initial_velocity: Danica::Wrapper::Variable.new(
|
167
|
+
initial_space: Danica::Wrapper::Variable.new(name: :S0, latex: 'S_0'),
|
168
|
+
initial_velocity: Danica::Wrapper::Variable.new(name: :V0, latex: 'V_0')
|
163
169
|
}
|
164
170
|
end
|
165
171
|
|
166
172
|
context 'when variables are already wrapped with Danica::Wrapper::Variable' do
|
167
173
|
let(:variables) { expected }
|
174
|
+
|
168
175
|
it 'returns a hash with the variabels' do
|
169
176
|
expect(subject.variables_hash).to eq(expected)
|
170
177
|
end
|
@@ -198,10 +205,11 @@ describe Danica::Expression do
|
|
198
205
|
end
|
199
206
|
|
200
207
|
context 'when initializing with array' do
|
201
|
-
context '
|
202
|
-
let(:variables) { [ :t, 'a', {name: :S0, latex: 'S_0'}, { name: :V0, latex: 'V_0' } ] }
|
208
|
+
context 'when variables contain hashes' do
|
203
209
|
subject { described_class::Spatial.new(variables) }
|
204
210
|
|
211
|
+
let(:variables) { [:t, 'a', { name: :S0, latex: 'S_0' }, { name: :V0, latex: 'V_0' }] }
|
212
|
+
|
205
213
|
it 'returns a hash with the variabels' do
|
206
214
|
expect(subject.variables_hash).to eq(expected)
|
207
215
|
end
|
@@ -209,21 +217,23 @@ describe Danica::Expression do
|
|
209
217
|
end
|
210
218
|
|
211
219
|
context 'when initializing with sequence' do
|
212
|
-
context '
|
213
|
-
let(:variables) { [ :t, 'a', {name: :S0, latex: 'S_0'}, { name: :V0, latex: 'V_0' } ] }
|
220
|
+
context 'when variables contain hashes' do
|
214
221
|
subject { described_class::Spatial.new(*variables, {}) }
|
215
222
|
|
223
|
+
let(:variables) { [:t, 'a', { name: :S0, latex: 'S_0' }, { name: :V0, latex: 'V_0' }] }
|
224
|
+
|
216
225
|
it 'returns a hash with the variabels' do
|
217
226
|
expect(subject.variables_hash).to eq(expected)
|
218
227
|
end
|
219
228
|
end
|
220
229
|
end
|
221
230
|
|
222
|
-
context 'when initializing with variables
|
223
|
-
context '
|
224
|
-
let(:variables) { [ :t, 'a', {name: :S0, latex: 'S_0'}, { name: :V0, latex: 'V_0' } ] }
|
231
|
+
context 'when initializing with variables hash' do
|
232
|
+
context 'when variables contain hashes' do
|
225
233
|
subject { described_class::Spatial.new(variables: variables) }
|
226
234
|
|
235
|
+
let(:variables) { [:t, 'a', { name: :S0, latex: 'S_0' }, { name: :V0, latex: 'V_0' }] }
|
236
|
+
|
227
237
|
it 'returns a hash with the variabels' do
|
228
238
|
expect(subject.variables_hash).to eq(expected)
|
229
239
|
end
|
@@ -234,7 +244,9 @@ describe Danica::Expression do
|
|
234
244
|
describe '#variables' do
|
235
245
|
context 'when initialized with an array of variables' do
|
236
246
|
subject { described_class::Spatial.new(variables: variables.values) }
|
247
|
+
|
237
248
|
let(:expected) { variables.values.map { |v| Danica::Wrapper::Variable.new(v.is_a?(Hash) ? v : { name: v }) } }
|
249
|
+
|
238
250
|
it do
|
239
251
|
expect(subject.variables.compact).to eq(expected)
|
240
252
|
end
|
@@ -242,6 +254,7 @@ describe Danica::Expression do
|
|
242
254
|
|
243
255
|
context 'when not initializing all variables' do
|
244
256
|
subject { described_class::Spatial.new }
|
257
|
+
|
245
258
|
let(:time) { Danica::Wrapper::Variable.new(name: :t) }
|
246
259
|
|
247
260
|
context 'when initialized with an empty variable set' do
|
@@ -255,25 +268,32 @@ describe Danica::Expression do
|
|
255
268
|
subject.time = time
|
256
269
|
end
|
257
270
|
|
258
|
-
|
259
|
-
|
271
|
+
let(:expected_variables) do
|
272
|
+
[
|
260
273
|
time,
|
261
274
|
Danica::Wrapper::Variable.new(name: :acceleration),
|
262
275
|
Danica::Wrapper::Variable.new(name: :initial_space),
|
263
276
|
Danica::Wrapper::Variable.new(name: :initial_velocity)
|
264
|
-
]
|
277
|
+
]
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'returns the list of variables merged default and new variables' do
|
281
|
+
expect(subject.variables.compact).to eq(expected_variables)
|
265
282
|
end
|
266
283
|
end
|
267
284
|
|
268
285
|
context 'when initializing with a variable set' do
|
269
|
-
|
270
|
-
|
286
|
+
subject { described_class::Spatial.new(*names) }
|
287
|
+
|
288
|
+
let(:names) { %i[t a s0 v0] }
|
271
289
|
|
272
290
|
it 'returns the variables given oin initialization' do
|
273
291
|
expect(subject.variables.map(&:name)).to eq(names)
|
274
292
|
end
|
275
293
|
|
276
294
|
context 'when initializing variables with a hash out of order' do
|
295
|
+
subject { described_class::Spatial.new variables }
|
296
|
+
|
277
297
|
let(:variables) do
|
278
298
|
{
|
279
299
|
initial_velocity: :v0,
|
@@ -282,7 +302,6 @@ describe Danica::Expression do
|
|
282
302
|
time: :t
|
283
303
|
}
|
284
304
|
end
|
285
|
-
subject { described_class::Spatial.new variables }
|
286
305
|
|
287
306
|
it 'returns the variables given on initialization' do
|
288
307
|
expect(subject.variables.map(&:name)).to eq(names)
|
@@ -294,13 +313,15 @@ describe Danica::Expression do
|
|
294
313
|
|
295
314
|
describe '#calculate' do
|
296
315
|
context 'when all variables have value' do
|
316
|
+
subject { described_class::Spatial.new(time, acceleration, initial_space, initial_velocity) }
|
317
|
+
|
297
318
|
let(:time_value) { 2 }
|
298
319
|
let(:time) { time_value }
|
299
320
|
let(:acceleration) { 3 }
|
300
321
|
let(:initial_space) { 1 }
|
301
322
|
let(:initial_velocity) { 1 }
|
302
|
-
|
303
|
-
let(:expected) { initial_space + initial_velocity * time_value + acceleration * (time_value
|
323
|
+
|
324
|
+
let(:expected) { initial_space + initial_velocity * time_value + acceleration * (time_value**2) / 2.0 }
|
304
325
|
|
305
326
|
it 'retuirns the calculated value' do
|
306
327
|
expect(subject.calculate).to eq(expected)
|
@@ -313,7 +334,7 @@ describe Danica::Expression do
|
|
313
334
|
expect { subject.calculate }.to raise_error(Danica::Exception::NotDefined)
|
314
335
|
end
|
315
336
|
|
316
|
-
context '
|
337
|
+
context 'when calling calculate with a value for the variables' do
|
317
338
|
it 'calculate using the given value' do
|
318
339
|
expect(subject.calculate(time_value)).to eq(expected)
|
319
340
|
end
|
@@ -344,10 +365,11 @@ describe Danica::Expression do
|
|
344
365
|
describe 'baskara' do
|
345
366
|
context 'when using the default value for variables' do
|
346
367
|
subject { described_class::Baskara.new }
|
368
|
+
|
347
369
|
it_behaves_like 'an object that respond to basic_methods'
|
348
370
|
|
349
371
|
describe '#to_tex' do
|
350
|
-
let(:expected) { '\frac{-b \pm \sqrt{b^{2} -4 \cdot a \cdot c}}{2 \cdot a}'
|
372
|
+
let(:expected) { '\frac{-b \pm \sqrt{b^{2} -4 \cdot a \cdot c}}{2 \cdot a}' }
|
351
373
|
|
352
374
|
it 'return the latex format CAM' do
|
353
375
|
expect(subject.to_tex).to eq(expected)
|
@@ -355,7 +377,7 @@ describe Danica::Expression do
|
|
355
377
|
end
|
356
378
|
|
357
379
|
describe '#to_gnu' do
|
358
|
-
let(:expected) { '(-b + sqrt(b**(2) -4 * a * c))/(2 * a)'
|
380
|
+
let(:expected) { '(-b + sqrt(b**(2) -4 * a * c))/(2 * a)' }
|
359
381
|
|
360
382
|
it 'return the gnu format CAM' do
|
361
383
|
expect(subject.to_gnu).to eq(expected)
|
@@ -1,11 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
5
|
+
shared_examples 'a formatted result' do |output|
|
6
|
+
it do
|
7
|
+
expect(result).to be_a(described_class)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'keeps being able to parse format' do
|
11
|
+
expect(result.to_s).to eq(output)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
shared_examples('a formatted object that responds to basic operations') do |operations_map|
|
16
|
+
operations_map.each do |operation, (output, reverse_output)|
|
17
|
+
describe(operation.to_s) do
|
18
|
+
let(:result) { subject.public_send(operation, 2) }
|
19
|
+
|
20
|
+
it_behaves_like 'a formatted result', output
|
21
|
+
|
22
|
+
context 'when doing it backwards' do
|
23
|
+
let(:result) { Danica::Wrapper::Number.new(2).public_send(operation, subject) }
|
24
|
+
|
25
|
+
it_behaves_like 'a formatted result', reverse_output
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
3
30
|
describe Danica::Formatted do
|
31
|
+
subject do
|
32
|
+
described_class.new(content, format: format, **options)
|
33
|
+
end
|
34
|
+
|
4
35
|
let(:content) { Danica::Wrapper::Variable.new(latex: :V, gnuplot: :v) }
|
5
36
|
let(:format) { :tex }
|
6
37
|
let(:options) { {} }
|
7
|
-
|
8
|
-
|
38
|
+
|
39
|
+
describe '#repack' do
|
40
|
+
let(:expression) { Danica::Wrapper::Number.new(1.0 / 3) }
|
41
|
+
|
42
|
+
it do
|
43
|
+
expect(subject.repack(expression)).to be_a(described_class)
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when there are options' do
|
47
|
+
let(:options) { { decimals: 3 } }
|
48
|
+
|
49
|
+
it 'wraps expression with options' do
|
50
|
+
expect(subject.repack(expression).to_s).to eq('0.333')
|
51
|
+
end
|
52
|
+
end
|
9
53
|
end
|
10
54
|
|
11
55
|
describe '#to_s' do
|
@@ -24,7 +68,7 @@ describe Danica::Formatted do
|
|
24
68
|
end
|
25
69
|
|
26
70
|
context 'when variable has numeric value' do
|
27
|
-
let(:content) { Danica::Wrapper::Number.new(1/3.0) }
|
71
|
+
let(:content) { Danica::Wrapper::Number.new(1 / 3.0) }
|
28
72
|
|
29
73
|
it 'returns the formatted number' do
|
30
74
|
expect(subject.to_s).to eq('0.3333333333333333')
|
@@ -41,25 +85,12 @@ describe Danica::Formatted do
|
|
41
85
|
end
|
42
86
|
|
43
87
|
describe 'operators' do
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
expect((subject + 2).to_s).to eq('V + 2')
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe '*' do
|
55
|
-
it do
|
56
|
-
expect(subject * 2).to be_a(described_class)
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'keeps being able to parse format' do
|
60
|
-
expect((subject * 2).to_s).to eq('V \cdot 2')
|
61
|
-
end
|
62
|
-
end
|
88
|
+
it_behaves_like 'a formatted object that responds to basic operations',
|
89
|
+
:+ => ['V + 2', '2 + V'],
|
90
|
+
:- => ['V -2', '2 -V'],
|
91
|
+
:* => ['V \cdot 2', '2 \cdot V'],
|
92
|
+
:/ => ['\frac{V}{2}', '\frac{2}{V}'],
|
93
|
+
:** => ['V^{2}', '2^{V}']
|
63
94
|
|
64
95
|
describe '-@' do
|
65
96
|
it do
|
@@ -96,7 +127,7 @@ describe Danica::Formatted do
|
|
96
127
|
|
97
128
|
describe '#tex' do
|
98
129
|
it do
|
99
|
-
expect(subject.tex).to be_a(
|
130
|
+
expect(subject.tex).to be_a(described_class)
|
100
131
|
end
|
101
132
|
|
102
133
|
context 'when original format is tex' do
|
@@ -111,6 +142,7 @@ describe Danica::Formatted do
|
|
111
142
|
|
112
143
|
context 'when original format is gnu' do
|
113
144
|
let(:format) { :gnu }
|
145
|
+
|
114
146
|
it 'returns the tex string' do
|
115
147
|
expect(subject.tex.to_s).to eq('V')
|
116
148
|
end
|
@@ -123,7 +155,7 @@ describe Danica::Formatted do
|
|
123
155
|
|
124
156
|
describe '#gnu' do
|
125
157
|
it do
|
126
|
-
expect(subject.gnu).to be_a(
|
158
|
+
expect(subject.gnu).to be_a(described_class)
|
127
159
|
end
|
128
160
|
|
129
161
|
context 'when original format is tex' do
|
@@ -134,6 +166,7 @@ describe Danica::Formatted do
|
|
134
166
|
|
135
167
|
context 'when original format is gnu' do
|
136
168
|
let(:format) { :gnu }
|
169
|
+
|
137
170
|
it 'returns the gnu string' do
|
138
171
|
expect(subject.gnu.to_s).to eq('v')
|
139
172
|
end
|