danica 2.2.1 → 2.3.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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +39 -15
  3. data/lib/danica.rb +3 -18
  4. data/lib/danica/base_operations.rb +6 -6
  5. data/lib/danica/common.rb +7 -5
  6. data/lib/danica/dsl.rb +21 -5
  7. data/lib/danica/exception.rb +1 -1
  8. data/lib/danica/operator.rb +11 -0
  9. data/lib/danica/{sum.rb → operator/addition.rb} +2 -4
  10. data/lib/danica/operator/cos.rb +5 -0
  11. data/lib/danica/{division.rb → operator/division.rb} +1 -1
  12. data/lib/danica/operator/exponential.rb +5 -0
  13. data/lib/danica/operator/functional.rb +29 -0
  14. data/lib/danica/{product.rb → operator/multiplication.rb} +1 -3
  15. data/lib/danica/{power.rb → operator/power.rb} +1 -1
  16. data/lib/danica/operator/sin.rb +5 -0
  17. data/lib/danica/operator/squared_root.rb +5 -0
  18. data/lib/danica/variables_holder/variables_builder.rb +0 -2
  19. data/lib/danica/version.rb +1 -1
  20. data/lib/danica/wrapper.rb +10 -0
  21. data/lib/danica/{constant.rb → wrapper/constant.rb} +4 -1
  22. data/lib/danica/{group.rb → wrapper/group.rb} +2 -1
  23. data/lib/danica/{negative.rb → wrapper/negative.rb} +1 -1
  24. data/lib/danica/{number.rb → wrapper/number.rb} +1 -1
  25. data/lib/danica/{positive_negative.rb → wrapper/plus_minus.rb} +1 -1
  26. data/lib/danica/{variable.rb → wrapper/variable.rb} +3 -3
  27. data/spec/integration/negative_spec.rb +3 -3
  28. data/spec/integration/positive_negative_spec.rb +3 -3
  29. data/spec/integration/power_spec.rb +4 -4
  30. data/spec/integration/product_spec.rb +8 -8
  31. data/spec/integration/sum_spec.rb +5 -5
  32. data/spec/lib/danica/dsl_spec.rb +14 -11
  33. data/spec/lib/danica/function_spec.rb +8 -8
  34. data/spec/lib/danica/{sum_spec.rb → operator/addition_spec.rb} +3 -3
  35. data/spec/lib/danica/{cos_spec.rb → operator/cos_spec.rb} +1 -1
  36. data/spec/lib/danica/{division_spec.rb → operator/division_spec.rb} +6 -6
  37. data/spec/lib/danica/{exponential_spec.rb → operator/exponential_spec.rb} +1 -1
  38. data/spec/lib/danica/{product_spec.rb → operator/multiplication_spec.rb} +3 -3
  39. data/spec/lib/danica/{power_spec.rb → operator/power_spec.rb} +1 -1
  40. data/spec/lib/danica/{sin_spec.rb → operator/sin_spec.rb} +1 -1
  41. data/spec/lib/danica/{squared_root_spec.rb → operator/squared_root_spec.rb} +1 -1
  42. data/spec/lib/danica/{constant_spec.rb → wrapper/constant_spec.rb} +1 -1
  43. data/spec/lib/danica/wrapper/group_spec.rb +53 -0
  44. data/spec/lib/danica/{negative_spec.rb → wrapper/negative_spec.rb} +2 -2
  45. data/spec/lib/danica/{number_spec.rb → wrapper/number_spec.rb} +1 -1
  46. data/spec/lib/danica/{positive_negative_spec.rb → wrapper/plus_minus_spec.rb} +2 -2
  47. data/spec/lib/danica/{variable_spec.rb → wrapper/variable_spec.rb} +1 -1
  48. data/spec/lib/danica_spec.rb +10 -10
  49. data/spec/support/models/functions/baskara.rb +2 -2
  50. data/spec/support/models/functions/gauss.rb +4 -4
  51. data/spec/support/models/functions/spatial.rb +3 -3
  52. data/spec/support/shared_examples/base_operations.rb +10 -10
  53. data/spec/support/shared_examples/operator/chained.rb +1 -1
  54. metadata +46 -43
  55. data/lib/danica/cos.rb +0 -20
  56. data/lib/danica/exception/not_defined.rb +0 -2
  57. data/lib/danica/exponential.rb +0 -20
  58. data/lib/danica/sin.rb +0 -19
  59. data/lib/danica/squared_root.rb +0 -19
@@ -1,6 +1,7 @@
1
1
  module Danica
2
- class Group
2
+ class Wrapper::Group
3
3
  include Common
4
+ include BaseOperations
4
5
  include ActiveModel::Model
5
6
 
