danica 2.7.6 → 3.0.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 (74) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +18 -10
  3. data/.rubocop.yml +11 -1
  4. data/.rubocop_todo.yml +50 -73
  5. data/Dockerfile +2 -2
  6. data/Gemfile +15 -0
  7. data/Makefile +7 -0
  8. data/README.md +7 -1
  9. data/danica.gemspec +3 -16
  10. data/danica.png +0 -0
  11. data/lib/danica/common.rb +13 -13
  12. data/lib/danica/dsl.rb +4 -4
  13. data/lib/danica/equation/builder.rb +2 -2
  14. data/lib/danica/equation.rb +6 -6
  15. data/lib/danica/exception.rb +2 -0
  16. data/lib/danica/expressable.rb +1 -1
  17. data/lib/danica/formatted.rb +10 -10
  18. data/lib/danica/function/name.rb +3 -3
  19. data/lib/danica/function.rb +2 -2
  20. data/lib/danica/operator/chained.rb +4 -4
  21. data/lib/danica/operator/division.rb +4 -4
  22. data/lib/danica/operator/functional.rb +3 -3
  23. data/lib/danica/operator/power.rb +4 -4
  24. data/lib/danica/variables_holder/alias_builder.rb +15 -1
  25. data/lib/danica/variables_holder/variables_builder.rb +11 -10
  26. data/lib/danica/variables_holder.rb +4 -4
  27. data/lib/danica/version.rb +1 -1
  28. data/lib/danica/wrapper/constant.rb +1 -5
  29. data/lib/danica/wrapper/group.rb +4 -4
  30. data/lib/danica/wrapper/negative.rb +2 -2
  31. data/lib/danica/wrapper/number.rb +1 -1
  32. data/lib/danica/wrapper/plus_minus.rb +4 -4
  33. data/lib/danica/wrapper/variable.rb +4 -4
  34. data/lib/danica/wrapper.rb +1 -1
  35. data/spec/integration/global/danica/operator/multiplication_spec.rb +1 -1
  36. data/spec/integration/readme/{equation_spec.rb → danica/equation_spec.rb} +2 -2
  37. data/spec/integration/readme/danica/expression/baskara_spec.rb +11 -0
  38. data/spec/integration/readme/{expression_spec.rb → danica/expression_spec.rb} +0 -8
  39. data/spec/integration/readme/danica/function/my_function_spec.rb +11 -0
  40. data/spec/integration/readme/danica/function/quadratic_sum_spec.rb +11 -0
  41. data/spec/integration/readme/{function_spec.rb → danica/function/spatial_spec.rb} +0 -32
  42. data/spec/integration/readme/danica/function_spec.rb +19 -0
  43. data/spec/integration/readme/{operator_spec.rb → danica/operator/inverse_spec.rb} +0 -22
  44. data/spec/integration/readme/danica/operator/my_operator_spec.rb +25 -0
  45. data/spec/integration/readme/{constant_spec.rb → danica/wrapper/constant_spec.rb} +2 -2
  46. data/spec/integration/readme/{number_spec.rb → danica/wrapper/number_spec.rb} +3 -3
  47. data/spec/integration/readme/{variables_spec.rb → danica/wrapper/variables_spec.rb} +15 -15
  48. data/spec/integration/readme/danica_spec.rb +3 -3
  49. data/spec/lib/danica/common_spec.rb +27 -27
  50. data/spec/lib/danica/dsl_spec.rb +1 -5
  51. data/spec/lib/danica/equation_spec.rb +7 -7
  52. data/spec/lib/danica/expression/gauss_spec.rb +6 -6
  53. data/spec/lib/danica/expression_spec.rb +39 -41
  54. data/spec/lib/danica/formatted_spec.rb +24 -23
  55. data/spec/lib/danica/function/name_spec.rb +6 -5
  56. data/spec/lib/danica/function_spec.rb +7 -18
  57. data/spec/lib/danica/operator/division_spec.rb +5 -5
  58. data/spec/lib/danica/operator_spec.rb +5 -5
  59. data/spec/lib/danica/variables_holder/store_spec.rb +9 -13
  60. data/spec/lib/danica/variables_holder_spec.rb +68 -67
  61. data/spec/lib/danica/wrapper/constant_spec.rb +19 -19
  62. data/spec/lib/danica/wrapper/group_spec.rb +7 -7
  63. data/spec/lib/danica/wrapper/negative_spec.rb +7 -7
  64. data/spec/lib/danica/wrapper/number_spec.rb +5 -5
  65. data/spec/lib/danica/wrapper/plus_minus_spec.rb +7 -7
  66. data/spec/lib/danica/wrapper/variable_spec.rb +6 -4
  67. data/spec/lib/danica/wrapper_spec.rb +3 -3
  68. data/spec/spec_helper.rb +4 -3
  69. data/spec/support/models/dummy/dsl_dummy.rb +5 -0
  70. data/spec/support/models/function/my_function.rb +1 -1
  71. data/spec/support/models/variables_holder/dummy.rb +1 -1
  72. data/spec/support/shared_examples/operator/chained.rb +2 -1
  73. data/spec/support/shared_examples/operator/single_input.rb +2 -1
  74. metadata +24 -233
