danica 2.7.6 → 3.0.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/.circleci/config.yml +18 -10
- data/.rubocop.yml +11 -1
- data/.rubocop_todo.yml +50 -73
- data/Dockerfile +2 -2
- data/Gemfile +15 -0
- data/Makefile +7 -0
- data/README.md +7 -1
- data/danica.gemspec +3 -16
- data/danica.png +0 -0
- data/lib/danica/common.rb +13 -13
- data/lib/danica/dsl.rb +4 -4
- data/lib/danica/equation/builder.rb +2 -2
- data/lib/danica/equation.rb +6 -6
- data/lib/danica/exception.rb +2 -0
- data/lib/danica/expressable.rb +1 -1
- data/lib/danica/formatted.rb +10 -10
- data/lib/danica/function/name.rb +3 -3
- data/lib/danica/function.rb +2 -2
- data/lib/danica/operator/chained.rb +4 -4
- data/lib/danica/operator/division.rb +4 -4
- data/lib/danica/operator/functional.rb +3 -3
- data/lib/danica/operator/power.rb +4 -4
- data/lib/danica/variables_holder/alias_builder.rb +15 -1
- data/lib/danica/variables_holder/variables_builder.rb +11 -10
- data/lib/danica/variables_holder.rb +4 -4
- data/lib/danica/version.rb +1 -1
- data/lib/danica/wrapper/constant.rb +1 -5
- data/lib/danica/wrapper/group.rb +4 -4
- data/lib/danica/wrapper/negative.rb +2 -2
- data/lib/danica/wrapper/number.rb +1 -1
- data/lib/danica/wrapper/plus_minus.rb +4 -4
- data/lib/danica/wrapper/variable.rb +4 -4
- data/lib/danica/wrapper.rb +1 -1
- data/spec/integration/global/danica/operator/multiplication_spec.rb +1 -1
- data/spec/integration/readme/{equation_spec.rb → danica/equation_spec.rb} +2 -2
- data/spec/integration/readme/danica/expression/baskara_spec.rb +11 -0
- data/spec/integration/readme/{expression_spec.rb → danica/expression_spec.rb} +0 -8
- data/spec/integration/readme/danica/function/my_function_spec.rb +11 -0
- data/spec/integration/readme/danica/function/quadratic_sum_spec.rb +11 -0
- data/spec/integration/readme/{function_spec.rb → danica/function/spatial_spec.rb} +0 -32
- data/spec/integration/readme/danica/function_spec.rb +19 -0
- data/spec/integration/readme/{operator_spec.rb → danica/operator/inverse_spec.rb} +0 -22
- data/spec/integration/readme/danica/operator/my_operator_spec.rb +25 -0
- data/spec/integration/readme/{constant_spec.rb → danica/wrapper/constant_spec.rb} +2 -2
- data/spec/integration/readme/{number_spec.rb → danica/wrapper/number_spec.rb} +3 -3
- data/spec/integration/readme/{variables_spec.rb → danica/wrapper/variables_spec.rb} +15 -15
- data/spec/integration/readme/danica_spec.rb +3 -3
- data/spec/lib/danica/common_spec.rb +27 -27
- data/spec/lib/danica/dsl_spec.rb +1 -5
- data/spec/lib/danica/equation_spec.rb +7 -7
- data/spec/lib/danica/expression/gauss_spec.rb +6 -6
- data/spec/lib/danica/expression_spec.rb +39 -41
- data/spec/lib/danica/formatted_spec.rb +24 -23
- data/spec/lib/danica/function/name_spec.rb +6 -5
- data/spec/lib/danica/function_spec.rb +7 -18
- data/spec/lib/danica/operator/division_spec.rb +5 -5
- data/spec/lib/danica/operator_spec.rb +5 -5
- data/spec/lib/danica/variables_holder/store_spec.rb +9 -13
- data/spec/lib/danica/variables_holder_spec.rb +68 -67
- data/spec/lib/danica/wrapper/constant_spec.rb +19 -19
- data/spec/lib/danica/wrapper/group_spec.rb +7 -7
- data/spec/lib/danica/wrapper/negative_spec.rb +7 -7
- data/spec/lib/danica/wrapper/number_spec.rb +5 -5
- data/spec/lib/danica/wrapper/plus_minus_spec.rb +7 -7
- data/spec/lib/danica/wrapper/variable_spec.rb +6 -4
- data/spec/lib/danica/wrapper_spec.rb +3 -3
- data/spec/spec_helper.rb +4 -3
- data/spec/support/models/dummy/dsl_dummy.rb +5 -0
- data/spec/support/models/function/my_function.rb +1 -1
- data/spec/support/models/variables_holder/dummy.rb +1 -1
- data/spec/support/shared_examples/operator/chained.rb +2 -1
- data/spec/support/shared_examples/operator/single_input.rb +2 -1
- metadata +24 -233
@@ -27,7 +27,7 @@ module Danica
|
|
27
27
|
end
|
28
28
|
|
29
29
|
describe Danica::Common do
|
30
|
-
subject { clazz.new }
|
30
|
+
subject(:dummy) { clazz.new }
|
31
31
|
|
32
32
|
let(:clazz) { described_class::Dummy }
|
33
33
|
|
@@ -36,7 +36,7 @@ describe Danica::Common do
|
|
36
36
|
describe '#to_f' do
|
37
37
|
it do
|
38
38
|
expect do
|
39
|
-
|
39
|
+
dummy.to_f
|
40
40
|
end.to raise_error(Danica::Exception::NotImplemented)
|
41
41
|
end
|
42
42
|
end
|
@@ -45,39 +45,39 @@ describe Danica::Common do
|
|
45
45
|
context 'when defining to_tex and to_gnu' do
|
46
46
|
context 'when requesting :tex' do
|
47
47
|
it 'has a string for latex' do
|
48
|
-
expect(
|
48
|
+
expect(dummy.to(:tex)).to eq('tex')
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
context "when requesting 'tex'" do
|
53
53
|
it 'has a string for latex' do
|
54
|
-
expect(
|
54
|
+
expect(dummy.to('tex')).to eq('tex')
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
context 'when requesting :gnu' do
|
59
59
|
it 'has a string for gnu' do
|
60
|
-
expect(
|
60
|
+
expect(dummy.to(:gnu)).to eq('gnu')
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
64
|
context "when requesting 'gnu'" do
|
65
65
|
it 'has a string for gnu' do
|
66
|
-
expect(
|
66
|
+
expect(dummy.to('gnu')).to eq('gnu')
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
70
|
context 'when requesting wrong format' do
|
71
71
|
it do
|
72
72
|
expect do
|
73
|
-
|
73
|
+
dummy.to('format')
|
74
74
|
end.to raise_error(Danica::Exception::FormattedNotFound)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
78
|
context 'when passing options' do
|
79
79
|
it 'passes the options ahead' do
|
80
|
-
expect(
|
80
|
+
expect(dummy.to(:gnu, opt: 1)).to eq('gnu {:opt=>1}')
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
@@ -88,22 +88,22 @@ describe Danica::Common do
|
|
88
88
|
let(:clazz) { described_class::Dummy2 }
|
89
89
|
|
90
90
|
it 'returns the call of #to(:tex)' do
|
91
|
-
expect(
|
91
|
+
expect(dummy.to_tex).to eq('formatted: tex')
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
95
|
context 'when formatted was generated with gnu and with options' do
|
96
|
-
subject { number.gnu(decimals: 3) }
|
96
|
+
subject(:dummy) { number.gnu(decimals: 3) }
|
97
97
|
|
98
98
|
let(:number) { Danica::Wrapper::Number.new(1.0 / 3) }
|
99
99
|
|
100
100
|
it 'formats with the current options' do
|
101
|
-
expect(
|
101
|
+
expect(dummy.to_tex).to eq('0.333')
|
102
102
|
end
|
103
103
|
|
104
104
|
context 'when overwritting options' do
|
105
105
|
it 'formats with the current options' do
|
106
|
-
expect(
|
106
|
+
expect(dummy.to_tex(decimals: 4)).to eq('0.3333')
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|
@@ -114,22 +114,22 @@ describe Danica::Common do
|
|
114
114
|
let(:clazz) { described_class::Dummy2 }
|
115
115
|
|
116
116
|
it 'returns the call of #to(:gnu)' do
|
117
|
-
expect(
|
117
|
+
expect(dummy.to_gnu).to eq('formatted: gnu')
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
121
|
context 'when formatted was generated with tex and with options' do
|
122
|
-
subject { number.tex(decimals: 3) }
|
122
|
+
subject(:dummy) { number.tex(decimals: 3) }
|
123
123
|
|
124
124
|
let(:number) { Danica::Wrapper::Number.new(1.0 / 3) }
|
125
125
|
|
126
126
|
it 'formats with the current options' do
|
127
|
-
expect(
|
127
|
+
expect(dummy.to_gnu).to eq('0.333')
|
128
128
|
end
|
129
129
|
|
130
130
|
context 'when overwritting options' do
|
131
131
|
it 'formats with the current options' do
|
132
|
-
expect(
|
132
|
+
expect(dummy.to_gnu(decimals: 4)).to eq('0.3333')
|
133
133
|
end
|
134
134
|
end
|
135
135
|
end
|
@@ -137,17 +137,17 @@ describe Danica::Common do
|
|
137
137
|
|
138
138
|
describe 'to' do
|
139
139
|
context 'when already formatted with options' do
|
140
|
-
subject { number.tex(decimals: 3) }
|
140
|
+
subject(:dummy) { number.tex(decimals: 3) }
|
141
141
|
|
142
142
|
let(:number) { Danica::Wrapper::Number.new(1.0 / 3) }
|
143
143
|
|
144
144
|
it 'uses to with options' do
|
145
|
-
expect(
|
145
|
+
expect(dummy.to(:gnu)).to eq('0.333')
|
146
146
|
end
|
147
147
|
|
148
148
|
context 'when calling with options' do
|
149
149
|
it 'uses options' do
|
150
|
-
expect(
|
150
|
+
expect(dummy.to(:gnu, decimals: 4)).to eq('0.3333')
|
151
151
|
end
|
152
152
|
end
|
153
153
|
end
|
@@ -155,43 +155,43 @@ describe Danica::Common do
|
|
155
155
|
|
156
156
|
describe '#tex' do
|
157
157
|
it do
|
158
|
-
expect(
|
158
|
+
expect(dummy.tex).to be_a(Danica::Formatted)
|
159
159
|
end
|
160
160
|
|
161
161
|
it 'knows how to return a tex string' do
|
162
|
-
expect(
|
162
|
+
expect(dummy.tex.to_s).to eq('tex {:format=>:tex}')
|
163
163
|
end
|
164
164
|
|
165
165
|
context 'when passing options' do
|
166
166
|
it 'uses the arguments' do
|
167
|
-
expect(
|
167
|
+
expect(dummy.tex(decimals: 3).to_s).to eq('tex {:format=>:tex, :decimals=>3}')
|
168
168
|
end
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
172
172
|
describe '#gnu' do
|
173
173
|
it do
|
174
|
-
expect(
|
174
|
+
expect(dummy.gnu).to be_a(Danica::Formatted)
|
175
175
|
end
|
176
176
|
|
177
177
|
it 'knows how to return a gnu string' do
|
178
|
-
expect(
|
178
|
+
expect(dummy.gnu.to_s).to eq('gnu {:format=>:gnu}')
|
179
179
|
end
|
180
180
|
|
181
181
|
context 'when passing options' do
|
182
182
|
it 'uses the arguments' do
|
183
|
-
expect(
|
183
|
+
expect(dummy.gnu(decimals: 3).to_s).to eq('gnu {:format=>:gnu, :decimals=>3}')
|
184
184
|
end
|
185
185
|
end
|
186
186
|
end
|
187
187
|
|
188
188
|
describe '#formatted' do
|
189
189
|
it do
|
190
|
-
expect(
|
190
|
+
expect(dummy.formatted(format: :gnu)).to be_a(Danica::Formatted)
|
191
191
|
end
|
192
192
|
|
193
193
|
it 'knows how to return to build the string string' do
|
194
|
-
expect(
|
194
|
+
expect(dummy.formatted(format: :gnu, decimals: 3).to_s).to eq('gnu {:format=>:gnu, :decimals=>3}')
|
195
195
|
end
|
196
196
|
end
|
197
197
|
end
|
data/spec/lib/danica/dsl_spec.rb
CHANGED
@@ -41,11 +41,7 @@ shared_examples 'a class with mapped dsl' do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
describe Danica::DSL do
|
44
|
-
|
45
|
-
include Danica::DSL
|
46
|
-
end
|
47
|
-
|
48
|
-
let(:subject) { described_class::Dummy.new }
|
44
|
+
subject { described_class::Dummy.new }
|
49
45
|
|
50
46
|
it_behaves_like 'a class with mapped dsl'
|
51
47
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Danica::Equation do
|
6
|
-
subject do
|
6
|
+
subject(:equation) do
|
7
7
|
clazz.new
|
8
8
|
end
|
9
9
|
|
@@ -18,12 +18,12 @@ describe Danica::Equation do
|
|
18
18
|
|
19
19
|
describe '.build' do
|
20
20
|
it 'returns a class that is also an equation' do
|
21
|
-
expect(
|
21
|
+
expect(equation).to be_a(described_class)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
describe '.create' do
|
26
|
-
subject do
|
26
|
+
subject(:equation) do
|
27
27
|
described_class.create(:x, :y) do
|
28
28
|
left { y }
|
29
29
|
right { x**2 }
|
@@ -31,25 +31,25 @@ describe Danica::Equation do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'returns a class that is also an equation' do
|
34
|
-
expect(
|
34
|
+
expect(equation).to be_a(described_class)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
describe '#to_f' do
|
39
39
|
it do
|
40
|
-
expect {
|
40
|
+
expect { equation.to_f }.to raise_error(Danica::Exception::NotImplemented)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
describe '#to_tex' do
|
45
45
|
it 'joins the expressions in a equation' do
|
46
|
-
expect(
|
46
|
+
expect(equation.to_tex).to eq('y = x^{2}')
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
describe '#to_gnu' do
|
51
51
|
it 'joins the expressions in a equation' do
|
52
|
-
expect(
|
52
|
+
expect(equation.to_gnu).to eq('y = x**(2)')
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Danica::Expression::Gauss do
|
6
|
-
subject { described_class::Gauss.new(variables) }
|
6
|
+
subject(:expression) { described_class::Gauss.new(variables) }
|
7
7
|
|
8
8
|
let(:variables) do
|
9
9
|
{
|
@@ -20,7 +20,7 @@ describe Danica::Expression::Gauss do
|
|
20
20
|
let(:expected) { '\frac{1}{\theta \cdot \sqrt{2 \cdot \pi}} \cdot e^{-\frac{\left(x -u\right)^{2}}{2 \cdot \theta^{2}}}' }
|
21
21
|
|
22
22
|
it 'return the latex format CAM' do
|
23
|
-
expect(
|
23
|
+
expect(expression.to_tex).to eq(expected)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -30,19 +30,19 @@ describe Danica::Expression::Gauss do
|
|
30
30
|
let(:expected) { '(1)/(v * sqrt(2 * pi)) * exp(-((x -u)**(2))/(2 * v**(2)))' }
|
31
31
|
|
32
32
|
it 'return the gnu format CAM' do
|
33
|
-
expect(
|
33
|
+
expect(expression.to_gnu).to eq(expected)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
context 'when not passing variables' do
|
39
|
-
subject { described_class::Gauss.new }
|
39
|
+
subject(:expression) { described_class::Gauss.new }
|
40
40
|
|
41
41
|
describe '#to_tex' do
|
42
42
|
let(:expected) { '\frac{1}{\sigma \cdot \sqrt{2 \cdot \pi}} \cdot e^{-\frac{\left(x -\mu\right)^{2}}{2 \cdot \sigma^{2}}}' }
|
43
43
|
|
44
44
|
it 'rely on default variables definition' do
|
45
|
-
expect(
|
45
|
+
expect(expression.to_tex).to eq(expected)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -50,7 +50,7 @@ describe Danica::Expression::Gauss do
|
|
50
50
|
let(:expected) { '(1)/(v * sqrt(2 * pi)) * exp(-((x -u)**(2))/(2 * v**(2)))' }
|
51
51
|
|
52
52
|
it 'rely on default variables definition' do
|
53
|
-
expect(
|
53
|
+
expect(expression.to_gnu).to eq(expected)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -27,8 +27,6 @@ shared_examples 'a generically generated expression' do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
describe Danica::Expression do
|
30
|
-
subject { expression }
|
31
|
-
|
32
30
|
let(:variables) { %i[x y] }
|
33
31
|
let(:expression_class) do
|
34
32
|
described_class.build(*variables) do
|
@@ -37,7 +35,7 @@ describe Danica::Expression do
|
|
37
35
|
end
|
38
36
|
|
39
37
|
describe '.build' do
|
40
|
-
|
38
|
+
subject(:expression) do
|
41
39
|
expression_class.new
|
42
40
|
end
|
43
41
|
|
@@ -113,7 +111,7 @@ describe Danica::Expression do
|
|
113
111
|
end
|
114
112
|
|
115
113
|
describe '.create' do
|
116
|
-
|
114
|
+
subject(:expression) do
|
117
115
|
described_class.create(*variables) do
|
118
116
|
Danica::Operator::Power.new(x, y)
|
119
117
|
end
|
@@ -125,7 +123,7 @@ describe Danica::Expression do
|
|
125
123
|
end
|
126
124
|
|
127
125
|
describe 'spatial' do
|
128
|
-
subject { described_class::Spatial.new(variables) }
|
126
|
+
subject(:expression) { described_class::Spatial.new(variables) }
|
129
127
|
|
130
128
|
let(:variables) do
|
131
129
|
{
|
@@ -144,7 +142,7 @@ describe Danica::Expression do
|
|
144
142
|
let(:expected) { 'S_0 + V_0 \cdot t + \frac{a \cdot t^{2}}{2}' }
|
145
143
|
|
146
144
|
it 'return the latex format CAM' do
|
147
|
-
expect(
|
145
|
+
expect(expression.to_tex).to eq(expected)
|
148
146
|
end
|
149
147
|
end
|
150
148
|
end
|
@@ -154,7 +152,7 @@ describe Danica::Expression do
|
|
154
152
|
let(:expected) { 'S0 + V0 * t + (a * t**(2))/(2)' }
|
155
153
|
|
156
154
|
it 'return the latex format CAM' do
|
157
|
-
expect(
|
155
|
+
expect(expression.to_gnu).to eq(expected)
|
158
156
|
end
|
159
157
|
end
|
160
158
|
end
|
@@ -173,7 +171,7 @@ describe Danica::Expression do
|
|
173
171
|
let(:variables) { expected }
|
174
172
|
|
175
173
|
it 'returns a hash with the variabels' do
|
176
|
-
expect(
|
174
|
+
expect(expression.variables_hash).to eq(expected)
|
177
175
|
end
|
178
176
|
end
|
179
177
|
|
@@ -183,59 +181,59 @@ describe Danica::Expression do
|
|
183
181
|
end
|
184
182
|
|
185
183
|
it 'returns a hash with the variabels' do
|
186
|
-
expect(
|
184
|
+
expect(expression.variables_hash).to eq(expected)
|
187
185
|
end
|
188
186
|
end
|
189
187
|
|
190
188
|
context 'when variables are not wrapped yet' do
|
191
189
|
it 'returns a hash with the variabels' do
|
192
|
-
expect(
|
190
|
+
expect(expression.variables_hash).to eq(expected)
|
193
191
|
end
|
194
192
|
end
|
195
193
|
|
196
194
|
context 'when changing a variable' do
|
197
195
|
before do
|
198
|
-
|
196
|
+
expression.time = :x
|
199
197
|
expected[:time] = Danica::Wrapper::Variable.new(name: :x)
|
200
198
|
end
|
201
199
|
|
202
200
|
it do
|
203
|
-
expect(
|
201
|
+
expect(expression.variables_hash).to eq(expected)
|
204
202
|
end
|
205
203
|
end
|
206
204
|
|
207
205
|
context 'when initializing with array' do
|
208
206
|
context 'when variables contain hashes' do
|
209
|
-
subject { described_class::Spatial.new(variables) }
|
207
|
+
subject(:expression) { described_class::Spatial.new(variables) }
|
210
208
|
|
211
209
|
let(:variables) { [:t, 'a', { name: :S0, latex: 'S_0' }, { name: :V0, latex: 'V_0' }] }
|
212
210
|
|
213
211
|
it 'returns a hash with the variabels' do
|
214
|
-
expect(
|
212
|
+
expect(expression.variables_hash).to eq(expected)
|
215
213
|
end
|
216
214
|
end
|
217
215
|
end
|
218
216
|
|
219
217
|
context 'when initializing with sequence' do
|
220
218
|
context 'when variables contain hashes' do
|
221
|
-
subject { described_class::Spatial.new(*variables, {}) }
|
219
|
+
subject(:expression) { described_class::Spatial.new(*variables, {}) }
|
222
220
|
|
223
221
|
let(:variables) { [:t, 'a', { name: :S0, latex: 'S_0' }, { name: :V0, latex: 'V_0' }] }
|
224
222
|
|
225
223
|
it 'returns a hash with the variabels' do
|
226
|
-
expect(
|
224
|
+
expect(expression.variables_hash).to eq(expected)
|
227
225
|
end
|
228
226
|
end
|
229
227
|
end
|
230
228
|
|
231
229
|
context 'when initializing with variables hash' do
|
232
230
|
context 'when variables contain hashes' do
|
233
|
-
subject { described_class::Spatial.new(variables: variables) }
|
231
|
+
subject(:expression) { described_class::Spatial.new(variables: variables) }
|
234
232
|
|
235
233
|
let(:variables) { [:t, 'a', { name: :S0, latex: 'S_0' }, { name: :V0, latex: 'V_0' }] }
|
236
234
|
|
237
235
|
it 'returns a hash with the variabels' do
|
238
|
-
expect(
|
236
|
+
expect(expression.variables_hash).to eq(expected)
|
239
237
|
end
|
240
238
|
end
|
241
239
|
end
|
@@ -243,29 +241,29 @@ describe Danica::Expression do
|
|
243
241
|
|
244
242
|
describe '#variables' do
|
245
243
|
context 'when initialized with an array of variables' do
|
246
|
-
subject { described_class::Spatial.new(variables: variables.values) }
|
244
|
+
subject(:expression) { described_class::Spatial.new(variables: variables.values) }
|
247
245
|
|
248
246
|
let(:expected) { variables.values.map { |v| Danica::Wrapper::Variable.new(v.is_a?(Hash) ? v : { name: v }) } }
|
249
247
|
|
250
248
|
it do
|
251
|
-
expect(
|
249
|
+
expect(expression.variables.compact).to eq(expected)
|
252
250
|
end
|
253
251
|
end
|
254
252
|
|
255
253
|
context 'when not initializing all variables' do
|
256
|
-
subject { described_class::Spatial.new }
|
254
|
+
subject(:expression) { described_class::Spatial.new }
|
257
255
|
|
258
256
|
let(:time) { Danica::Wrapper::Variable.new(name: :t) }
|
259
257
|
|
260
258
|
context 'when initialized with an empty variable set' do
|
261
259
|
it do
|
262
|
-
expect(
|
260
|
+
expect(expression.variables.compact).not_to be_empty
|
263
261
|
end
|
264
262
|
end
|
265
263
|
|
266
264
|
context 'when changing a variable' do
|
267
265
|
before do
|
268
|
-
|
266
|
+
expression.time = time
|
269
267
|
end
|
270
268
|
|
271
269
|
let(:expected_variables) do
|
@@ -278,21 +276,21 @@ describe Danica::Expression do
|
|
278
276
|
end
|
279
277
|
|
280
278
|
it 'returns the list of variables merged default and new variables' do
|
281
|
-
expect(
|
279
|
+
expect(expression.variables.compact).to eq(expected_variables)
|
282
280
|
end
|
283
281
|
end
|
284
282
|
|
285
283
|
context 'when initializing with a variable set' do
|
286
|
-
subject { described_class::Spatial.new(*names) }
|
284
|
+
subject(:expression) { described_class::Spatial.new(*names) }
|
287
285
|
|
288
286
|
let(:names) { %i[t a s0 v0] }
|
289
287
|
|
290
288
|
it 'returns the variables given oin initialization' do
|
291
|
-
expect(
|
289
|
+
expect(expression.variables.map(&:name)).to eq(names)
|
292
290
|
end
|
293
291
|
|
294
292
|
context 'when initializing variables with a hash out of order' do
|
295
|
-
subject { described_class::Spatial.new variables }
|
293
|
+
subject(:expression) { described_class::Spatial.new variables }
|
296
294
|
|
297
295
|
let(:variables) do
|
298
296
|
{
|
@@ -304,7 +302,7 @@ describe Danica::Expression do
|
|
304
302
|
end
|
305
303
|
|
306
304
|
it 'returns the variables given on initialization' do
|
307
|
-
expect(
|
305
|
+
expect(expression.variables.map(&:name)).to eq(names)
|
308
306
|
end
|
309
307
|
end
|
310
308
|
end
|
@@ -313,7 +311,7 @@ describe Danica::Expression do
|
|
313
311
|
|
314
312
|
describe '#calculate' do
|
315
313
|
context 'when all variables have value' do
|
316
|
-
subject { described_class::Spatial.new(time, acceleration, initial_space, initial_velocity) }
|
314
|
+
subject(:expression) { described_class::Spatial.new(time, acceleration, initial_space, initial_velocity) }
|
317
315
|
|
318
316
|
let(:time_value) { 2 }
|
319
317
|
let(:time) { time_value }
|
@@ -321,40 +319,40 @@ describe Danica::Expression do
|
|
321
319
|
let(:initial_space) { 1 }
|
322
320
|
let(:initial_velocity) { 1 }
|
323
321
|
|
324
|
-
let(:expected) { initial_space + initial_velocity * time_value + acceleration * (time_value**2) / 2.0 }
|
322
|
+
let(:expected) { initial_space + (initial_velocity * time_value) + (acceleration * (time_value**2) / 2.0) }
|
325
323
|
|
326
324
|
it 'retuirns the calculated value' do
|
327
|
-
expect(
|
325
|
+
expect(expression.calculate).to eq(expected)
|
328
326
|
end
|
329
327
|
|
330
328
|
context 'when not all variables have value' do
|
331
329
|
let(:time) { :t }
|
332
330
|
|
333
331
|
it do
|
334
|
-
expect {
|
332
|
+
expect { expression.calculate }.to raise_error(Danica::Exception::NotDefined)
|
335
333
|
end
|
336
334
|
|
337
335
|
context 'when calling calculate with a value for the variables' do
|
338
336
|
it 'calculate using the given value' do
|
339
|
-
expect(
|
337
|
+
expect(expression.calculate(time_value)).to eq(expected)
|
340
338
|
end
|
341
339
|
|
342
340
|
it 'does not change the values of then valued variables' do
|
343
341
|
expect do
|
344
|
-
|
345
|
-
end.not_to change(
|
342
|
+
expression.calculate(time_value)
|
343
|
+
end.not_to change(expression.time, :valued?)
|
346
344
|
end
|
347
345
|
end
|
348
346
|
|
349
347
|
context 'when calling with a hash for the values' do
|
350
348
|
it 'calculate using the given value' do
|
351
|
-
expect(
|
349
|
+
expect(expression.calculate(time: time_value)).to eq(expected)
|
352
350
|
end
|
353
351
|
|
354
352
|
it 'does not change the values of then valued variables' do
|
355
353
|
expect do
|
356
|
-
|
357
|
-
end.not_to change(
|
354
|
+
expression.calculate(time: time_value)
|
355
|
+
end.not_to change(expression.time, :valued?)
|
358
356
|
end
|
359
357
|
end
|
360
358
|
end
|
@@ -364,7 +362,7 @@ describe Danica::Expression do
|
|
364
362
|
|
365
363
|
describe 'baskara' do
|
366
364
|
context 'when using the default value for variables' do
|
367
|
-
subject { described_class::Baskara.new }
|
365
|
+
subject(:expression) { described_class::Baskara.new }
|
368
366
|
|
369
367
|
it_behaves_like 'an object that respond to basic_methods'
|
370
368
|
|
@@ -372,7 +370,7 @@ describe Danica::Expression do
|
|
372
370
|
let(:expected) { '\frac{-b \pm \sqrt{b^{2} -4 \cdot a \cdot c}}{2 \cdot a}' }
|
373
371
|
|
374
372
|
it 'return the latex format CAM' do
|
375
|
-
expect(
|
373
|
+
expect(expression.to_tex).to eq(expected)
|
376
374
|
end
|
377
375
|
end
|
378
376
|
|
@@ -380,7 +378,7 @@ describe Danica::Expression do
|
|
380
378
|
let(:expected) { '(-b + sqrt(b**(2) -4 * a * c))/(2 * a)' }
|
381
379
|
|
382
380
|
it 'return the gnu format CAM' do
|
383
|
-
expect(
|
381
|
+
expect(expression.to_gnu).to eq(expected)
|
384
382
|
end
|
385
383
|
end
|
386
384
|
end
|