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,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Danica::Function::Name do
4
- let(:x) { Danica::Wrapper::Variable.new(name: :x, latex: '\mu', gnuplot: 'u')}
6
+ let(:x) { Danica::Wrapper::Variable.new(name: :x, latex: '\mu', gnuplot: 'u') }
5
7
  let(:subject) { described_class.new(name: :f, variables: [x]) }
6
8
 
7
9
  it_behaves_like 'an object that respond to basic_methods'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  shared_examples 'a generically generated function' do
@@ -28,8 +30,9 @@ end
28
30
 
29
31
  describe Danica::Function do
30
32
  subject { function }
33
+
31
34
  let(:function) { function_class.new }
32
- let(:variables) { %i(x y) }
35
+ let(:variables) { %i[x y] }
33
36
  let(:function_class) do
34
37
  described_class.build(*variables) do
35
38
  Danica::Operator::Power.new(x, y)
@@ -37,12 +40,13 @@ describe Danica::Function do
37
40
  end
38
41
 
39
42
  describe '.for' do
40
- let(:expression_class) { Danica::Expression::Gauss }
41
- let(:expression) { expression_class.new }
42
43
  subject do
43
44
  described_class.for(expression_class).new
44
45
  end
45
46
 
47
+ let(:expression_class) { Danica::Expression::Gauss }
48
+ let(:expression) { expression_class.new }
49
+
46
50
  it 'returns a function' do
47
51
  expect(subject).to be_a(described_class)
48
52
  end
@@ -111,7 +115,7 @@ describe Danica::Function do
111
115
  let(:function_class) { Danica::Function::SaddleParabole }
112
116
 
113
117
  it 'has the defined variables on class definition' do
114
- expect(function_class.variables_names).to eq([:x, :y])
118
+ expect(function_class.variables_names).to eq(%i[x y])
115
119
  end
116
120
 
117
121
  it 'has the defined variables' do
@@ -143,6 +147,7 @@ describe Danica::Function do
143
147
  f.name = :f
144
148
  end
145
149
  end
150
+
146
151
  it_behaves_like 'a generically generated function'
147
152
  end
148
153
 
@@ -157,9 +162,8 @@ describe Danica::Function do
157
162
 
158
163
  context 'when changing the function variables' do
159
164
  it 'changes the name variables' do
160
- expect do
161
- function.x = 2
162
- end.to change { function.name.variables.map(&:content) }
165
+ expect { function.x = 2 }
166
+ .to(change { function.name.variables.map(&:content) })
163
167
  end
164
168
  end
165
169
  end
@@ -174,7 +178,7 @@ describe Danica::Function do
174
178
  expect(function.to_tex).to eq('f(x, y) = x^{y}')
175
179
  end
176
180
 
177
- context 'and one of the variables is changed' do
181
+ context 'when one of the variables is changed' do
178
182
  it 'uses the new variable value' do
179
183
  expect do
180
184
  function.y = 2
@@ -192,7 +196,7 @@ describe Danica::Function do
192
196
  expect(function.to_tex).to eq('f(y) = \pi^{y}')
193
197
  end
194
198
 
195
- context 'from a hash' do
199
+ context 'when name is in the hash' do
196
200
  let(:function) do
197
201
  function_class.new(name: :f, x: { latex: '\pi', gnuplot: 'pi', value: 3.14 })
198
202
  end
@@ -244,7 +248,7 @@ describe Danica::Function do
244
248
  expect(function.to_gnu).to eq('f(y) = pi**(y)')
245
249
  end
246
250
 
247
- context 'from a hash' do
251
+ context 'when name is in the hash' do
248
252
  let(:function) do
249
253
  function_class.new(name: :f, x: { latex: '\pi', gnuplot: 'pi', value: 3.14 })
250
254
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Danica::Operator::Addition do
@@ -11,34 +13,29 @@ describe Danica::Operator::Addition do
11
13
 
12
14
  it_behaves_like 'an object that respond to basic_methods'
13
15
 
14
- it_behaves_like 'an object with basic operation', ignore: %i(+ -)
16
+ it_behaves_like 'an object with basic operation', ignore: %i[+ -]
15
17
  it_behaves_like 'an object with + operation' do
16
- let(:subject_included) { 10 }
17
-
18
18
  context 'when other is also a addition' do
19
19
  let(:other) { described_class.new(200, 5) }
20
20
 
21
21
  it 'includes the addition parcels' do
