danica 2.2.1 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -15
- data/lib/danica.rb +3 -18
- data/lib/danica/base_operations.rb +6 -6
- data/lib/danica/common.rb +7 -5
- data/lib/danica/dsl.rb +21 -5
- data/lib/danica/exception.rb +1 -1
- data/lib/danica/operator.rb +11 -0
- data/lib/danica/{sum.rb → operator/addition.rb} +2 -4
- data/lib/danica/operator/cos.rb +5 -0
- data/lib/danica/{division.rb → operator/division.rb} +1 -1
- data/lib/danica/operator/exponential.rb +5 -0
- data/lib/danica/operator/functional.rb +29 -0
- data/lib/danica/{product.rb → operator/multiplication.rb} +1 -3
- data/lib/danica/{power.rb → operator/power.rb} +1 -1
- data/lib/danica/operator/sin.rb +5 -0
- data/lib/danica/operator/squared_root.rb +5 -0
- data/lib/danica/variables_holder/variables_builder.rb +0 -2
- data/lib/danica/version.rb +1 -1
- data/lib/danica/wrapper.rb +10 -0
- data/lib/danica/{constant.rb → wrapper/constant.rb} +4 -1
- data/lib/danica/{group.rb → wrapper/group.rb} +2 -1
- data/lib/danica/{negative.rb → wrapper/negative.rb} +1 -1
- data/lib/danica/{number.rb → wrapper/number.rb} +1 -1
- data/lib/danica/{positive_negative.rb → wrapper/plus_minus.rb} +1 -1
- data/lib/danica/{variable.rb → wrapper/variable.rb} +3 -3
- data/spec/integration/negative_spec.rb +3 -3
- data/spec/integration/positive_negative_spec.rb +3 -3
- data/spec/integration/power_spec.rb +4 -4
- data/spec/integration/product_spec.rb +8 -8
- data/spec/integration/sum_spec.rb +5 -5
- data/spec/lib/danica/dsl_spec.rb +14 -11
- data/spec/lib/danica/function_spec.rb +8 -8
- data/spec/lib/danica/{sum_spec.rb → operator/addition_spec.rb} +3 -3
- data/spec/lib/danica/{cos_spec.rb → operator/cos_spec.rb} +1 -1
- data/spec/lib/danica/{division_spec.rb → operator/division_spec.rb} +6 -6
- data/spec/lib/danica/{exponential_spec.rb → operator/exponential_spec.rb} +1 -1
- data/spec/lib/danica/{product_spec.rb → operator/multiplication_spec.rb} +3 -3
- data/spec/lib/danica/{power_spec.rb → operator/power_spec.rb} +1 -1
- data/spec/lib/danica/{sin_spec.rb → operator/sin_spec.rb} +1 -1
- data/spec/lib/danica/{squared_root_spec.rb → operator/squared_root_spec.rb} +1 -1
- data/spec/lib/danica/{constant_spec.rb → wrapper/constant_spec.rb} +1 -1
- data/spec/lib/danica/wrapper/group_spec.rb +53 -0
- data/spec/lib/danica/{negative_spec.rb → wrapper/negative_spec.rb} +2 -2
- data/spec/lib/danica/{number_spec.rb → wrapper/number_spec.rb} +1 -1
- data/spec/lib/danica/{positive_negative_spec.rb → wrapper/plus_minus_spec.rb} +2 -2
- data/spec/lib/danica/{variable_spec.rb → wrapper/variable_spec.rb} +1 -1
- data/spec/lib/danica_spec.rb +10 -10
- data/spec/support/models/functions/baskara.rb +2 -2
- data/spec/support/models/functions/gauss.rb +4 -4
- data/spec/support/models/functions/spatial.rb +3 -3
- data/spec/support/shared_examples/base_operations.rb +10 -10
- data/spec/support/shared_examples/operator/chained.rb +1 -1
- metadata +46 -43
- data/lib/danica/cos.rb +0 -20
- data/lib/danica/exception/not_defined.rb +0 -2
- data/lib/danica/exponential.rb +0 -20
- data/lib/danica/sin.rb +0 -19
- data/lib/danica/squared_root.rb +0 -19
data/spec/lib/danica_spec.rb
CHANGED
@@ -4,24 +4,24 @@ describe Danica do
|
|
4
4
|
describe '.build' do
|
5
5
|
let(:result) { described_class.build(&block) }
|
6
6
|
|
7
|
-
context 'when creating a
|
7
|
+
context 'when creating a addition' do
|
8
8
|
let(:block) do
|
9
|
-
proc {
|
9
|
+
proc { addition(1, 2) }
|
10
10
|
end
|
11
11
|
|
12
|
-
it 'returns the expected
|
13
|
-
expect(result).to eq(Danica::
|
12
|
+
it 'returns the expected addition' do
|
13
|
+
expect(result).to eq(Danica::Operator::Addition.new(1,2))
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
context 'when creating a power of
|
17
|
+
context 'when creating a power of addition and multiplication' do
|
18
18
|
let(:block) do
|
19
|
-
proc { power(
|
19
|
+
proc { power(addition(1, 2), multiplication(2,3)) }
|
20
20
|
end
|
21
21
|
let(:expected) do
|
22
|
-
Danica::Power.new(
|
23
|
-
Danica::
|
24
|
-
Danica::
|
22
|
+
Danica::Operator::Power.new(
|
23
|
+
Danica::Operator::Addition.new(1, 2),
|
24
|
+
Danica::Operator::Multiplication.new(2, 3)
|
25
25
|
)
|
26
26
|
end
|
27
27
|
|
@@ -40,7 +40,7 @@ describe Danica do
|
|
40
40
|
end
|
41
41
|
let(:function) do
|
42
42
|
Danica::Function.build(:x) do
|
43
|
-
Danica::Power.new(x, 2)
|
43
|
+
Danica::Operator::Power.new(x, 2)
|
44
44
|
end.new
|
45
45
|
end
|
46
46
|
|
@@ -4,7 +4,7 @@ module Danica
|
|
4
4
|
private
|
5
5
|
|
6
6
|
def numerator
|
7
|
-
negative(b) +
|
7
|
+
negative(b) + Wrapper::PlusMinus.new(squared_root(delta))
|
8
8
|
end
|
9
9
|
|
10
10
|
def denominator
|
@@ -12,7 +12,7 @@ module Danica
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def delta
|
15
|
-
power(b, 2) -
|
15
|
+
power(b, 2) - multiplication(4, a, c)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Danica
|
2
|
-
class Function::Gauss < Function.build(:x, median: :u, variance_root: { latex: '\theta', gnu: :v }) {
|
2
|
+
class Function::Gauss < Function.build(:x, median: :u, variance_root: { latex: '\theta', gnu: :v }) { multiplication(parcels) }
|
3
3
|
|
4
4
|
private
|
5
5
|
|
@@ -12,7 +12,7 @@ module Danica
|
|
12
12
|
|
13
13
|
def denominator
|
14
14
|
squared_root(
|
15
|
-
|
15
|
+
multiplication(2, PI, variance),
|
16
16
|
)
|
17
17
|
end
|
18
18
|
|
@@ -20,9 +20,9 @@ module Danica
|
|
20
20
|
negative(
|
21
21
|
division(
|
22
22
|
power(group(
|
23
|
-
|
23
|
+
addition(x, negative(median))
|
24
24
|
), 2),
|
25
|
-
|
25
|
+
multiplication(2, variance)
|
26
26
|
)
|
27
27
|
)
|
28
28
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Danica
|
2
|
-
class Function::Spatial < Function.build(:time, :acceleration, :initial_space, :initial_velocity) {
|
2
|
+
class Function::Spatial < Function.build(:time, :acceleration, :initial_space, :initial_velocity) { addition(parcels) }
|
3
3
|
|
4
4
|
private
|
5
5
|
|
@@ -12,11 +12,11 @@ module Danica
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def spatial_velocity
|
15
|
-
|
15
|
+
multiplication(initial_velocity, time)
|
16
16
|
end
|
17
17
|
|
18
18
|
def spatial_acceleration
|
19
|
-
division(
|
19
|
+
division(multiplication(acceleration, time_squared), 2)
|
20
20
|
end
|
21
21
|
|
22
22
|
def time_squared
|
@@ -21,11 +21,11 @@ shared_examples 'an object with + operation' do
|
|
21
21
|
let(:result) { subject + other }
|
22
22
|
let(:subject_included) { subject }
|
23
23
|
|
24
|
-
it_behaves_like 'an object with an operation', Danica::
|
24
|
+
it_behaves_like 'an object with an operation', Danica::Operator::Addition
|
25
25
|
|
26
26
|
context 'when operating as reverse' do
|
27
|
-
let(:result) { Danica::Number.new(other) + subject }
|
28
|
-
it_behaves_like 'an object with an operation', Danica::
|
27
|
+
let(:result) { Danica::Wrapper::Number.new(other) + subject }
|
28
|
+
it_behaves_like 'an object with an operation', Danica::Operator::Addition
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -34,20 +34,20 @@ shared_examples 'an object with * operation' do
|
|
34
34
|
let(:result) { subject * other }
|
35
35
|
let(:subject_included) { subject }
|
36
36
|
|
37
|
-
it_behaves_like 'an object with an operation', Danica::
|
37
|
+
it_behaves_like 'an object with an operation', Danica::Operator::Multiplication
|
38
38
|
|
39
39
|
context 'when operating as reverse' do
|
40
|
-
let(:result) { Danica::Number.new(other) * subject }
|
41
|
-
it_behaves_like 'an object with an operation', Danica::
|
40
|
+
let(:result) { Danica::Wrapper::Number.new(other) * subject }
|
41
|
+
it_behaves_like 'an object with an operation', Danica::Operator::Multiplication
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
shared_examples 'an object with / operation' do
|
46
46
|
let(:other) { 104 }
|
47
|
-
let(:other_number) { Danica::Number.new(104) }
|
47
|
+
let(:other_number) { Danica::Wrapper::Number.new(104) }
|
48
48
|
let(:result) { subject / other }
|
49
49
|
|
50
|
-
it { expect(result).to be_a(Danica::Division) }
|
50
|
+
it { expect(result).to be_a(Danica::Operator::Division) }
|
51
51
|
|
52
52
|
it 'includes other as denominator' do
|
53
53
|
expect(result.denominator).to eq(other_number)
|
@@ -60,11 +60,11 @@ end
|
|
60
60
|
|
61
61
|
shared_examples 'an object with - operation' do
|
62
62
|
let(:other) { 104 }
|
63
|
-
let(:negative_other) { Danica::Negative.new(other) }
|
63
|
+
let(:negative_other) { Danica::Wrapper::Negative.new(other) }
|
64
64
|
let(:result) { subject - other }
|
65
65
|
let(:subject_included) { subject }
|
66
66
|
|
67
|
-
it { expect(result).to be_a(Danica::
|
67
|
+
it { expect(result).to be_a(Danica::Operator::Addition) }
|
68
68
|
|
69
69
|
it 'includes other as negative parcel' do
|
70
70
|
expect(result).to include(negative_other)
|
@@ -15,7 +15,7 @@ shared_examples 'a operator that knows how to calculate' do |arguments|
|
|
15
15
|
subject { described_class.new(*variables) }
|
16
16
|
|
17
17
|
describe 'to_f' do
|
18
|
-
it 'returns the
|
18
|
+
it 'returns the addition of variables value' do
|
19
19
|
expect(subject.to_f).to eq(calculated)
|
20
20
|
end
|
21
21
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danica
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darthjee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -155,49 +155,51 @@ files:
|
|
155
155
|
- lib/danica/base_operations.rb
|
156
156
|
- lib/danica/builder.rb
|
157
157
|
- lib/danica/common.rb
|
158
|
-
- lib/danica/constant.rb
|
159
|
-
- lib/danica/cos.rb
|
160
|
-
- lib/danica/division.rb
|
161
158
|
- lib/danica/dsl.rb
|
162
159
|
- lib/danica/exception.rb
|
163
|
-
- lib/danica/exception/not_defined.rb
|
164
|
-
- lib/danica/exponential.rb
|
165
160
|
- lib/danica/function.rb
|
166
|
-
- lib/danica/group.rb
|
167
|
-
- lib/danica/negative.rb
|
168
|
-
- lib/danica/number.rb
|
169
161
|
- lib/danica/operator.rb
|
162
|
+
- lib/danica/operator/addition.rb
|
170
163
|
- lib/danica/operator/chained.rb
|
171
|
-
- lib/danica/
|
172
|
-
- lib/danica/
|
173
|
-
- lib/danica/
|
174
|
-
- lib/danica/
|
175
|
-
- lib/danica/
|
176
|
-
- lib/danica/
|
177
|
-
- lib/danica/
|
164
|
+
- lib/danica/operator/cos.rb
|
165
|
+
- lib/danica/operator/division.rb
|
166
|
+
- lib/danica/operator/exponential.rb
|
167
|
+
- lib/danica/operator/functional.rb
|
168
|
+
- lib/danica/operator/multiplication.rb
|
169
|
+
- lib/danica/operator/power.rb
|
170
|
+
- lib/danica/operator/sin.rb
|
171
|
+
- lib/danica/operator/squared_root.rb
|
178
172
|
- lib/danica/variables_holder.rb
|
179
173
|
- lib/danica/variables_holder/variables_builder.rb
|
180
174
|
- lib/danica/version.rb
|
175
|
+
- lib/danica/wrapper.rb
|
176
|
+
- lib/danica/wrapper/constant.rb
|
177
|
+
- lib/danica/wrapper/group.rb
|
178
|
+
- lib/danica/wrapper/negative.rb
|
179
|
+
- lib/danica/wrapper/number.rb
|
180
|
+
- lib/danica/wrapper/plus_minus.rb
|
181
|
+
- lib/danica/wrapper/variable.rb
|
181
182
|
- spec/integration/negative_spec.rb
|
182
183
|
- spec/integration/positive_negative_spec.rb
|
183
184
|
- spec/integration/power_spec.rb
|
184
185
|
- spec/integration/product_spec.rb
|
185
186
|
- spec/integration/sum_spec.rb
|
186
|
-
- spec/lib/danica/constant_spec.rb
|
187
|
-
- spec/lib/danica/cos_spec.rb
|
188
|
-
- spec/lib/danica/division_spec.rb
|
189
187
|
- spec/lib/danica/dsl_spec.rb
|
190
|
-
- spec/lib/danica/exponential_spec.rb
|
191
188
|
- spec/lib/danica/function_spec.rb
|
192
|
-
- spec/lib/danica/
|
193
|
-
- spec/lib/danica/
|
194
|
-
- spec/lib/danica/
|
195
|
-
- spec/lib/danica/
|
196
|
-
- spec/lib/danica/
|
197
|
-
- spec/lib/danica/
|
198
|
-
- spec/lib/danica/
|
199
|
-
- spec/lib/danica/
|
200
|
-
- spec/lib/danica/
|
189
|
+
- spec/lib/danica/operator/addition_spec.rb
|
190
|
+
- spec/lib/danica/operator/cos_spec.rb
|
191
|
+
- spec/lib/danica/operator/division_spec.rb
|
192
|
+
- spec/lib/danica/operator/exponential_spec.rb
|
193
|
+
- spec/lib/danica/operator/multiplication_spec.rb
|
194
|
+
- spec/lib/danica/operator/power_spec.rb
|
195
|
+
- spec/lib/danica/operator/sin_spec.rb
|
196
|
+
- spec/lib/danica/operator/squared_root_spec.rb
|
197
|
+
- spec/lib/danica/wrapper/constant_spec.rb
|
198
|
+
- spec/lib/danica/wrapper/group_spec.rb
|
199
|
+
- spec/lib/danica/wrapper/negative_spec.rb
|
200
|
+
- spec/lib/danica/wrapper/number_spec.rb
|
201
|
+
- spec/lib/danica/wrapper/plus_minus_spec.rb
|
202
|
+
- spec/lib/danica/wrapper/variable_spec.rb
|
201
203
|
- spec/lib/danica_spec.rb
|
202
204
|
- spec/spec_helper.rb
|
203
205
|
- spec/support/models/functions/baskara.rb
|
@@ -240,21 +242,22 @@ test_files:
|
|
240
242
|
- spec/integration/power_spec.rb
|
241
243
|
- spec/integration/product_spec.rb
|
242
244
|
- spec/integration/sum_spec.rb
|
243
|
-
- spec/lib/danica/constant_spec.rb
|
244
|
-
- spec/lib/danica/cos_spec.rb
|
245
|
-
- spec/lib/danica/division_spec.rb
|
246
245
|
- spec/lib/danica/dsl_spec.rb
|
247
|
-
- spec/lib/danica/exponential_spec.rb
|
248
246
|
- spec/lib/danica/function_spec.rb
|
249
|
-
- spec/lib/danica/
|
250
|
-
- spec/lib/danica/
|
251
|
-
- spec/lib/danica/
|
252
|
-
- spec/lib/danica/
|
253
|
-
- spec/lib/danica/
|
254
|
-
- spec/lib/danica/
|
255
|
-
- spec/lib/danica/
|
256
|
-
- spec/lib/danica/
|
257
|
-
- spec/lib/danica/
|
247
|
+
- spec/lib/danica/operator/addition_spec.rb
|
248
|
+
- spec/lib/danica/operator/cos_spec.rb
|
249
|
+
- spec/lib/danica/operator/division_spec.rb
|
250
|
+
- spec/lib/danica/operator/exponential_spec.rb
|
251
|
+
- spec/lib/danica/operator/multiplication_spec.rb
|
252
|
+
- spec/lib/danica/operator/power_spec.rb
|
253
|
+
- spec/lib/danica/operator/sin_spec.rb
|
254
|
+
- spec/lib/danica/operator/squared_root_spec.rb
|
255
|
+
- spec/lib/danica/wrapper/constant_spec.rb
|
256
|
+
- spec/lib/danica/wrapper/group_spec.rb
|
257
|
+
- spec/lib/danica/wrapper/negative_spec.rb
|
258
|
+
- spec/lib/danica/wrapper/number_spec.rb
|
259
|
+
- spec/lib/danica/wrapper/plus_minus_spec.rb
|
260
|
+
- spec/lib/danica/wrapper/variable_spec.rb
|
258
261
|
- spec/lib/danica_spec.rb
|
259
262
|
- spec/spec_helper.rb
|
260
263
|
- spec/support/models/functions/baskara.rb
|
data/lib/danica/cos.rb
DELETED
data/lib/danica/exponential.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module Danica
|
2
|
-
class Exponential < Operator
|
3
|
-
variables :exponent
|
4
|
-
default_value :is_grouped?, true
|
5
|
-
|
6
|
-
def to_f
|
7
|
-
Math.exp(exponent.to_f)
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_tex
|
11
|
-
"e^{#{exponent.to_tex}}"
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_gnu
|
15
|
-
"exp(#{exponent.to_gnu})"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
|
data/lib/danica/sin.rb
DELETED
data/lib/danica/squared_root.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module Danica
|
2
|
-
class SquaredRoot < Operator
|
3
|
-
variables :variable
|
4
|
-
default_value :is_grouped?, true
|
5
|
-
|
6
|
-
def to_f
|
7
|
-
Math.sqrt(variable.to_f)
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_tex
|
11
|
-
"\\sqrt{#{variable.to_tex}}"
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_gnu
|
15
|
-
"sqrt(#{variable.to_gnu})"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|