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.
Files changed (123) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +71 -0
  3. data/.gitignore +6 -1
  4. data/.rubocop.yml +9 -0
  5. data/.rubocop_todo.yml +123 -0
  6. data/Dockerfile +22 -0
  7. data/Gemfile +2 -1
  8. data/README.md +9 -1
  9. data/Rakefile +4 -0
  10. data/config/check_specs.yml +13 -0
  11. data/config/rubycritc.rb +12 -0
  12. data/config/yardstick.rb +13 -0
  13. data/config/yardstick.yml +33 -0
  14. data/danica.gemspec +16 -9
  15. data/docker-compose.yml +14 -9
  16. data/lib/danica.rb +3 -1
  17. data/lib/danica/base_operations.rb +15 -7
  18. data/lib/danica/builder.rb +2 -0
  19. data/lib/danica/common.rb +24 -16
  20. data/lib/danica/dsl.rb +15 -9
  21. data/lib/danica/dsl/builder.rb +40 -0
  22. data/lib/danica/equation.rb +3 -3
  23. data/lib/danica/equation/builder.rb +2 -0
  24. data/lib/danica/exception.rb +14 -2
  25. data/lib/danica/expressable.rb +20 -16
  26. data/lib/danica/expression.rb +4 -2
  27. data/lib/danica/expression/gauss.rb +5 -5
  28. data/lib/danica/formatted.rb +34 -11
  29. data/lib/danica/function.rb +5 -3
  30. data/lib/danica/function/name.rb +2 -0
  31. data/lib/danica/operator.rb +13 -9
  32. data/lib/danica/operator/addition.rb +4 -7
  33. data/lib/danica/operator/chained.rb +4 -8
  34. data/lib/danica/operator/cos.rb +2 -1
  35. data/lib/danica/operator/division.rb +3 -2
  36. data/lib/danica/operator/exponential.rb +2 -1
  37. data/lib/danica/operator/functional.rb +3 -2
  38. data/lib/danica/operator/multiplication.rb +5 -7
  39. data/lib/danica/operator/power.rb +4 -3
  40. data/lib/danica/operator/sin.rb +2 -1
  41. data/lib/danica/operator/squared_root.rb +2 -1
  42. data/lib/danica/variables_holder.rb +27 -24
  43. data/lib/danica/variables_holder/alias_builder.rb +4 -4
  44. data/lib/danica/variables_holder/calculator.rb +2 -0
  45. data/lib/danica/variables_holder/store.rb +3 -2
  46. data/lib/danica/variables_holder/variables_builder.rb +2 -1
  47. data/lib/danica/version.rb +3 -1
  48. data/lib/danica/wrapper.rb +17 -9
  49. data/lib/danica/wrapper/constant.rb +10 -14
  50. data/lib/danica/wrapper/container.rb +4 -4
  51. data/lib/danica/wrapper/group.rb +3 -2
  52. data/lib/danica/wrapper/negative.rb +3 -1
  53. data/lib/danica/wrapper/number.rb +6 -3
  54. data/lib/danica/wrapper/plus_minus.rb +3 -1
  55. data/lib/danica/wrapper/variable.rb +13 -8
  56. data/scripts/check_readme.sh +6 -0
  57. data/scripts/rubycritic.sh +10 -0
  58. data/spec/integration/global/danica/formatted_spec.rb +87 -0
  59. data/spec/integration/global/danica/operator/addition_spec.rb +32 -0
  60. data/spec/integration/global/danica/operator/multiplication_spec.rb +106 -0
  61. data/spec/integration/{power_spec.rb → global/danica/operator/power_spec.rb} +4 -2
  62. data/spec/integration/global/danica/wrapper/negative_spec.rb +56 -0
  63. data/spec/integration/{plus_minus_spec.rb → global/danica/wrapper/plus_minus_spec.rb} +5 -4
  64. data/spec/integration/readme/constant_spec.rb +4 -1
  65. data/spec/integration/readme/danica/formatted_spec.rb +24 -0
  66. data/spec/integration/readme/danica_spec.rb +20 -4
  67. data/spec/integration/readme/equation_spec.rb +4 -2
  68. data/spec/integration/readme/expression_spec.rb +11 -8
  69. data/spec/integration/readme/function_spec.rb +11 -7
  70. data/spec/integration/readme/number_spec.rb +9 -8
  71. data/spec/integration/readme/operator_spec.rb +3 -1
  72. data/spec/integration/readme/variables_spec.rb +8 -6
  73. data/spec/lib/danica/common_spec.rb +79 -8
  74. data/spec/lib/danica/dsl_spec.rb +21 -18
  75. data/spec/lib/danica/equation_spec.rb +10 -8
  76. data/spec/lib/danica/expressable_spec.rb +5 -2
  77. data/spec/lib/danica/expression/gauss_spec.rb +6 -3
  78. data/spec/lib/danica/expression_spec.rb +48 -26
  79. data/spec/lib/danica/formatted_spec.rb +57 -24
  80. data/spec/lib/danica/function/name_spec.rb +3 -1
  81. data/spec/lib/danica/function_spec.rb +14 -10
  82. data/spec/lib/danica/operator/addition_spec.rb +18 -21
  83. data/spec/lib/danica/operator/cos_spec.rb +9 -8
  84. data/spec/lib/danica/operator/division_spec.rb +18 -17
  85. data/spec/lib/danica/operator/exponential_spec.rb +9 -8
  86. data/spec/lib/danica/operator/multiplication_spec.rb +19 -20
  87. data/spec/lib/danica/operator/power_spec.rb +17 -16
  88. data/spec/lib/danica/operator/sin_spec.rb +9 -8
  89. data/spec/lib/danica/operator/squared_root_spec.rb +9 -8
  90. data/spec/lib/danica/operator_spec.rb +13 -4
  91. data/spec/lib/danica/variables_holder/store_spec.rb +19 -13
  92. data/spec/lib/danica/variables_holder_spec.rb +76 -59
  93. data/spec/lib/danica/wrapper/constant_spec.rb +9 -2
  94. data/spec/lib/danica/wrapper/group_spec.rb +4 -1
  95. data/spec/lib/danica/wrapper/negative_spec.rb +4 -1
  96. data/spec/lib/danica/wrapper/number_spec.rb +8 -3
  97. data/spec/lib/danica/wrapper/plus_minus_spec.rb +4 -1
  98. data/spec/lib/danica/wrapper/variable_spec.rb +6 -3
  99. data/spec/lib/danica/wrapper_spec.rb +22 -16
  100. data/spec/lib/danica_spec.rb +6 -5
  101. data/spec/spec_helper.rb +3 -2
  102. data/spec/support/models/expression/baskara.rb +3 -3
  103. data/spec/support/models/expression/parabole.rb +2 -0
  104. data/spec/support/models/expression/quadratic_sum.rb +3 -1
  105. data/spec/support/models/expression/spatial.rb +2 -1
  106. data/spec/support/models/function/my_function.rb +3 -1
  107. data/spec/support/models/function/parabole.rb +1 -1
  108. data/spec/support/models/function/quadratic_sum.rb +2 -0
  109. data/spec/support/models/function/spatial.rb +2 -0
  110. data/spec/support/models/operator/inverse.rb +3 -1
  111. data/spec/support/models/operator/my_operator.rb +3 -1
  112. data/spec/support/models/variables_holder/dummy.rb +3 -1
  113. data/spec/support/shared_contexts/common.rb +4 -2
  114. data/spec/support/shared_examples/base_operations.rb +7 -4
  115. data/spec/support/shared_examples/common.rb +3 -1
  116. data/spec/support/shared_examples/operator/chained.rb +12 -6
  117. data/spec/support/shared_examples/operator/dual_term.rb +9 -8
  118. data/spec/support/shared_examples/operator/single_input.rb +7 -2
  119. data/spec/support/shared_examples/variable.rb +8 -4
  120. metadata +115 -30
  121. data/spec/integration/addition_spec.rb +0 -28
  122. data/spec/integration/multiplication_spec.rb +0 -44
  123. data/spec/integration/negative_spec.rb +0 -25