22
- expect(result).to include(200)
22
+ expect(result.to_gnu).to eq('10 + 2 + 200 + 5')
23
23
  end
24
24
  end
25
25
  end
26
- it_behaves_like 'an object with - operation' do
27
- let(:subject_included) { 10 }
28
- end
26
+ it_behaves_like 'an object with - operation'
29
27
 
30
- it_behaves_like 'a operator that joins many variables with same operation', {
31
- calculated: 10,
32
- numeric_variables: [ 1.5, 3.0, 3.5 ],
33
- tex: {
34
- string_expected: 'X1 + X2 + X3 + X4',
35
- integer_expected: '1.5 + 3 + X3 + X4',
36
- float_expected: '1.5 + 3 + 3.5 + X4'
37
- },
38
- gnu: {
39
- string_expected: 'X1 + X2 + X3 + X4',
40
- integer_expected: '1.5 + 3 + X3 + X4',
41
- float_expected: '1.5 + 3 + 3.5 + X4'
42
- }
43
- }
28
+ it_behaves_like 'a operator that joins many variables with same operation',
29
+ calculated: 10,
30
+ numeric_variables: [1.5, 3.0, 3.5],
31
+ tex: {
32
+ string_expected: 'X1 + X2 + X3 + X4',
33
+ integer_expected: '1.5 + 3 + X3 + X4',
34
+ float_expected: '1.5 + 3 + 3.5 + X4'
35
+ },
36
+ gnu: {
37
+ string_expected: 'X1 + X2 + X3 + X4',
38
+ integer_expected: '1.5 + 3 + X3 + X4',
39
+ float_expected: '1.5 + 3 + 3.5 + X4'
40
+ }
44
41
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Danica::Operator::Cos do
@@ -6,12 +8,11 @@ describe Danica::Operator::Cos do
6
8
  it_behaves_like 'an object that respond to basic_methods'
7
9
  it_behaves_like 'an object with basic operation'
8
10
 
9
- it_behaves_like 'a operator with a single input value', {
10
- variable_value: Math::PI,
11
- expected_number: -1.0,
12
- expected_number_tex: 'cos(3.141592653589793)',
13
- expected_number_gnu: 'cos(3.141592653589793)',
14
- expected_tex: 'cos(X)',
15
- expected_gnu: 'cos(X)'
16
- }
11
+ it_behaves_like 'a operator with a single input value',
12
+ variable_value: Math::PI,
13
+ expected_number: -1.0,
14
+ expected_number_tex: 'cos(3.141592653589793)',
15
+ expected_number_gnu: 'cos(3.141592653589793)',
16
+ expected_tex: 'cos(X)',
17
+ expected_gnu: 'cos(X)'
17
18
  end
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Danica::Operator::Division do
4
- let(:variables) { [2, 4] }
5
6
  subject { described_class.new(*variables) }
6
7
 
8
+ let(:variables) { [2, 4] }
9
+
7
10
  describe '#numerator' do
8
11
  it 'returns the numerator' do
9
12
  expect(subject.numerator).to eq(Danica::Wrapper::Number.new(2))
@@ -19,25 +22,24 @@ describe Danica::Operator::Division do
19
22
  it_behaves_like 'an object that respond to basic_methods'
20
23
  it_behaves_like 'an object with basic operation'
21
24
 
22
- it_behaves_like 'a operator that has two terms', :division, {
23
- values: [ 2, 4 ],
24
- calculated: 1.0 / 2.0,
25
- to_tex: {
26
- string_expected: '\frac{X1}{X2}',
27
- numeric_string_expected: '\frac{2}{4}',
28
- partial_string_expected: '\frac{2}{X2}'
29
- },
30
- to_gnu: {
31
- string_expected: '(X1)/(X2)',
32
- numeric_string_expected: '(2)/(4)',
33
- partial_string_expected: '(2)/(X2)'
34
- }
35
- }
25
+ it_behaves_like 'a operator that has two terms', :division,
26
+ values: [2, 4],
27
+ calculated: 1.0 / 2.0,
28
+ to_tex: {
29
+ string_expected: '\frac{X1}{X2}',
30
+ numeric_string_expected: '\frac{2}{4}',
31
+ partial_string_expected: '\frac{2}{X2}'
32
+ },
33
+ to_gnu: {
34
+ string_expected: '(X1)/(X2)',
35
+ numeric_string_expected: '(2)/(4)',
36
+ partial_string_expected: '(2)/(X2)'
37
+ }
36
38
 