6
7
  attr_accessor :value
@@ -1,5 +1,5 @@
1
1
  module Danica
2
- class Negative
2
+ class Wrapper::Negative
3
3
  include Common
4
4
  include BaseOperations
5
5
  include VariablesHolder
@@ -1,5 +1,5 @@
1
1
  module Danica
2
- class Number
2
+ class Wrapper::Number
3
3
  include ActiveModel::Model
4
4
  include BaseOperations
5
5
  include Common
@@ -1,5 +1,5 @@
1
1
  module Danica
2
- class PositiveNegative
2
+ class Wrapper::PlusMinus
3
3
  include Common
4
4
  include BaseOperations
5
5
  include VariablesHolder
@@ -1,5 +1,5 @@
1
1
  module Danica
2
- class Variable
2
+ class Wrapper::Variable
3
3
  include ActiveModel::Model
4
4
  include BaseOperations
5
5
  include Common
@@ -14,7 +14,7 @@ module Danica
14
14
  end
15
15
 
16
16
  def ==(other)
17
- return false unless other.class == Variable
17
+ return false unless other.class == self.class
18
18
  return other.value == value &&
19
19
  other.name == name &&
20
20
  other.latex == latex &&
@@ -32,7 +32,7 @@ module Danica
32
32
  end
33
33
 
34
34
  def value=(value)
35
- @value = value.is_a?(Numeric) ? Number.new(value) : value
35
+ @value = value.is_a?(Numeric) ? number(value) : value
36
36
  end
37
37
  end
38
38
  end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'integration of negative' do
4
- describe 'with a sum' do
4
+ describe 'with a addition' do
5
5
  subject do