@@ -1,7 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Danica::Wrapper::Constant do
4
6
  subject { described_class.new(2.5, :M, :m) }
7
+
5
8
  let(:other) { described_class.new(3, :N, :n) }
6
9
 
7
10
  it_behaves_like 'an object that respond to basic_methods'
@@ -25,22 +28,26 @@ describe Danica::Wrapper::Constant do
25
28
  expect(subject.to(:tex)).to eq('M')
26
29
  end
27
30
  end
31
+
28
32
  context "when requesting 'tex'" do
29
33
  it 'has a string for latex' do
30
34
  expect(subject.to('tex')).to eq('M')
31
35
  end
32
36
  end
37
+
33
38
  context 'when requesting :gnu' do
34
39
  it 'has a string for gnu' do
35
40
  expect(subject.to(:gnu)).to eq('m')
36
41
  end
37
42
  end
43
+
38
44
  context "when requesting 'gnu'" do
39
45
  it 'has a string for gnu' do
40
46
  expect(subject.to('gnu')).to eq('m')
41
47
  end
42
48
  end
43
- context "when requesting wrong format" do
49
+
50
+ context 'when requesting wrong format' do
44
51
  it do
45
52
  expect do
46
53
  subject.to('format')
@@ -95,9 +102,9 @@ describe Danica::Wrapper::Constant do
95
102
 
