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.
- checksums.yaml +4 -4
- data/.circleci/config.yml +18 -10
- data/.rubocop.yml +11 -1
- data/.rubocop_todo.yml +50 -73
- data/Dockerfile +2 -2
- data/Gemfile +15 -0
- data/Makefile +7 -0
- data/README.md +7 -1
- data/danica.gemspec +3 -16
- data/danica.png +0 -0
- data/lib/danica/common.rb +13 -13
- data/lib/danica/dsl.rb +4 -4
- data/lib/danica/equation/builder.rb +2 -2
- data/lib/danica/equation.rb +6 -6
- data/lib/danica/exception.rb +2 -0
- data/lib/danica/expressable.rb +1 -1
- data/lib/danica/formatted.rb +10 -10
- data/lib/danica/function/name.rb +3 -3
- data/lib/danica/function.rb +2 -2
- data/lib/danica/operator/chained.rb +4 -4
- data/lib/danica/operator/division.rb +4 -4
- data/lib/danica/operator/functional.rb +3 -3
- data/lib/danica/operator/power.rb +4 -4
- data/lib/danica/variables_holder/alias_builder.rb +15 -1
- data/lib/danica/variables_holder/variables_builder.rb +11 -10
- data/lib/danica/variables_holder.rb +4 -4
- data/lib/danica/version.rb +1 -1
- data/lib/danica/wrapper/constant.rb +1 -5
- data/lib/danica/wrapper/group.rb +4 -4
- data/lib/danica/wrapper/negative.rb +2 -2
- data/lib/danica/wrapper/number.rb +1 -1
- data/lib/danica/wrapper/plus_minus.rb +4 -4
- data/lib/danica/wrapper/variable.rb +4 -4
- data/lib/danica/wrapper.rb +1 -1
- data/spec/integration/global/danica/operator/multiplication_spec.rb +1 -1
- data/spec/integration/readme/{equation_spec.rb → danica/equation_spec.rb} +2 -2
- data/spec/integration/readme/danica/expression/baskara_spec.rb +11 -0
- data/spec/integration/readme/{expression_spec.rb → danica/expression_spec.rb} +0 -8
- data/spec/integration/readme/danica/function/my_function_spec.rb +11 -0
- data/spec/integration/readme/danica/function/quadratic_sum_spec.rb +11 -0
- data/spec/integration/readme/{function_spec.rb → danica/function/spatial_spec.rb} +0 -32
- data/spec/integration/readme/danica/function_spec.rb +19 -0
- data/spec/integration/readme/{operator_spec.rb → danica/operator/inverse_spec.rb} +0 -22
- data/spec/integration/readme/danica/operator/my_operator_spec.rb +25 -0
- data/spec/integration/readme/{constant_spec.rb → danica/wrapper/constant_spec.rb} +2 -2
- data/spec/integration/readme/{number_spec.rb → danica/wrapper/number_spec.rb} +3 -3
- data/spec/integration/readme/{variables_spec.rb → danica/wrapper/variables_spec.rb} +15 -15
- data/spec/integration/readme/danica_spec.rb +3 -3
- data/spec/lib/danica/common_spec.rb +27 -27
- data/spec/lib/danica/dsl_spec.rb +1 -5
- data/spec/lib/danica/equation_spec.rb +7 -7
- data/spec/lib/danica/expression/gauss_spec.rb +6 -6
- data/spec/lib/danica/expression_spec.rb +39 -41
- data/spec/lib/danica/formatted_spec.rb +24 -23
- data/spec/lib/danica/function/name_spec.rb +6 -5
- data/spec/lib/danica/function_spec.rb +7 -18
- data/spec/lib/danica/operator/division_spec.rb +5 -5
- data/spec/lib/danica/operator_spec.rb +5 -5
- data/spec/lib/danica/variables_holder/store_spec.rb +9 -13
- data/spec/lib/danica/variables_holder_spec.rb +68 -67
- data/spec/lib/danica/wrapper/constant_spec.rb +19 -19
- data/spec/lib/danica/wrapper/group_spec.rb +7 -7
- data/spec/lib/danica/wrapper/negative_spec.rb +7 -7
- data/spec/lib/danica/wrapper/number_spec.rb +5 -5
- data/spec/lib/danica/wrapper/plus_minus_spec.rb +7 -7
- data/spec/lib/danica/wrapper/variable_spec.rb +6 -4
- data/spec/lib/danica/wrapper_spec.rb +3 -3
- data/spec/spec_helper.rb +4 -3
- data/spec/support/models/dummy/dsl_dummy.rb +5 -0
- data/spec/support/models/function/my_function.rb +1 -1
- data/spec/support/models/variables_holder/dummy.rb +1 -1
- data/spec/support/shared_examples/operator/chained.rb +2 -1
- data/spec/support/shared_examples/operator/single_input.rb +2 -1
- metadata +24 -233
@@ -5,31 +5,32 @@ module Danica::VariablesHolder
|
|
5
5
|
include Danica::DSL
|
6
6
|
include Danica::Wrapper
|
7
7
|
|
8
|
-
attr_reader :instance, :attr_names
|
8
|
+
attr_reader :instance, :attr_names, :names_hash
|
9
9
|
|
10
|
-
def initialize(
|
10
|
+
def initialize(instance, attr_names)
|
11
11
|
@instance = instance
|
12
12
|
@attr_names = attr_names
|
13
|
+
@names_hash = attr_names.extract_options!.symbolize_keys
|
13
14
|
end
|
14
15
|
|
15
16
|
def build
|
16
|
-
names_hash = attr_names.extract_options!.symbolize_keys
|
17
|
-
|
18
17
|
attr_names.map(&:to_sym).each do |name|
|
19
|
-
|
20
|
-
add_reader(name)
|
21
|
-
instance.variables_hash[name] = wrap_value(name)
|
18
|
+
build_variable(name, name)
|
22
19
|
end
|
23
20
|
|
24
21
|
names_hash.each do |name, default|
|
25
|
-
|
26
|
-
add_reader(name)
|
27
|
-
instance.variables_hash[name] = wrap_value(default)
|
22
|
+
build_variable(name, default)
|
28
23
|
end
|
29
24
|
end
|
30
25
|
|
31
26
|
private
|
32
27
|
|
28
|
+
def build_variable(name, default)
|
29
|
+
add_setter(name)
|
30
|
+
add_reader(name)
|
31
|
+
instance.variables_hash[name] = wrap_value(default)
|
32
|
+
end
|
33
|
+
|
33
34
|
def add_setter(name)
|
34
35
|
instance.send(:define_method, "#{name}=") do |value|
|
35
36
|
containers_hash[name].content = wrap_value(value)
|
@@ -20,7 +20,7 @@ module Danica
|
|
20
20
|
|
21
21
|
class_methods do
|
22
22
|
def variables(*names)
|
23
|
-
VariablesBuilder.new(
|
23
|
+
VariablesBuilder.new(self, names).build
|
24
24
|
end
|
25
25
|
|
26
26
|
def variable_alias(origin, destiny)
|
@@ -41,7 +41,7 @@ module Danica
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def superclass_variables_hash
|
44
|
-
@superclass_variables_hash ||=
|
44
|
+
@superclass_variables_hash ||= superclass.try(:variables_hash) || {}
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -61,8 +61,8 @@ module Danica
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
def calculate(*
|
65
|
-
Calculator.new(self, *
|
64
|
+
def calculate(*)
|
65
|
+
Calculator.new(self, *).calculate
|
66
66
|
end
|
67
67
|
|
68
68
|
private
|
data/lib/danica/version.rb
CHANGED
data/lib/danica/wrapper/group.rb
CHANGED
@@ -16,12 +16,12 @@ module Danica
|
|
16
16
|
@value = wrap_value(value)
|
17
17
|
end
|
18
18
|
|
19
|
-
def to_tex(**
|
20
|
-
"\\left(#{value.to_tex(
|
19
|
+
def to_tex(**)
|
20
|
+
"\\left(#{value.to_tex(**)}\\right)"
|
21
21
|
end
|
22
22
|
|
23
|
-
def to_gnu(**
|
24
|
-
"(#{value.to_gnu(
|
23
|
+
def to_gnu(**)
|
24
|
+
"(#{value.to_gnu(**)})"
|
25
25
|
end
|
26
26
|
|
27
27
|
def ==(other)
|
@@ -21,12 +21,12 @@ module Danica
|
|
21
21
|
value.to_f
|
22
22
|
end
|
23
23
|
|
24
|
-
def to_tex(**
|
25
|
-
"\\pm #{wrap_as_group(value).to_tex(
|
24
|
+
def to_tex(**)
|
25
|
+
"\\pm #{wrap_as_group(value).to_tex(**)}"
|
26
26
|
end
|
27
27
|
|
28
|
-
def to_gnu(**
|
29
|
-
"+ #{wrap_as_group(value).to_gnu(
|
28
|
+
def to_gnu(**)
|
29
|
+
"+ #{wrap_as_group(value).to_gnu(**)}"
|
30
30
|
end
|
31
31
|
|
32
32
|
def ==(other)
|
@@ -34,14 +34,14 @@ module Danica
|
|
34
34
|
other.gnuplot == gnuplot
|
35
35
|
end
|
36
36
|
|
37
|
-
def to_tex(**
|
38
|
-
return value.to_tex(
|
37
|
+
def to_tex(**)
|
38
|
+
return value.to_tex(**) if value
|
39
39
|
|
40
40
|
(latex || name).to_s
|
41
41
|
end
|
42
42
|
|
43
|
-
def to_gnu(**
|
44
|
-
return value.to_gnu(
|
43
|
+
def to_gnu(**)
|
44
|
+
return value.to_gnu(**) if value
|
45
45
|
|
46
46
|
(gnuplot || name).to_s
|
47
47
|
end
|
data/lib/danica/wrapper.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Danica::Expression::Baskara do
|
6
|
+
describe '#to_tex' do
|
7
|
+
it 'returns bascara tex string' do
|
8
|
+
expect(subject.to_tex).to eq('\frac{-b \pm \sqrt{b^{2} -4 \cdot a \cdot c}}{2 \cdot a}')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -2,14 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Danica::Expression::Baskara do
|
6
|
-
describe '#to_tex' do
|
7
|
-
it 'returns bascara tex string' do
|
8
|
-
expect(subject.to_tex).to eq('\frac{-b \pm \sqrt{b^{2} -4 \cdot a \cdot c}}{2 \cdot a}')
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
5
|
describe Danica::Expression do
|
14
6
|
subject { clazz.new }
|
15
7
|
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Danica::Function::QuadraticSum do
|
6
|
+
describe '#to_tex' do
|
7
|
+
it 'creates a funcion out of an expression' do
|
8
|
+
expect(subject.to_tex).to eq('f(x, y) = \\left(x + y\\right)^{2}')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -67,35 +67,3 @@ describe Danica::Function::Spatial do
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
70
|
-
|
71
|
-
describe Danica::Function::MyFunction do
|
72
|
-
describe '#to_gnu' do
|
73
|
-
it 'returns the function' do
|
74
|
-
expect(subject.to_gnu).to eq('f(x, y) = x**(2) + y')
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe Danica::Function::QuadraticSum do
|
80
|
-
describe '#to_tex' do
|
81
|
-
it 'creates a funcion out of an expression' do
|
82
|
-
expect(subject.to_tex).to eq('f(x, y) = \\left(x + y\\right)^{2}')
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe Danica::Function do
|
88
|
-
subject { described_class.build(:x, :y, :z) { z * (x**y) }.new(y: 3, z: Danica::PI) }
|
89
|
-
|
90
|
-
describe '#to_tex' do
|
91
|
-
it do
|
92
|
-
expect(subject.to_tex).to eq('f(x, 3) = \pi \cdot x^{3}')
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe '#to_gnu' do
|
97
|
-
it do
|
98
|
-
expect(subject.to_gnu).to eq('f(x) = pi * x**(3)')
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Danica::Function do
|
6
|
+
subject { described_class.build(:x, :y, :z) { z * (x**y) }.new(y: 3, z: Danica::PI) }
|
7
|
+
|
8
|
+
describe '#to_tex' do
|
9
|
+
it do
|
10
|
+
expect(subject.to_tex).to eq('f(x, 3) = \pi \cdot x^{3}')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#to_gnu' do
|
15
|
+
it do
|
16
|
+
expect(subject.to_gnu).to eq('f(x) = pi * x**(3)')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -2,28 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe MyOperator do
|
6
|
-
describe '#to_gnu' do
|
7
|
-
it 'returns the gnu format' do
|
8
|
-
expect(subject.to_gnu).to eq('x**(pi)')
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '#to_tex' do
|
13
|
-
it 'returns the tex format' do
|
14
|
-
expect(subject.to_tex).to eq('x^{\pi}')
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '#to_f' do
|
19
|
-
subject { described_class.new(x: 2) }
|
20
|
-
|
21
|
-
it 'returns the result of the operation' do
|
22
|
-
expect(subject.to_f).to eq(2**Math::PI)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
5
|
describe Danica::Operator::Inverse do
|
28
6
|
subject { described_class.new(:x) }
|
29
7
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe MyOperator do
|
6
|
+
describe '#to_gnu' do
|
7
|
+
it 'returns the gnu format' do
|
8
|
+
expect(subject.to_gnu).to eq('x**(pi)')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#to_tex' do
|
13
|
+
it 'returns the tex format' do
|
14
|
+
expect(subject.to_tex).to eq('x^{\pi}')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#to_f' do
|
19
|
+
subject { described_class.new(x: 2) }
|
20
|
+
|
21
|
+
it 'returns the result of the operation' do
|
22
|
+
expect(subject.to_f).to eq(2**Math::PI)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Danica::Wrapper::Constant do
|
6
|
-
subject do
|
6
|
+
subject(:constant) do
|
7
7
|
described_class.new(gnuplot: 'pi', latex: '\pi', value: 3.141592)
|
8
8
|
end
|
9
9
|
|
@@ -18,7 +18,7 @@ describe Danica::Wrapper::Constant do
|
|
18
18
|
describe 'outputs' do
|
19
19
|
it do
|
20
20
|
output.each do |format, expected|
|
21
|
-
expect(
|
21
|
+
expect(constant.to(format)).to eq(expected)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Danica::Wrapper::Number do
|
6
|
-
subject do
|
6
|
+
subject(:wrapper) do
|
7
7
|
Danica::DSL.build do
|
8
8
|
number(3)
|
9
9
|
end
|
@@ -14,11 +14,11 @@ describe Danica::Wrapper::Number do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it do
|
17
|
-
expect(
|
17
|
+
expect(wrapper).to eq(number)
|
18
18
|
end
|
19
19
|
|
20
20
|
describe 'from basic operation' do
|
21
|
-
|
21
|
+
subject(:sum) do
|
22
22
|
Danica::DSL.build do
|
23
23
|
power(:x, 2) + 3
|
24
24
|
end
|
@@ -5,63 +5,63 @@ require 'spec_helper'
|
|
5
5
|
describe Danica::Wrapper::Variable do
|
6
6
|
describe '#to_tex' do
|
7
7
|
context 'when initializing with the name' do
|
8
|
-
subject do
|
8
|
+
subject(:variable) do
|
9
9
|
described_class.new(:x)
|
10
10
|
end
|
11
11
|
|
12
12
|
it do
|
13
|
-
expect(
|
13
|
+
expect(variable.to_tex).to eq('x')
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
context 'when initializing with a hash' do
|
18
|
-
subject do
|
18
|
+
subject(:variable) do
|
19
19
|
described_class.new(name: :x)
|
20
20
|
end
|
21
21
|
|
22
22
|
it do
|
23
|
-
expect(
|
23
|
+
expect(variable.to_tex).to eq('x')
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
context 'when initializing from DSL' do
|
28
|
-
subject do
|
28
|
+
subject(:variable) do
|
29
29
|
Danica::DSL.build do
|
30
30
|
variable(:x)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
it do
|
35
|
-
expect(
|
35
|
+
expect(variable.to_tex).to eq('x')
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
context 'when variable has value' do
|
40
|
-
subject do
|
40
|
+
subject(:variable) do
|
41
41
|
Danica::DSL.build do
|
42
42
|
variable(name: :frequency, latex: '\lambda', gnuplot: :f, value: 2)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
it do
|
47
|
-
expect(
|
47
|
+
expect(variable.to_tex).to eq('2')
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
describe '#to_f' do
|
53
|
-
subject do
|
53
|
+
subject(:variable) do
|
54
54
|
Danica::DSL.build do
|
55
55
|
variable(name: :x, value: 2)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
it do
|
60
|
-
expect(
|
60
|
+
expect(variable.to_f).to eq(2)
|
61
61
|
end
|
62
62
|
|
63
63
|
context 'when adding the value later' do
|
64
|
-
subject do
|
64
|
+
subject(:variable) do
|
65
65
|
Danica::DSL.build do
|
66
66
|
variable(:x)
|
67
67
|
end
|
@@ -75,14 +75,14 @@ describe Danica::Wrapper::Variable do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
it do
|
78
|
-
|
78
|
+
variable.value = 4
|
79
79
|
expect(power.to_f).to eq(16)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
84
|
describe 'custom outputs' do
|
85
|
-
subject do
|
85
|
+
subject(:variable) do
|
86
86
|
Danica::DSL.build do
|
87
87
|
variable(name: :frequency, latex: '\lambda', gnuplot: :f)
|
88
88
|
end
|
@@ -90,13 +90,13 @@ describe Danica::Wrapper::Variable do
|
|
90
90
|
|
91
91
|
describe '#to_tex' do
|
92
92
|
it do
|
93
|
-
expect(
|
93
|
+
expect(variable.to_tex).to eq('\lambda')
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
describe '#to_gnu' do
|
98
98
|
it do
|
99
|
-
expect(
|
99
|
+
expect(variable.to_gnu).to eq('f')
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe Danica do
|
6
6
|
describe 'formatting' do
|
7
|
-
subject do
|
7
|
+
subject(:expression) do
|
8
8
|
value = 1 / 3.0
|
9
9
|
described_class.build(:x) do
|
10
10
|
x + value
|
@@ -13,14 +13,14 @@ describe Danica do
|
|
13
13
|
|
14
14
|
describe '#to_tex' do
|
15
15
|
it 'formats the output' do
|
16
|
-
expect(
|
16
|
+
expect(expression.to_tex(decimals: 3)).to eq('x + 0.333')
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
describe '.build' do
|
22
22
|
context 'when building an expression' do
|
23
|
-
|
23
|
+
subject(:expression) do
|
24
24
|
described_class.build do
|
25
25
|
(number(1) + 2) * power(3, 4)
|
26
26
|
end
|