@@ -15,20 +15,21 @@ end
15
15
  shared_examples('a formatted object that responds to basic operations') do |operations_map|
16
16
  operations_map.each do |operation, (output, reverse_output)|
17
17
  describe(operation.to_s) do
18
- let(:result) { subject.public_send(operation, 2) }
18
+ let(:result) { formatted.public_send(operation, 2) }
19
19
 
20
20
  it_behaves_like 'a formatted result', output
21
21
 
22
22
  context 'when doing it backwards' do
23
- let(:result) { Danica::Wrapper::Number.new(2).public_send(operation, subject) }
23
+ let(:result) { Danica::Wrapper::Number.new(2).public_send(operation, formatted) }
24
24
 
25
25
  it_behaves_like 'a formatted result', reverse_output
26
26
  end
27
27
  end
28
28
  end
29
29
  end
30
+
30
31
  describe Danica::Formatted do
31
- subject do
32
+ subject(:formatted) do
32
33
  described_class.new(content, format: format, **options)
33
34
  end
34
35
 
@@ -40,14 +41,14 @@ describe Danica::Formatted do
40
41
  let(:expression) { Danica::Wrapper::Number.new(1.0 / 3) }
41
42
 
42
43
  it do
43
- expect(subject.repack(expression)).to be_a(described_class)
44
+ expect(formatted.repack(expression)).to be_a(described_class)
44
45
  end
45
46
 
46
47
  context 'when there are options' do
47
48
  let(:options) { { decimals: 3 } }
48
49
 
49
50
  it 'wraps expression with options' do
50
- expect(subject.repack(expression).to_s).to eq('0.333')
51
+ expect(formatted.repack(expression).to_s).to eq('0.333')
51
52
  end
52
53
  end
53
54
  end
@@ -55,7 +56,7 @@ describe Danica::Formatted do
55
56
  describe '#to_s' do
56
57
  context 'when format is tex' do
57
58
  it 'return the expected tex string' do
58
- expect(subject.to_s).to eq('V')
59
+ expect(formatted.to_s).to eq('V')
59
60
  end
60
61
  end
61
62
 
@@ -63,7 +64,7 @@ describe Danica::Formatted do
63
64
  let(:format) { :gnu }
64
65
 
65
66
  it 'return the expected gnu string' do
66
- expect(subject.to_s).to eq('v')
67
+ expect(formatted.to_s).to eq('v')
67
68
  end
68
69
  end
69
70
 
@@ -71,14 +72,14 @@ describe Danica::Formatted do
71
72
  let(:content) { Danica::Wrapper::Number.new(1 / 3.0) }
72
73
 
73
74
  it 'returns the formatted number' do
74
- expect(subject.to_s).to eq('0.3333333333333333')
75
+ expect(formatted.to_s).to eq('0.3333333333333333')
75
76
  end
76
77
 
77
78
  context 'when passing decimals settings' do
78
79
  let(:options) { { decimals: 4 } }
79
80
 
80
81
  it 'returns the formatted number' do
81
- expect(subject.to_s).to eq('0.3333')
82
+ expect(formatted.to_s).to eq('0.3333')
82
83
  end
83
84
  end
84
85
  end
@@ -94,11 +95,11 @@ describe Danica::Formatted do
94
95
 
95
96
  describe '-@' do
96
97
  it do
97
- expect(-subject).to be_a(described_class)
98
+ expect(-formatted).to be_a(described_class)
98
99
  end
99
100
 
100
101
  it 'keeps being able to parse format' do
101
- expect((-subject).to_s).to eq('-V')
102
+ expect((-formatted).to_s).to eq('-V')
102
103
  end
103
104
  end
104
105
  end
