danica 2.7.4 → 2.7.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +28 -0
  3. data/.gitignore +6 -1
  4. data/.rubocop.yml +9 -0
  5. data/.rubocop_todo.yml +100 -0
  6. data/Dockerfile +26 -0
  7. data/Gemfile +2 -1
  8. data/Rakefile +4 -0
  9. data/config/rubycritc.rb +12 -0
  10. data/config/yardstick.rb +13 -0
  11. data/config/yardstick.yml +33 -0
  12. data/danica.gemspec +14 -7
  13. data/docker-compose.yml +14 -9
  14. data/lib/danica.rb +2 -1
  15. data/lib/danica/base_operations.rb +2 -0
  16. data/lib/danica/builder.rb +2 -0
  17. data/lib/danica/common.rb +5 -2
  18. data/lib/danica/dsl.rb +8 -6
  19. data/lib/danica/dsl/builder.rb +3 -1
  20. data/lib/danica/equation.rb +3 -3
  21. data/lib/danica/equation/builder.rb +2 -0
  22. data/lib/danica/exception.rb +3 -2
  23. data/lib/danica/expressable.rb +14 -8
  24. data/lib/danica/expression.rb +4 -2
  25. data/lib/danica/expression/gauss.rb +5 -5
  26. data/lib/danica/formatted.rb +4 -2
  27. data/lib/danica/function.rb +5 -3
  28. data/lib/danica/function/name.rb +2 -0
  29. data/lib/danica/operator.rb +12 -9
  30. data/lib/danica/operator/addition.rb +4 -3
  31. data/lib/danica/operator/chained.rb +4 -3
  32. data/lib/danica/operator/cos.rb +2 -1
  33. data/lib/danica/operator/division.rb +2 -1
  34. data/lib/danica/operator/exponential.rb +2 -1
  35. data/lib/danica/operator/functional.rb +3 -2
  36. data/lib/danica/operator/multiplication.rb +4 -2
  37. data/lib/danica/operator/power.rb +4 -3
  38. data/lib/danica/operator/sin.rb +2 -1
  39. data/lib/danica/operator/squared_root.rb +2 -1
  40. data/lib/danica/variables_holder.rb +7 -4
  41. data/lib/danica/variables_holder/alias_builder.rb +4 -4
  42. data/lib/danica/variables_holder/calculator.rb +2 -0
  43. data/lib/danica/variables_holder/store.rb +3 -2
  44. data/lib/danica/variables_holder/variables_builder.rb +2 -1
  45. data/lib/danica/version.rb +3 -1
  46. data/lib/danica/wrapper.rb +11 -9
  47. data/lib/danica/wrapper/constant.rb +9 -14
  48. data/lib/danica/wrapper/container.rb +2 -3
  49. data/lib/danica/wrapper/group.rb +2 -2
  50. data/lib/danica/wrapper/negative.rb +2 -1
  51. data/lib/danica/wrapper/number.rb +4 -3
  52. data/lib/danica/wrapper/plus_minus.rb +2 -1
  53. data/lib/danica/wrapper/variable.rb +10 -8
  54. data/scripts/check_readme.sh +6 -0
  55. data/scripts/rubycritic.sh +10 -0
  56. data/spec/integration/global/danica/formatted_spec.rb +87 -0
  57. data/spec/integration/global/danica/operator/addition_spec.rb +32 -0
  58. data/spec/integration/{multiplication_spec.rb → global/danica/operator/multiplication_spec.rb} +12 -9
  59. data/spec/integration/{power_spec.rb → global/danica/operator/power_spec.rb} +4 -2
  60. data/spec/integration/{negative_spec.rb → global/danica/wrapper/negative_spec.rb} +9 -8
  61. data/spec/integration/{plus_minus_spec.rb → global/danica/wrapper/plus_minus_spec.rb} +5 -4
  62. data/spec/integration/readme/constant_spec.rb +4 -1
  63. data/spec/integration/readme/danica/formatted_spec.rb +24 -0
  64. data/spec/integration/readme/danica_spec.rb +20 -4
  65. data/spec/integration/readme/equation_spec.rb +4 -2
  66. data/spec/integration/readme/expression_spec.rb +11 -8
  67. data/spec/integration/readme/function_spec.rb +11 -7
  68. data/spec/integration/readme/number_spec.rb +9 -8
  69. data/spec/integration/readme/operator_spec.rb +3 -1
  70. data/spec/integration/readme/variables_spec.rb +8 -6
  71. data/spec/lib/danica/common_spec.rb +23 -9
  72. data/spec/lib/danica/dsl_spec.rb +5 -2
  73. data/spec/lib/danica/equation_spec.rb +10 -8
  74. data/spec/lib/danica/expressable_spec.rb +5 -2
  75. data/spec/lib/danica/expression/gauss_spec.rb +6 -3
  76. data/spec/lib/danica/expression_spec.rb +48 -26
  77. data/spec/lib/danica/formatted_spec.rb +20 -14
  78. data/spec/lib/danica/function/name_spec.rb +3 -1
  79. data/spec/lib/danica/function_spec.rb +14 -10
  80. data/spec/lib/danica/operator/addition_spec.rb +16 -15
  81. data/spec/lib/danica/operator/cos_spec.rb +9 -8
  82. data/spec/lib/danica/operator/division_spec.rb +18 -17
  83. data/spec/lib/danica/operator/exponential_spec.rb +9 -8
  84. data/spec/lib/danica/operator/multiplication_spec.rb +16 -15
  85. data/spec/lib/danica/operator/power_spec.rb +17 -16
  86. data/spec/lib/danica/operator/sin_spec.rb +9 -8
  87. data/spec/lib/danica/operator/squared_root_spec.rb +9 -8
  88. data/spec/lib/danica/operator_spec.rb +13 -4
  89. data/spec/lib/danica/variables_holder/store_spec.rb +19 -13
  90. data/spec/lib/danica/variables_holder_spec.rb +76 -59
  91. data/spec/lib/danica/wrapper/constant_spec.rb +9 -2
  92. data/spec/lib/danica/wrapper/group_spec.rb +4 -1
  93. data/spec/lib/danica/wrapper/negative_spec.rb +4 -1
  94. data/spec/lib/danica/wrapper/number_spec.rb +8 -3
  95. data/spec/lib/danica/wrapper/plus_minus_spec.rb +4 -1
  96. data/spec/lib/danica/wrapper/variable_spec.rb +6 -3
  97. data/spec/lib/danica/wrapper_spec.rb +14 -12
  98. data/spec/lib/danica_spec.rb +6 -5
  99. data/spec/spec_helper.rb +2 -1
  100. data/spec/support/models/expression/baskara.rb +3 -3
  101. data/spec/support/models/expression/parabole.rb +2 -0
  102. data/spec/support/models/expression/quadratic_sum.rb +3 -1
  103. data/spec/support/models/expression/spatial.rb +2 -1
  104. data/spec/support/models/function/my_function.rb +3 -1
  105. data/spec/support/models/function/parabole.rb +1 -1
  106. data/spec/support/models/function/quadratic_sum.rb +2 -0
  107. data/spec/support/models/function/spatial.rb +2 -0
  108. data/spec/support/models/operator/inverse.rb +3 -1
  109. data/spec/support/models/operator/my_operator.rb +3 -1
  110. data/spec/support/models/variables_holder/dummy.rb +3 -1
  111. data/spec/support/shared_contexts/common.rb +4 -2
  112. data/spec/support/shared_examples/base_operations.rb +7 -4
  113. data/spec/support/shared_examples/common.rb +3 -1
  114. data/spec/support/shared_examples/operator/chained.rb +12 -6
  115. data/spec/support/shared_examples/operator/dual_term.rb +9 -8
  116. data/spec/support/shared_examples/operator/single_input.rb +7 -2
  117. data/spec/support/shared_examples/variable.rb +8 -4
  118. metadata +109 -30
  119. data/spec/integration/addition_spec.rb +0 -28
  120. data/spec/integration/formatted_spec.rb +0 -75
  121. data/spec/integration/readme/formatting_spec.rb +0 -34