37
39
  describe 'more complex division' do
38
40
  describe 'of two additions' do
39
41
  subject do
40
- Danica::Operator::Division.new(
42
+ described_class.new(
41
43
  Danica::Operator::Addition.new(2, :x),
42
44
  Danica::Operator::Addition.new(3, :y)
43
45
  )
@@ -55,4 +57,3 @@ describe Danica::Operator::Division do
55
57
  end
56
58
  end
57
59
  end
58
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Danica::Operator::Exponential do
@@ -6,12 +8,11 @@ describe Danica::Operator::Exponential do
6
8
  it_behaves_like 'an object that respond to basic_methods'
7
9
  it_behaves_like 'an object with basic operation'
8
10
 
9
- it_behaves_like 'a operator with a single input value', {
10
- variable_value: 2,
11
- expected_number: Math.exp(2),
12
- expected_number_tex: 'e^{2}',
13
- expected_number_gnu: 'exp(2)',
14
- expected_tex: 'e^{X}',
15
- expected_gnu: 'exp(X)'
16
- }
11
+ it_behaves_like 'a operator with a single input value',
12
+ variable_value: 2,
13
+ expected_number: Math.exp(2),
14
+ expected_number_tex: 'e^{2}',
15
+ expected_number_gnu: 'exp(2)',
16
+ expected_tex: 'e^{X}',
17
+ expected_gnu: 'exp(X)'
17
18
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Danica::Operator::Multiplication do
4
- subject { described_class.new(2,4) }
6
+ subject { described_class.new(2, 4) }
5
7
 
6
8
  it 'initializes from array' do
7
9
  expect do
@@ -12,30 +14,27 @@ describe Danica::Operator::Multiplication do
12
14
  it_behaves_like 'an object that respond to basic_methods'
13
15
 
14
16
  it_behaves_like 'an object with * operation' do
15
- let(:subject_included) { 4 }
16
-
17
- context 'when other is also a addition' do
17
+ context 'when other is also a multiplication' do
18
18
  let(:other) { described_class.new(200, 5) }
19
19
 
20
- it 'includes the addition parcels' do
21
- expect(result).to include(200)
20
+ it 'includes the addition parcels in the result' do
21
+ expect(result.to_gnu).to eq('2 * 4 * 200 * 5')
22
22
  end
23
23
  end
24
24
  end
25
25
  it_behaves_like 'an object with basic operation', ignore: :*
26
26
 
27
- it_behaves_like 'a operator that joins many variables with same operation', {
28
- calculated: 24,
29
- numeric_variables: [ 1.5, 2, 3.5 ],
30
- tex: {
31
- string_expected: %w(X1 X2 X3 X4).join(' \cdot '),
32
- integer_expected: %w(1.5 2 X3 X4).join(' \cdot '),
33
- float_expected: %w(1.5 2 3.5 X4).join(' \cdot ')
34
- },
35
- gnu: {
36
- string_expected: %w(X1 X2 X3 X4).join(' * '),
37
- integer_expected: %w(1.5 2 X3 X4).join(' * '),
38
- float_expected: %w(1.5 2 3.5 X4).join(' * '),
39
- }
40
- }
27
+ it_behaves_like 'a operator that joins many variables with same operation',
28
+ calculated: 24,
29
+ numeric_variables: [1.5, 2, 3.5],
30
+ tex: {
31
+ string_expected: %w[X1 X2 X3 X4].join(' \cdot '),
32
+ integer_expected: %w[1.5 2 X3 X4].join(' \cdot '),
33
+ float_expected: %w[1.5 2 3.5 X4].join(' \cdot ')
34
+ },
35
+ gnu: {
36
+ string_expected: %w[X1 X2 X3 X4].join(' * '),
37
+ integer_expected: %w[1.5 2 X3 X4].join(' * '),
38
+ float_expected: %w[1.5 2 3.5 X4].join(' * ')
39
+ }
41
40
  end
@@ -1,25 +1,26 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Danica::Operator::Power do
4
- let(:variables) { [2, 4] }
5
6
  subject { described_class.new(*variables) }
6
7
 
8
+ let(:variables) { [2, 4] }
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
 
10
- it_behaves_like 'a operator that has two terms', :power, {
11
- values: [ 3, 2 ],
12
- calculated: 9.0,
13
- to_tex: {
14
- string_expected: 'X1^{X2}',
15
- numeric_string_expected: '3^{2}',
16
- partial_string_expected: '3^{X2}'
17
- },
18
- to_gnu: {
19
- string_expected: 'X1**(X2)',
20
- numeric_string_expected: '3**(2)',
21
- partial_string_expected: '3**(X2)'
22
- }
23
- }
13
+ it_behaves_like 'a operator that has two terms', :power,
14
+ values: [3, 2],
15
+ calculated: 9.0,
16
+ to_tex: {
17
+ string_expected: 'X1^{X2}',
18
+ numeric_string_expected: '3^{2}',
19
+ partial_string_expected: '3^{X2}'
20
+ },
21
+ to_gnu: {
22
+ string_expected: 'X1**(X2)',
23
+ numeric_string_expected: '3**(2)',
24
+ partial_string_expected: '3**(X2)'
25
+ }
24
26
  end
25
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Danica::Operator::Sin do
@@ -6,12 +8,11 @@ describe Danica::Operator::Sin do
6
8
  it_behaves_like 'an object that respond to basic_methods'
7
9
  it_behaves_like 'an object with basic operation'
8
10
 
9
- it_behaves_like 'a operator with a single input value', {
10
- variable_value: Math::PI / 2.0,
11
- expected_number: 1.0,
12
- expected_number_tex: 'sin(1.5707963267948966)',
13
- expected_number_gnu: 'sin(1.5707963267948966)',
14
- expected_tex: 'sin(X)',
15
- expected_gnu: 'sin(X)'
16
- }
11
+ it_behaves_like 'a operator with a single input value',
12
+ variable_value: Math::PI / 2.0,
13
+ expected_number: 1.0,
14
+ expected_number_tex: 'sin(1.5707963267948966)',
15
+ expected_number_gnu: 'sin(1.5707963267948966)',
16
+ expected_tex: 'sin(X)',
17
+ expected_gnu: 'sin(X)'
17
18
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Danica::Operator::SquaredRoot do
@@ -6,12 +8,11 @@ describe Danica::Operator::SquaredRoot do
6
8
  it_behaves_like 'an object that respond to basic_methods'
7
9
  it_behaves_like 'an object with basic operation'
8
10
 
9
- it_behaves_like 'a operator with a single input value', {
10
- variable_value: 9,
11
- expected_number: 3.0,
12
- expected_number_tex: '\sqrt{9}',
13
- expected_number_gnu: 'sqrt(9)',
14
- expected_tex: '\sqrt{X}',
15
- expected_gnu: 'sqrt(X)'
16
- }
11
+ it_behaves_like 'a operator with a single input value',
12
+ variable_value: 9,
13
+ expected_number: 3.0,
14
+ expected_number_tex: '\sqrt{9}',
15
+ expected_number_gnu: 'sqrt(9)',
16
+ expected_tex: '\sqrt{X}',
17
+ expected_gnu: 'sqrt(X)'
17
18
  end
@@ -1,31 +1,40 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  class Danica::Operator::Dummy < Danica::Operator
4
6
  variables :a, :b
5
7
 
6
- def to(*args)
8
+ def to(*_args)
7
9
  a + b
8
10
  end
9
11
  end
10
12
 
11
13
  describe Danica::Operator do
14
+ subject { clazz.new(*variables) }
15
+
12
16
  let(:variables) { [2, 4] }
13
17
  let(:clazz) { described_class::Dummy }
14
- subject { clazz.new(*variables) }
15
18
 
16
19
  it_behaves_like 'an object that respond to basic_methods'
17
20
 
18
21
  describe 'variables assignment' do
19
- it 'assignes the variables tpo its places' do
22
+ it 'assignes first variable' do
20
23
  expect(subject.a).to eq(Danica::Wrapper::Number.new(2))
24
+ end
25
+
26
+ it 'assignes second variable' do
21
27
  expect(subject.b).to eq(Danica::Wrapper::Number.new(4))
22
28
  end
23
29
 
24
30
  context 'when initializing with a hash' do
25
31
  let(:variables) { [{ name: :A, value: 2 }, { name: :B, value: 4 }] }
26
32
 
27
- it 'assignes the variables tpo its places' do
33
+ it 'assignes first variable' do
28
34
  expect(subject.a).to eq(Danica::Wrapper::Variable.new(name: :A, value: 2))
35
+ end
36
+
37
+ it 'assignes second variable' do
29
38
  expect(subject.b).to eq(Danica::Wrapper::Variable.new(name: :B, value: 4))
30
39
  end
31
40
  end