@@ -107,36 +108,36 @@ describe Danica::Formatted do
107
108
  let(:content) { Danica::Wrapper::Number.new(2) }
108
109
 
109
110
  it do
110
- expect(subject.to_f).to be_a(Numeric)
111
+ expect(formatted.to_f).to be_a(Numeric)
111
112
  end
112
113
 
113
114
  it 'returns the number' do
114
- expect(subject.to_f).to eq(2)
115
+ expect(formatted.to_f).to eq(2)
115
116
  end
116
117
  end
117
118
 
118
119
  describe '#to' do
119
120
  it do
120
- expect(subject.to(:tex)).to be_a(String)
121
+ expect(formatted.to(:tex)).to be_a(String)
121
122
  end
122
123
 
123
124
  it 'returns the string' do
124
- expect(subject.to(:tex)).to eq('V')
125
+ expect(formatted.to(:tex)).to eq('V')
125
126
  end
126
127
  end
127
128
 
128
129
  describe '#tex' do
129
130
  it do
130
- expect(subject.tex).to be_a(described_class)
131
+ expect(formatted.tex).to be_a(described_class)
131
132
  end
132
133
 
133
134
  context 'when original format is tex' do
134
135
  it 'returns the tex string' do
135
- expect(subject.tex.to_s).to eq('V')
136
+ expect(formatted.tex.to_s).to eq('V')
136
137
  end
137
138
 
138
139
  it 'returns similar object' do
139
- expect(subject.tex).to eq(subject)
140
+ expect(formatted.tex).to eq(formatted)
140
141
  end
141
142
  end
142
143
 
@@ -144,23 +145,23 @@ describe Danica::Formatted do
144
145
  let(:format) { :gnu }
145
146
 
146
147
  it 'returns the tex string' do
147
- expect(subject.tex.to_s).to eq('V')
148
+ expect(formatted.tex.to_s).to eq('V')
148
149
  end
149
150
 
150
151
  it 'returns a new format object' do
151
- expect(subject.tex).not_to eq(subject)
152
+ expect(formatted.tex).not_to eq(formatted)
152
153
  end
153
154
  end
154
155
  end
155
156
 
156
157
  describe '#gnu' do
157
158
  it do
158
- expect(subject.gnu).to be_a(described_class)
159
+ expect(formatted.gnu).to be_a(described_class)
159
160
  end
160
161
 
161
162
  context 'when original format is tex' do
162
163
  it 'returns the gnu string' do
163
- expect(subject.gnu.to_s).to eq('v')
164
+ expect(formatted.gnu.to_s).to eq('v')
164
165
  end
165
166
  end
166
167
 
@@ -168,7 +169,7 @@ describe Danica::Formatted do
168
169
  let(:format) { :gnu }
169
170
 
170
171
  it 'returns the gnu string' do
171
- expect(subject.gnu.to_s).to eq('v')
172
+ expect(formatted.gnu.to_s).to eq('v')
172
173
  end
173
174
  end
174
175
  end
@@ -3,35 +3,36 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Danica::Function::Name do
6
+ subject(:name) { described_class.new(name: :f, variables: [x]) }
7
+
6
8
  let(:x) { Danica::Wrapper::Variable.new(name: :x, latex: '\mu', gnuplot: 'u') }
7
- let(:subject) { described_class.new(name: :f, variables: [x]) }
8
9
 
9
10
  it_behaves_like 'an object that respond to basic_methods'
10
11
 
11
12
  describe '#to_tex' do
12
13
  it 'returns the name of the function with tex variables' do
13
- expect(subject.to_tex).to eq('f(\mu)')
14
+ expect(name.to_tex).to eq('f(\mu)')
14
15
  end
15
16
 
16
17
  context 'when initializing variables from scratch' do
17
18
  let(:x) { :x }
18
19
 
19
20
  it 'returns the name of the function with tex variables' do
20
- expect(subject.to_tex).to eq('f(x)')
21
+ expect(name.to_tex).to eq('f(x)')
21
22
  end
22
23
  end
23
24
  end
24
25
 
25
26
  describe '#to_gnu' do
26
27
  it 'returns the name of the function with tex variables' do
27
- expect(subject.to_gnu).to eq('f(u)')
28
+ expect(name.to_gnu).to eq('f(u)')
28
29
  end
29
30
 
30
31
  context 'when initializing variables from scratch' do
31
32
  let(:x) { :x }
32
33
 
33
34
  it 'returns the name of the function with tex variables' do
