danica 2.7.1 → 2.7.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +71 -0
- data/.gitignore +6 -1
- data/.rubocop.yml +9 -0
- data/.rubocop_todo.yml +123 -0
- data/Dockerfile +22 -0
- data/Gemfile +2 -1
- data/README.md +9 -1
- data/Rakefile +4 -0
- data/config/check_specs.yml +13 -0
- data/config/rubycritc.rb +12 -0
- data/config/yardstick.rb +13 -0
- data/config/yardstick.yml +33 -0
- data/danica.gemspec +16 -9
- data/docker-compose.yml +14 -9
- data/lib/danica.rb +3 -1
- data/lib/danica/base_operations.rb +15 -7
- data/lib/danica/builder.rb +2 -0
- data/lib/danica/common.rb +24 -16
- data/lib/danica/dsl.rb +15 -9
- data/lib/danica/dsl/builder.rb +40 -0
- data/lib/danica/equation.rb +3 -3
- data/lib/danica/equation/builder.rb +2 -0
- data/lib/danica/exception.rb +14 -2
- data/lib/danica/expressable.rb +20 -16
- data/lib/danica/expression.rb +4 -2
- data/lib/danica/expression/gauss.rb +5 -5
- data/lib/danica/formatted.rb +34 -11
- data/lib/danica/function.rb +5 -3
- data/lib/danica/function/name.rb +2 -0
- data/lib/danica/operator.rb +13 -9
- data/lib/danica/operator/addition.rb +4 -7
- data/lib/danica/operator/chained.rb +4 -8
- data/lib/danica/operator/cos.rb +2 -1
- data/lib/danica/operator/division.rb +3 -2
- data/lib/danica/operator/exponential.rb +2 -1
- data/lib/danica/operator/functional.rb +3 -2
- data/lib/danica/operator/multiplication.rb +5 -7
- data/lib/danica/operator/power.rb +4 -3
- data/lib/danica/operator/sin.rb +2 -1
- data/lib/danica/operator/squared_root.rb +2 -1
- data/lib/danica/variables_holder.rb +27 -24
- data/lib/danica/variables_holder/alias_builder.rb +4 -4
- data/lib/danica/variables_holder/calculator.rb +2 -0
- data/lib/danica/variables_holder/store.rb +3 -2
- data/lib/danica/variables_holder/variables_builder.rb +2 -1
- data/lib/danica/version.rb +3 -1
- data/lib/danica/wrapper.rb +17 -9
- data/lib/danica/wrapper/constant.rb +10 -14
- data/lib/danica/wrapper/container.rb +4 -4
- data/lib/danica/wrapper/group.rb +3 -2
- data/lib/danica/wrapper/negative.rb +3 -1
- data/lib/danica/wrapper/number.rb +6 -3
- data/lib/danica/wrapper/plus_minus.rb +3 -1
- data/lib/danica/wrapper/variable.rb +13 -8
- data/scripts/check_readme.sh +6 -0
- data/scripts/rubycritic.sh +10 -0
- data/spec/integration/global/danica/formatted_spec.rb +87 -0
- data/spec/integration/global/danica/operator/addition_spec.rb +32 -0
- data/spec/integration/global/danica/operator/multiplication_spec.rb +106 -0
- data/spec/integration/{power_spec.rb → global/danica/operator/power_spec.rb} +4 -2
- data/spec/integration/global/danica/wrapper/negative_spec.rb +56 -0
- data/spec/integration/{plus_minus_spec.rb → global/danica/wrapper/plus_minus_spec.rb} +5 -4
- data/spec/integration/readme/constant_spec.rb +4 -1
- data/spec/integration/readme/danica/formatted_spec.rb +24 -0
- data/spec/integration/readme/danica_spec.rb +20 -4
- data/spec/integration/readme/equation_spec.rb +4 -2
- data/spec/integration/readme/expression_spec.rb +11 -8
- data/spec/integration/readme/function_spec.rb +11 -7
- data/spec/integration/readme/number_spec.rb +9 -8
- data/spec/integration/readme/operator_spec.rb +3 -1
- data/spec/integration/readme/variables_spec.rb +8 -6
- data/spec/lib/danica/common_spec.rb +79 -8
- data/spec/lib/danica/dsl_spec.rb +21 -18
- data/spec/lib/danica/equation_spec.rb +10 -8
- data/spec/lib/danica/expressable_spec.rb +5 -2
- data/spec/lib/danica/expression/gauss_spec.rb +6 -3
- data/spec/lib/danica/expression_spec.rb +48 -26
- data/spec/lib/danica/formatted_spec.rb +57 -24
- data/spec/lib/danica/function/name_spec.rb +3 -1
- data/spec/lib/danica/function_spec.rb +14 -10
- data/spec/lib/danica/operator/addition_spec.rb +18 -21
- data/spec/lib/danica/operator/cos_spec.rb +9 -8
- data/spec/lib/danica/operator/division_spec.rb +18 -17
- data/spec/lib/danica/operator/exponential_spec.rb +9 -8
- data/spec/lib/danica/operator/multiplication_spec.rb +19 -20
- data/spec/lib/danica/operator/power_spec.rb +17 -16
- data/spec/lib/danica/operator/sin_spec.rb +9 -8
- data/spec/lib/danica/operator/squared_root_spec.rb +9 -8
- data/spec/lib/danica/operator_spec.rb +13 -4
- data/spec/lib/danica/variables_holder/store_spec.rb +19 -13
- data/spec/lib/danica/variables_holder_spec.rb +76 -59
- data/spec/lib/danica/wrapper/constant_spec.rb +9 -2
- data/spec/lib/danica/wrapper/group_spec.rb +4 -1
- data/spec/lib/danica/wrapper/negative_spec.rb +4 -1
- data/spec/lib/danica/wrapper/number_spec.rb +8 -3
- data/spec/lib/danica/wrapper/plus_minus_spec.rb +4 -1
- data/spec/lib/danica/wrapper/variable_spec.rb +6 -3
- data/spec/lib/danica/wrapper_spec.rb +22 -16
- data/spec/lib/danica_spec.rb +6 -5
- data/spec/spec_helper.rb +3 -2
- data/spec/support/models/expression/baskara.rb +3 -3
- data/spec/support/models/expression/parabole.rb +2 -0
- data/spec/support/models/expression/quadratic_sum.rb +3 -1
- data/spec/support/models/expression/spatial.rb +2 -1
- data/spec/support/models/function/my_function.rb +3 -1
- data/spec/support/models/function/parabole.rb +1 -1
- data/spec/support/models/function/quadratic_sum.rb +2 -0
- data/spec/support/models/function/spatial.rb +2 -0
- data/spec/support/models/operator/inverse.rb +3 -1
- data/spec/support/models/operator/my_operator.rb +3 -1
- data/spec/support/models/variables_holder/dummy.rb +3 -1
- data/spec/support/shared_contexts/common.rb +4 -2
- data/spec/support/shared_examples/base_operations.rb +7 -4
- data/spec/support/shared_examples/common.rb +3 -1
- data/spec/support/shared_examples/operator/chained.rb +12 -6
- data/spec/support/shared_examples/operator/dual_term.rb +9 -8
- data/spec/support/shared_examples/operator/single_input.rb +7 -2
- data/spec/support/shared_examples/variable.rb +8 -4
- metadata +115 -30
- data/spec/integration/addition_spec.rb +0 -28
- data/spec/integration/multiplication_spec.rb +0 -44
- 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
|
-
|
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
|
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
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
data/spec/lib/danica_spec.rb
CHANGED
@@ -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 { -
|
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 '
|
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
|
-
|
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,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
|
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,5 +1,7 @@
|
|
1
|
-
|
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
|
-
|
2
|
-
|
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
|
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
|
-
|