96
103
  context 'with same values' do
97
104
  let(:other) { described_class.new(2.5, :M, :m) }
105
+
98
106
  it { expect(subject).to eq(other) }
99
107
  end
100
108
  end
101
109
  end
102
110
  end
103
-
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Danica::Wrapper::Group do
4
- let(:value) { 10 }
5
6
  subject { described_class.new(value) }
6
7
 
8
+ let(:value) { 10 }
9
+
7
10
  it_behaves_like 'an object that respond to basic_methods'
8
11
  it_behaves_like 'an object with basic operation'
9
12
 
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Danica::Wrapper::Negative do
4
- let(:value) { 10 }
5
6
  subject { described_class.new(value) }
6
7
 
8
+ let(:value) { 10 }
9
+
7
10
  it_behaves_like 'an object that respond to basic_methods'
8
11
  it_behaves_like 'an object with basic operation'
9
12
 
@@ -1,20 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Danica::Wrapper::Number do
4
- let(:value) { 10 }
5
6
  subject { described_class.new(value) }
6
7
 
8
+ let(:value) { 10 }
9
+
7
10
  it_behaves_like 'an object that respond to basic_methods'
8
11
 
9
12
  it_behaves_like 'an object with basic operation'
10
13
 
11
14
  describe '#valued?' do
12
15
  context 'when value is present' do
13
- it { expect(subject.valued?).to be_truthy }
16
+ it { expect(subject).to be_valued }
14
17
  end
18
+
15
19
  context 'when value is not present' do
16
20
  let(:value) { false }
17
- it { expect(subject.valued?).to be_falsey }
21
+
22
+ it { expect(subject).not_to be_valued }
18
23
  end
19
24
  end
20
25
 
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Danica::Wrapper::PlusMinus do
4
- let(:value) { 10 }
5
6
  subject { described_class.new(value) }
6
7
 
8
+ let(:value) { 10 }
9
+
7
10
  it_behaves_like 'an object that respond to basic_methods'
8
11
  it_behaves_like 'an object with basic operation'
9
12
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Danica::Wrapper::Variable do
@@ -10,13 +12,13 @@ describe Danica::Wrapper::Variable do
10
12
  it 'can be initialize from nil value' do
11
13
  expect do
12
14
  described_class.new(nil)
13
- end
15
+ end.not_to raise_error
14
16
  end
15
17
 
16
18
  it 'can be initialize from nil name' do
17
19
  expect do
18
20
  described_class.new(name: nil)
19
- end
21
+ end.not_to raise_error
20
22
  end
21
23
 
22
24
  describe '#to_f' do
@@ -25,9 +27,10 @@ describe Danica::Wrapper::Variable do
25
27
  end
26
28
 
27
29
  context 'when variable has value' do
28
- let(:value) { 100 }
29
30
  subject { described_class.new(value: value) }
30
31
 
32
+ let(:value) { 100 }
33
+
31
34
  it 'returns the value' do
32
35
  expect(subject.to_f).to eq(value)
33
36
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  class Danica::Wrapper::Dummy
@@ -24,25 +26,29 @@ shared_examples 'a value wrapper' do |examples|
24
26
  end
25
27
 
26
28
  describe Danica::Wrapper do
27
- let(:clazz) { described_class::Dummy }
28
29
  subject { clazz.new(value) }
29
30
 
31
+ let(:clazz) { described_class::Dummy }
32
+
30
33
  describe 'wrap_value' do