34
- expect(subject.to_gnu).to eq('f(x)')
35
+ expect(name.to_gnu).to eq('f(x)')
35
36
  end
36
37
  end
37
38
  end
@@ -29,9 +29,8 @@ shared_examples 'a generically generated function' do
29
29
  end
30
30
 
31
31
  describe Danica::Function do
32
- subject { function }
32
+ subject(:function) { function_class.new }
33
33
 
34
- let(:function) { function_class.new }
35
34
  let(:variables) { %i[x y] }
36
35
  let(:function_class) do
37
36
  described_class.build(*variables) do
@@ -40,7 +39,7 @@ describe Danica::Function do
40
39
  end
41
40
 
42
41
  describe '.for' do
43
- subject do
42
+ subject(:function) do
44
43
  described_class.for(expression_class).new
45
44
  end
46
45
 
@@ -48,24 +47,24 @@ describe Danica::Function do
48
47
  let(:expression) { expression_class.new }
49
48
 
50
49
  it 'returns a function' do
51
- expect(subject).to be_a(described_class)
50
+ expect(function).to be_a(described_class)
52
51
  end
53
52
 
54
53
  it 'behaves like a function' do
55
54
  expect do
56
- subject.to_tex
55
+ function.to_tex
57
56
  end.not_to raise_error
58
57
  end
59
58
 
60
59
  it 'creates a funcion out of an expression' do
61
- expect(subject.to_tex).to eq("f(x, \\mu, \\sigma) = #{expression.to_tex}")
60
+ expect(function.to_tex).to eq("f(x, \\mu, \\sigma) = #{expression.to_tex}")
62
61
  end
63
62
 
64
63
  context 'when passing an operator' do
65
64
  let(:expression_class) { Danica::Operator::Cos }
66
65
 
67
66
  it do
68
- expect(subject.to_tex).to eq("f(value) = #{expression.to_tex}")
67
+ expect(function.to_tex).to eq("f(value) = #{expression.to_tex}")
69
68
  end
70
69
  end
71
70
  end
@@ -212,17 +211,7 @@ describe Danica::Function do
212
211
  function_class.new(name: :f, x: 2)
213
212
  end
214
213
 
215
- it 'sohws the variable as number' do
216
- expect(function.to_tex).to eq('f(2, y) = 2^{y}')
217
- end
218
- end
219
-
220
- context 'when a variable has value' do
221
- let(:function) do
222
- function_class.new(name: :f, x: 2)
223
- end
224
-
225
- it 'sohws the variable as number' do
214
+ it 'shwws the variable as number' do
226
215
  expect(function.to_tex).to eq('f(2, y) = 2^{y}')
227
216
  end
228
217
  end
@@ -3,19 +3,19 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Danica::Operator::Division do
6
- subject { described_class.new(*variables) }
6
+ subject(:operator) { described_class.new(*variables) }
7
7
 
8
8
  let(:variables) { [2, 4] }
9
9
 
10
10
  describe '#numerator' do
11
11
  it 'returns the numerator' do
12
- expect(subject.numerator).to eq(Danica::Wrapper::Number.new(2))
12
+ expect(operator.numerator).to eq(Danica::Wrapper::Number.new(2))
13
13
  end
14
14
  end
15
15
 
16
16
  describe '#denominator' do
17
17
  it 'returns the denominator' do
18
- expect(subject.denominator).to eq(Danica::Wrapper::Number.new(4))
18
+ expect(operator.denominator).to eq(Danica::Wrapper::Number.new(4))
19
19
  end
20
20
  end
21
21
 
@@ -38,7 +38,7 @@ describe Danica::Operator::Division do
38
38
 
39
39
  describe 'more complex division' do
40
40
  describe 'of two additions' do