@@ -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,7 +13,7 @@ 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
18
  context 'when other is also a addition' do
17
19
  let(:other) { described_class.new(200, 5) }
@@ -23,18 +25,17 @@ describe Danica::Operator::Addition do
23
25
  end
24
26
  it_behaves_like 'an object with - operation'
25
27
 
26
- it_behaves_like 'a operator that joins many variables with same operation', {
27
- calculated: 10,
28
- numeric_variables: [ 1.5, 3.0, 3.5 ],
29
- tex: {
30
- string_expected: 'X1 + X2 + X3 + X4',
31
- integer_expected: '1.5 + 3 + X3 + X4',
32
- float_expected: '1.5 + 3 + 3.5 + X4'
33
- },
34
- gnu: {
35
- string_expected: 'X1 + X2 + X3 + X4',
36
- integer_expected: '1.5 + 3 + X3 + X4',
37
- float_expected: '1.5 + 3 + 3.5 + X4'
38
- }
39
- }
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
+ }
40
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
@@ -22,18 +24,17 @@ describe Danica::Operator::Multiplication do
22
24
  end
23
25
  it_behaves_like 'an object with basic operation', ignore: :*
24
26
 
25
- it_behaves_like 'a operator that joins many variables with same operation', {
26
- calculated: 24,
27
- numeric_variables: [ 1.5, 2, 3.5 ],
28
- tex: {
29
- string_expected: %w(X1 X2 X3 X4).join(' \cdot '),
30
- integer_expected: %w(1.5 2 X3 X4).join(' \cdot '),
31
- float_expected: %w(1.5 2 3.5 X4).join(' \cdot ')
32
- },
33
- gnu: {
34
- string_expected: %w(X1 X2 X3 X4).join(' * '),
35
- integer_expected: %w(1.5 2 X3 X4).join(' * '),
36
- float_expected: %w(1.5 2 3.5 X4).join(' * '),
37
- }
38
- }
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
+ }
39
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
@@ -1,16 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
- describe Danica::VariablesHolder::Store do
5
+ describe Danica::VariablesHolder::Store do
6
+ subject do
7
+ described_class.new(default_variables_hash)
8
+ end
9
+
4
10
  let(:default_variables_hash) do