6
- Danica::Negative.new(
7
- Danica::Sum.new(1,2,3)
6
+ Danica::Wrapper::Negative.new(
7
+ Danica::Operator::Addition.new(1,2,3)
8
8
  )
9
9
  end
10
10
 
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'integration of positive negative' do
4
- describe 'with a sum' do
4
+ describe 'with a addition' do
5
5
  subject do
6
- Danica::PositiveNegative.new(
7
- Danica::Sum.new(1,2,3)
6
+ Danica::Wrapper::PlusMinus.new(
7
+ Danica::Operator::Addition.new(1,2,3)
8
8
  )
9
9
  end
10
10
 
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'integration of power' do
4
- describe 'of sums' do
4
+ describe 'of additions' do
5
5
  subject do
6
- Danica::Power.new(
7
- Danica::Sum.new(3, 4),
8
- Danica::Sum.new(5, 6)
6
+ Danica::Operator::Power.new(
7
+ Danica::Operator::Addition.new(3, 4),
8
+ Danica::Operator::Addition.new(5, 6)
9
9
  )
10
10
  end
11
11
 
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'integration of product' do
4
- describe 'of number and sum' do
3
+ describe 'integration of multiplication' do
4
+ describe 'of number and addition' do
5
5
  subject do
6
- Danica::Product.new(
7
- 3, Danica::Sum.new(2, 4)
6
+ Danica::Operator::Multiplication.new(
7
+ 3, Danica::Operator::Addition.new(2, 4)
8
8
  )
9
9
  end
10
10
 
@@ -21,11 +21,11 @@ describe 'integration of product' do
21
21
  end
22
22
  end
23
23
 
24
- describe 'of sums' do
24
+ describe 'of additions' do
25
25
  subject do
26
- Danica::Product.new(
27
- Danica::Sum.new(1,2),
28
- Danica::Sum.new(3,4)
26
+ Danica::Operator::Multiplication.new(
27
+ Danica::Operator::Addition.new(1,2),
28
+ Danica::Operator::Addition.new(3,4)
29
29
  )
30
30
  end
31
31
 
@@ -1,14 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'integration of sum' do
3
+ describe 'integration of addition' do
4
4
  describe 'with negative and positivenegative (+/-) numbers' do
5
5
  subject do
6
- Danica::Sum.new(
7
- Danica::Negative.new(1),
6
+ Danica::Operator::Addition.new(
7
+ Danica::Wrapper::Negative.new(1),
8
8
  2,
9
- Danica::Negative.new(3),
9
+ Danica::Wrapper::Negative.new(3),
10
10
  4,
11
- Danica::PositiveNegative.new(5)
11
+ Danica::Wrapper::PlusMinus.new(5)
12
12
  )
13
13
  end
14
14
 
@@ -12,21 +12,24 @@ end
12
12
 
13
13
  shared_context 'a class with mapped dsl' do
14
14
  {
15
- sum: Danica::Sum,
16
- product: Danica::Product,
17
- division: Danica::Division,
18
- sin: Danica::Sin,
19
- cos: Danica::Cos,
20
- power: Danica::Power
15
+ addition: Danica::Operator::Addition,
16
+ sum: Danica::Operator::Addition,
17
+ multiplication: Danica::Operator::Multiplication,
18
+ product: Danica::Operator::Multiplication,
19
+ division: Danica::Operator::Division,
20
+ sin: Danica::Operator::Sin,
21
+ cos: Danica::Operator::Cos,
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: Danica::SquaredRoot,
26
- exponential: Danica::Exponential,
27
- group: Danica::Group,
28
- negative: Danica::Negative,
29
- number: Danica::Number
27
+ squared_root: Danica::Operator::SquaredRoot,
28
+ exponential: Danica::Operator::Exponential,
29
+ group: Danica::Wrapper::Group,
30
+ negative: Danica::Wrapper::Negative,
31
+ number: Danica::Wrapper::Number,
32
+ plus_minus: Danica::Wrapper::PlusMinus
30
33
  }.each do |aliaz, clazz|
31
34
  it_behaves_like 'a class with alias to a clazz', aliaz, clazz, 9
32
35
  end
@@ -5,7 +5,7 @@ describe Danica::Function do
5
5
  let(:variables) { %i(x y) }
6
6
  let(:function_class) do
7
7
  described_class.build(*variables) do
8
- Danica::Power.new(x, y)
8
+ Danica::Operator::Power.new(x, y)
9
9
  end
10
10
  end
11
11
  let(:function) do
@@ -129,14 +129,14 @@ describe Danica::Function do
129
129
  describe '#variables_hash' do
130
130
  let(:expected) do
131
131
  {
132
- time: Danica::Variable.new(name: :t),
133
- acceleration: Danica::Variable.new(name: 'a'),
134
- initial_space: Danica::Variable.new( name: :S0, latex: 'S_0' ),
135
- initial_velocity: Danica::Variable.new( name: :V0, latex: 'V_0' )
132
+ time: Danica::Wrapper::Variable.new(name: :t),
133
+ acceleration: Danica::Wrapper::Variable.new(name: 'a'),
134
+ initial_space: Danica::Wrapper::Variable.new( name: :S0, latex: 'S_0' ),
135
+ initial_velocity: Danica::Wrapper::Variable.new( name: :V0, latex: 'V_0' )
136
136
  }
137
137
  end
138
138
 
139
- context 'when variables are already wrapped with DanicaVariable' do
139
+ context 'when variables are already wrapped with Danica::Wrapper::Variable' do
140
140
  let(:variables) { expected }
141
141
  it 'returns a hash with the variabels' do
142
142
  expect(subject.variables_hash).to eq(expected)
@@ -162,7 +162,7 @@ describe Danica::Function do
162
162
  context 'when changing a variable' do
163
163
  before do
164
164
  subject.time = :x
165
- expected[:time] = Danica::Variable.new(name: :x)
165
+ expected[:time] = Danica::Wrapper::Variable.new(name: :x)
166
166
  end
167
167
 
168
168
  it do
@@ -215,7 +215,7 @@ describe Danica::Function do
215
215
 
216
216
  context 'when not initializing all variables' do
217
217
  subject { described_class::Spatial.new }
218
- let(:time) { Danica::Variable.new(name: :t) }
218
+ let(:time) { Danica::Wrapper::Variable.new(name: :t) }
219
219
 
220
220
  context 'when initialized with an empty variable set' do
221
221
  it do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Danica::Sum do
3
+ describe Danica::Operator::Addition do
4
4
  subject { described_class.new(10, 2) }
5
5
 
6
6
  it_behaves_like 'an object that respond to basic_methods'
@@ -9,10 +9,10 @@ describe Danica::Sum do
9
9
  it_behaves_like 'an object with + operation' do
10
10
  let(:subject_included) { 10 }
11
11
 
12
- context 'when other is also a sum' do
12
+ context 'when other is also a addition' do
13
13
  let(:other) { described_class.new(200, 5) }
14
14
 
15
- it 'includes the sum parcels' do
15
+ it 'includes the addition parcels' do
16
16
  expect(result).to include(200)
17
17
  end
18
18
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Danica::Cos do
3
+ describe Danica::Operator::Cos do
4
4
  subject { described_class.new(:x) }
5
5
 
6
6
  it_behaves_like 'an object that respond to basic_methods'
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Danica::Division do
3
+ describe Danica::Operator::Division do
4
4
  let(:variables) { [2, 4] }
5
5
  subject { described_class.new(*variables) }
6
6
 
@@ -23,11 +23,11 @@ describe Danica::Division do
23
23
  }
24
24
 
25
25
  describe 'more complex division' do
26
- describe 'of two sums' do
26
+ describe 'of two additions' do
27
27
  subject do
28
- Danica::Division.new(
29
- Danica::Sum.new(2, :x),
30
- Danica::Sum.new(3, :y)
28
+ Danica::Operator::Division.new(
29
+ Danica::Operator::Addition.new(2, :x),
30
+ Danica::Operator::Addition.new(3, :y)
31
31
  )
32
32
  end
33
33
 
@@ -36,7 +36,7 @@ describe Danica::Division do
36
36
  '(2 + x)/(3 + y)'
37
37
  end
38
38
 
39
- it 'groups sum' do
39
+ it 'groups addition' do
40
40
  expect(subject.to_gnu).to eq(expected)
41
41
  end
42
42
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Danica::Exponential do
3
+ describe Danica::Operator::Exponential do
4
4
  subject { described_class.new(2) }
5
5
 
6
6
  it_behaves_like 'an object that respond to basic_methods'
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Danica::Product do
3
+ describe Danica::Operator::Multiplication do
4
4
  subject { described_class.new(2,4) }
5
5
  it_behaves_like 'an object that respond to basic_methods'
6
6
 
7
7
  it_behaves_like 'an object with * operation' do
8
8
  let(:subject_included) { 4 }
9
9
 
10
- context 'when other is also a sum' do
10
+ context 'when other is also a addition' do
11
11
  let(:other) { described_class.new(200, 5) }
12
12
 
13
- it 'includes the sum parcels' do
13
+ it 'includes the addition parcels' do
14
14
  expect(result).to include(200)
15
15
  end
16
16
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Danica::Power do
3
+ describe Danica::Operator::Power do
4
4
  let(:variables) { [2, 4] }
5
5
  subject { described_class.new(*variables) }
6
6
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Danica::Sin do
3
+ describe Danica::Operator::Sin do
4
4
  subject { described_class.new(10) }
5
5
 
6
6
  it_behaves_like 'an object that respond to basic_methods'
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Danica::SquaredRoot do
3
+ describe Danica::Operator::SquaredRoot do
4
4
  subject { described_class.new(9) }
5
5
 
6
6
  it_behaves_like 'an object that respond to basic_methods'
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Danica::Constant do
3
+ describe Danica::Wrapper::Constant do
4
4
  subject { described_class.new(2.5, :M, :m) }
5
5
  let(:other) { described_class.new(3, :N, :n) }
6
6
 
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe Danica::Wrapper::Group do
4
+ let(:value) { 10 }
5
+ subject { described_class.new(value) }
6
+
7
+ it_behaves_like 'an object that respond to basic_methods'
8
+ it_behaves_like 'an object with basic operation'
9
+
10
+ describe '#to_f' do
11
+ it 'returns the float of value' do
12
+ expect(subject.to_f).to eq(10)
13
+ end
14
+
15
+ it { expect(subject.to_f).to be_a(Float) }
16
+ end
17
+
18
+ describe '#to_tex' do
19
+ context 'when value should be integer' do
20
+ let(:value) { 10.0 }
21
+
22
+ it 'returns the positive negative string' do
23
+ expect(subject.to_tex).to eq('\left(10\right)')
24
+ end
25
+ end
26
+
27
+ context 'when value should be float' do
28
+ let(:value) { 10.5 }
29
+
30
+ it 'returns the positive negative string' do
31
+ expect(subject.to_tex).to eq('\left(10.5\right)')
32
+ end
33
+ end
34
+ end
35
+
36
+ describe '#to_gnu' do
37
+ context 'when value should be integer' do
38
+ let(:value) { 10.0 }
39
+
40
+ it 'returns the value integer string' do
41
+ expect(subject.to_gnu).to eq('(10)')
42
+ end
43
+ end
44
+
45
+ context 'when value should be a float' do
46
+ let(:value) { 10.5 }
47
+
48
+ it 'returns the value float string' do
49
+ expect(subject.to_gnu).to eq('(10.5)')
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Danica::Negative do
4
- let(:value) { Danica::Number.new(10) }
3
+ describe Danica::Wrapper::Negative do
4
+ let(:value) { 10 }
5
5
  subject { described_class.new(value) }
6
6
 
7
7
  it_behaves_like 'an object that respond to basic_methods'
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Danica::Number do
3
+ describe Danica::Wrapper::Number do
4
4
  let(:value) { 10 }
5
5
  subject { described_class.new(value) }
6
6
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Danica::PositiveNegative do
4
- let(:value) { Danica::Number.new(10) }
3
+ describe Danica::Wrapper::PlusMinus do
4
+ let(:value) { 10 }
5
5
  subject { described_class.new(value) }
6
6
 
7
7
  it_behaves_like 'an object that respond to basic_methods'