41
- subject do
41
+ subject(:operator) do
42
42
  described_class.new(
43
43
  Danica::Operator::Addition.new(2, :x),
44
44
  Danica::Operator::Addition.new(3, :y)
@@ -51,7 +51,7 @@ describe Danica::Operator::Division do
51
51
  end
52
52
 
53
53
  it 'groups addition' do
54
- expect(subject.to_gnu).to eq(expected)
54
+ expect(operator.to_gnu).to eq(expected)
55
55
  end
56
56
  end
57
57
  end
@@ -11,7 +11,7 @@ class Danica::Operator::Dummy < Danica::Operator
11
11
  end
12
12
 
13
13
  describe Danica::Operator do
14
- subject { clazz.new(*variables) }
14
+ subject(:operator) { clazz.new(*variables) }
15
15
 
16
16
  let(:variables) { [2, 4] }
17
17
  let(:clazz) { described_class::Dummy }
@@ -20,22 +20,22 @@ describe Danica::Operator do
20
20
 
21
21
  describe 'variables assignment' do
22
22
  it 'assignes first variable' do
23
- expect(subject.a).to eq(Danica::Wrapper::Number.new(2))
23
+ expect(operator.a).to eq(Danica::Wrapper::Number.new(2))
24
24
  end
25
25
 
26
26
  it 'assignes second variable' do
27
- expect(subject.b).to eq(Danica::Wrapper::Number.new(4))
27
+ expect(operator.b).to eq(Danica::Wrapper::Number.new(4))
28
28
  end
29
29
 
30
30
  context 'when initializing with a hash' do
31
31
  let(:variables) { [{ name: :A, value: 2 }, { name: :B, value: 4 }] }
32
32
 
33
33
  it 'assignes first variable' do
34
- expect(subject.a).to eq(Danica::Wrapper::Variable.new(name: :A, value: 2))
34
+ expect(operator.a).to eq(Danica::Wrapper::Variable.new(name: :A, value: 2))
35
35
  end
36
36
 
37
37
  it 'assignes second variable' do
38
- expect(subject.b).to eq(Danica::Wrapper::Variable.new(name: :B, value: 4))
38
+ expect(operator.b).to eq(Danica::Wrapper::Variable.new(name: :B, value: 4))
39
39
  end
40
40
  end
41
41
  end
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Danica::VariablesHolder::Store do
6
- subject do
6
+ subject(:holder) do
7
7
  described_class.new(default_variables_hash)
8
8
  end
9
9
 
@@ -18,7 +18,7 @@ describe Danica::VariablesHolder::Store do
18
18
  describe '#variables' do
19
19
  context 'when instance has no variables defined' do
20
20
  it do
21
- expect(subject.variables).not_to be_empty
21
+ expect(holder.variables).not_to be_empty
22
22
  end
23
23
 
24
24
  # it_behaves_like 'an object that returns the default variables'
@@ -26,7 +26,7 @@ describe Danica::VariablesHolder::Store do
26
26
 
27
27
  context 'when some variables where defined' do
28
28
  before do
29
- subject.containers_hash[:y] = Danica::Wrapper::Number.new(1)
29
+ holder.containers_hash[:y] = Danica::Wrapper::Number.new(1)
30
30
  end
31
31
 
32
32
  let(:expected_variables) do
@@ -38,30 +38,26 @@ describe Danica::VariablesHolder::Store do
38
38
  end
39
39
 
40
40
  it 'returns the default variables and the new set one' do
41
- expect(subject.variables)
41
+ expect(holder.variables)
42
42
  .to eq(expected_variables)
43
43
  end
44
44
 
45
45
  it 'does not change the default variables' do
46
46
  expect do
47
- subject.containers_hash[:x] = Danica::Wrapper::Number.new(2)
48
- end.not_to change(subject, :default_variables_hash)
47
+ holder.containers_hash[:x] = Danica::Wrapper::Number.new(2)
48
+ end.not_to change(holder, :default_variables_hash)
49
49
  end
50
50
  end
51
51
  end
52
52
 
53
53
  describe '#variables_hash' do
54
- context 'when instance has no variables defined' do
55
- # it_behaves_like 'an object that returns the default variables hash'
56
- end
57
-
58
54
  context 'when some variables where defined' do
59
55
  before do
60
- subject.containers_hash[:y] = Danica::Wrapper::Number.new(1)
56
+ holder.containers_hash[:y] = Danica::Wrapper::Number.new(1)
61
57
  end
62
58
 
63
59
  it 'returns the default hash with the set value' do
64
- expect(subject.variables_hash).to eq(
60
+ expect(holder.variables_hash).to eq(
65
61
  x: Danica::Wrapper::Variable.new(name: :x),
66
62
  y: Danica::Wrapper::Number.new(1),
67
63
  z: Danica::Wrapper::Number.new(10)
@@ -72,7 +68,7 @@ describe Danica::VariablesHolder::Store do
72
68
 
73
69
  describe '#containers' do
74
70
  it 'is an array of Containers' do
75
- expect(subject.containers).to all(be_a(Danica::Wrapper::Container))
71
+ expect(holder.containers).to all(be_a(Danica::Wrapper::Container))
76
72
  end
77
73
  end
78
74
  end