5
11
  {
6
12
  x: Danica::Wrapper::Variable.new(name: :x),
7
- y: Danica::Wrapper::Variable.new( latex: '\y' ),
13
+ y: Danica::Wrapper::Variable.new(latex: '\y'),
8
14
  z: Danica::Wrapper::Number.new(10)
9
15
  }
10
16
  end
11
- subject do
12
- described_class.new(default_variables_hash)
13
- end
14
17
 
15
18
  describe '#variables' do
16
19
  context 'when instance has no variables defined' do
@@ -18,7 +21,7 @@ describe Danica::VariablesHolder::Store do
18
21
  expect(subject.variables).not_to be_empty
19
22
  end
20
23
 
21
- #it_behaves_like 'an object that returns the default variables'
24
+ # it_behaves_like 'an object that returns the default variables'
22
25
  end
23
26
 
24
27
  context 'when some variables where defined' do
@@ -26,12 +29,17 @@ describe Danica::VariablesHolder::Store do
26
29
  subject.containers_hash[:y] = Danica::Wrapper::Number.new(1)
27
30
  end
28
31
 
29
- it 'returns the default variables and the new set one' do
30
- expect(subject.variables).to eq([
32
+ let(:expected_variables) do
33
+ [
31
34
  Danica::Wrapper::Variable.new(name: :x),
32
35
  Danica::Wrapper::Number.new(1),
33
36
  Danica::Wrapper::Number.new(10)
34
- ])
37
+ ]
38
+ end
39
+
40
+ it 'returns the default variables and the new set one' do
41
+ expect(subject.variables)
42
+ .to eq(expected_variables)
35
43
  end
36
44
 
37
45
  it 'does not change the default variables' do
@@ -44,7 +52,7 @@ describe Danica::VariablesHolder::Store do
44
52
 
45
53
  describe '#variables_hash' do
46
54
  context 'when instance has no variables defined' do
47
- #it_behaves_like 'an object that returns the default variables hash'
55
+ # it_behaves_like 'an object that returns the default variables hash'
48
56
  end
49
57
 
50
58
  context 'when some variables where defined' do
@@ -64,9 +72,7 @@ describe Danica::VariablesHolder::Store do
64
72
 
65
73
  describe '#containers' do
66
74
  it 'is an array of Containers' do
67
- subject.containers.each do |container|
68
- expect(container).to be_a(Danica::Wrapper::Container)
69
- end
75
+ expect(subject.containers).to all(be_a(Danica::Wrapper::Container))
70
76
  end
71
77
  end
72
78
  end