31
- it_behaves_like 'a value wrapper', {
32
- x: Danica::Wrapper::Variable,
33
- 'x' => Danica::Wrapper::Variable,
34
- 10 => Danica::Wrapper::Number,
35
- -10 => Danica::Wrapper::Negative,
36
- { name: :x } => Danica::Wrapper::Variable
37
- }
38
-
39
- context 'when value is a Hash' do
40
- context 'but it is a constant' do
41
- let(:value) { { value: 10, latex: :x, gnuplot: :X } }
42
-
43
- it do
44
- expect(subject.wrapped_value.content).to be_a(Danica::Wrapper::Constant)
45
- end
34
+ it_behaves_like 'a value wrapper',
35
+ x: Danica::Wrapper::Variable,
36
+ 'x' => Danica::Wrapper::Variable,
37
+ 10 => Danica::Wrapper::Number,
38
+ 10.5 => Danica::Wrapper::Number,
39
+ -10 => Danica::Wrapper::Negative,
40
+ { name: :x } => Danica::Wrapper::Variable,
41
+ { value: 10, latex: :x, gnuplot: :X } => Danica::Wrapper::Constant,
42
+ Danica::Wrapper::Variable.new(:x).tex => Danica::Wrapper::Variable,
43
+ Danica.build(:x) { x } => Danica::Expression
44
+
45
+ context 'when value is non accepted' do
46
+ let(:value) { Object.new }
47
+
48
+ it do
49
+ expect do
50
+ subject.wrapped_value.content
51
+ end.to raise_error(Danica::Exception::InvalidInput)
46
52
  end
47
53
  end
48
54
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Danica do
@@ -10,13 +12,13 @@ describe Danica do
10
12
  end
11
13
 
12
14
  it 'returns the expected addition' do
13
- expect(result.expression_block).to eq(Danica::Operator::Addition.new(1,2))
15
+ expect(result.expression_block).to eq(Danica::Operator::Addition.new(1, 2))
14
16
  end
15
17
  end
16
18
 
17
19
  context 'when creating a power of addition and multiplication' do
18
20
  let(:block) do
19
- proc { power(addition(1, 2), multiplication(2,3)) }
21
+ proc { power(addition(1, 2), multiplication(2, 3)) }
20
22
  end
21
23
  let(:expected) do
22
24
  Danica::Operator::Power.new(
@@ -70,7 +72,7 @@ describe Danica do
70
72
 
71
73
  context 'when defining a negative output' do
72
74
  let(:block) do
73
- proc { -(sum(2, 3)) }
75
+ proc { -sum(2, 3) }
74
76
  end
75
77
 
76
78
  let(:expected) do
@@ -83,7 +85,7 @@ describe Danica do
83
85
  expect(result.expression_block).to eq(expected)
84
86
  end
85
87
 
86
- context 'for a number' do
88
+ context 'when it is a number' do
87
89
  let(:block) do
88
90
  proc { -num(2) }
89
91
  end
@@ -99,4 +101,3 @@ describe Danica do
99
101
  end
100
102
  end
101
103
  end
102
-
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'simplecov'
2
4
 
3
5
  SimpleCov.profiles.define 'gem' do
@@ -8,7 +10,6 @@ SimpleCov.start 'gem'
8
10
  require 'pry-nav'
9
11
  require 'danica'
10
12
 
11
-
12
13
  # This file was generated by the `rspec --init` command. Conventionally, all
13
14
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
14
15
  # Require this file using `require "spec_helper"` to ensure that it is only
@@ -18,7 +19,7 @@ require 'danica'
18
19
 
19
20
  # Requires supporting ruby files with custom matchers and macros, etc,
20
21
  # in spec/support/ and its subdirectories.
21
- Dir['./spec/support/**/*.rb'].each { |f| require f }
22
+ Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
22
23
 
23
24
  RSpec.configure do |config|
24
25
  config.treat_symbols_as_metadata_keys_with_true_values = true
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica
2
4
  class Expression::Baskara < Expression.build(:a, :b, :c) { numerator / denominator }
3
-
4
5
  private
5
6
 
6
7
  def numerator
7
- negative(b) + Wrapper::PlusMinus.new(squared_root(delta))
8
+ negative(b) + Wrapper::PlusMinus.new(squared_root(delta))
8
9
  end
9
10
 
10
11
  def denominator
@@ -16,4 +17,3 @@ module Danica
16
17
  end
17
18
  end
18
19
  end
19
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica
2
4
  class Parabole < Expression.build(:x) { power(x, 2) }
3
5
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica
2
4
  class Expression
3
- class QuadraticSum < build(:x, :y) { (x + y) ** 2 }
5
+ class QuadraticSum < build(:x, :y) { (x + y)**2 }
4
6
  end
5
7
  end
6
8
  end
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica
2
4
  class Expression::Spatial < Expression.build(:time, :acceleration, :initial_space, :initial_velocity) { addition(parcels) }
3
-
4
5
  private
5
6
 
6
7
  def parcels
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Danica::Function::MyFunction < Danica::Function
2
4
  variables :x, :y
3
5
 
4
6
  def function_block
5
- x ** 2 + y
7
+ x**2 + y
6
8
  end
7
9
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Danica
3
4
  class Function::Parabole < Function.build(:x) { Danica::Parabole.new }
@@ -13,4 +14,3 @@ module Danica
13
14
  end
14
15
  end
15
16
  end
16
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../expression/quadratic_sum'
2
4
 
3
5
  module Danica
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica
2
4
  class Function::Spatial < Function
3
5
  variables :time, :acceleration, :initial_space, :initial_velocity
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Danica::Operator::Inverse < Danica::Operator
2
4
  variables :value
3
5
 
4
6
  def to_f
5
- value.to_f ** -1 #Do not worry with nil value as this has been implemented already raising Danica::Exception::NotDefined
7
+ value.to_f**-1 # Do not worry with nil value as this has been implemented already raising Danica::Exception::NotDefined
6
8
  end
7
9
 
8
10
  def to_tex
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class MyOperator < Danica::Operator
2
4
  variables :x
3
5
 
4
6
  def to_f
5
- (x ** Danica::PI).to_f
7
+ (x**Danica::PI).to_f
6
8
  end
7
9
 
8
10
  def to_tex
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica
2
4
  module VariablesHolder
3
5
  class Dummy
@@ -9,7 +11,7 @@ module Danica
9
11
  delegate :to, :to_f, to: :block
10
12
 
11
13
  def block
12
- x ** y + z
14
+ x**y + z
13
15
  end
14
16
  end
15
17
 
@@ -1,5 +1,7 @@
1
- shared_context 'variables are initialized' do |arguments, *names|
1
+ # frozen_string_literal: true
2
+
3
+ shared_context 'when variables are initialized' do |arguments, *names|
2
4
  names.each do |key|
3
- let(key) { arguments[key.to_sym] }
5
+ let(key) { arguments[key.to_sym] }
4
6
  end
5
7
  end
@@ -1,5 +1,7 @@
1
- shared_examples 'an object with basic operation' do |operations:%i(+ - * / **), ignore:[]|
2
- (operations - [ ignore ].flatten).each do |operation|
1
+ # frozen_string_literal: true
2
+
3
+ shared_examples 'an object with basic operation' do |operations: %i[+ - * / **], ignore: []|
4
+ (operations - [ignore].flatten).each do |operation|
3
5
  it_behaves_like "an object with #{operation} operation"
4
6
  end
5
7
  end
@@ -25,6 +27,7 @@ shared_examples 'an object with + operation' do
25
27
 
26
28
  context 'when operating as reverse' do
27
29
  let(:result) { Danica::Wrapper::Number.new(other) + subject }
30
+
28
31
  it_behaves_like 'an object with an operation', Danica::Operator::Addition
29
32
  end
30
33
  end
@@ -38,6 +41,7 @@ shared_examples 'an object with * operation' do
38
41
 
39
42
  context 'when operating as reverse' do
40
43
  let(:result) { Danica::Wrapper::Number.new(other) * subject }
44
+
41
45
  it_behaves_like 'an object with an operation', Danica::Operator::Multiplication
42
46
  end
43
47
  end
@@ -77,7 +81,7 @@ end
77
81
 
78
82
  shared_examples 'an object with ** operation' do
79
83
  let(:other) { 104 }
80
- let(:result) { subject ** other }
84
+ let(:result) { subject**other }
81
85
 
82
86
  it { expect(result).to be_a(Danica::Operator::Power) }
83
87
 
@@ -89,4 +93,3 @@ shared_examples 'an object with ** operation' do
89
93
  expect(result.exponent).to eq(Danica::Wrapper::Number.new(other))
90
94
  end
91
95
  end
92
-