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,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica
2
4
  class Wrapper::Container
3
5
  include Common
4
6
  attr_accessor :content
5
7
 
6
8
  delegate :to_f, :contentd?, :to, :to_tex, :to_gnu, :priority, :grouped?,
7
- :signaled?, :constant?, :valued?, :*, :+, :-, :/, :**,
9
+ :signaled?, :constant?, :valued?, :*, :+, :-, :/, :**, :-@,
8
10
  :variables, :variable?, to: :content
9
11
 
10
12
  default_value :container?, true
@@ -15,10 +17,8 @@ module Danica
15
17
 
16
18
  def ==(other)
17
19
  return content == other unless other.is_a?(self.class)
20
+
18
21
  content == other.content
19
22
  end
20
23
  end
21
24
  end
22
-
23
-
24
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica
2
4
  class Wrapper::Group
3
5
  include Common
@@ -24,9 +26,8 @@ module Danica
24
26
 
25
27
  def ==(other)
26
28
  return value == other unless other.is_a?(self.class)
29
+
27
30
  value == other.value
28
31
  end
29
32
  end
30
33
  end
31
-
32
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica
2
4
  class Wrapper::Negative
3
5
  include BaseOperations
@@ -25,8 +27,8 @@ module Danica
25
27
 
26
28
  def ==(other)
27
29
  return false unless other.class == self.class
30
+
28
31
  value == other.value
29
32
  end
30
33
  end
31
34
  end
32
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica
2
4
  class Wrapper::Number
3
5
  include BaseOperations
@@ -13,9 +15,10 @@ module Danica
13
15
  @value = value
14
16
  end
15
17
 
16
- def to(_, decimals: nil, **__)
18
+ def to(_format, decimals: nil, **_options)
17
19
  return value.to_i.to_s if value.to_i == value
18
- return ("%.#{decimals}f" % value).to_f.to_s if decimals
20
+ return format("%.#{decimals}f", value).to_f.to_s if decimals
21
+
19
22
  value.to_s
20
23
  end
21
24
 
@@ -29,8 +32,8 @@ module Danica
29
32
 
30
33
  def ==(other)
31
34
  return false unless other.class == self.class
35
+
32
36
  value == other.value
33
37
  end
34
38
  end
35
39
  end
36
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica
2
4
  class Wrapper::PlusMinus
3
5
  include BaseOperations
@@ -29,8 +31,8 @@ module Danica
29
31
 
30
32
  def ==(other)
31
33
  return false unless other.class == self.class
34
+
32
35
  value == other.value
33
36
  end
34
37
  end
35
38
  end
36
-
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Danica
2
4
  class Wrapper::Variable
3
5
  include BaseOperations
4
6
  include Common
5
7
 
6
- attr_accessor :value, :name, :latex, :gnuplot
8
+ attr_accessor :name, :latex, :gnuplot
9
+ attr_reader :value
7
10
 
8
11
  default_value :priority, 10
9
12
  default_value :is_grouped?, false
@@ -11,10 +14,10 @@ module Danica
11
14
 
12
15
  def initialize(*args)
13
16
  attrs = args.extract_options!
14
- attrs = args.as_hash(%i(name value latex gnuplot)).merge(attrs)
17
+ attrs = args.as_hash(%i[name value latex gnuplot]).merge(attrs)
15
18
 
16
19
  attrs.each do |key, value|
17
- self.public_send("#{key}=", value)
20
+ public_send("#{key}=", value)
18
21
  end
19
22
  end
20
23
 
@@ -24,19 +27,22 @@ module Danica
24
27
 
25
28
  def ==(other)
26
29
  return false unless other.class == self.class
27
- return other.value == value &&
28
- other.name == name &&
29
- other.latex == latex &&
30
- other.gnuplot == gnuplot
30
+
31
+ other.value == value &&
32
+ other.name == name &&
33
+ other.latex == latex &&
34
+ other.gnuplot == gnuplot
31
35
  end
32
36
 
33
37
  def to_tex(**options)
34
38
  return value.to_tex(options) if value
39
+
35
40
  (latex || name).to_s
36
41
  end
37
42
 
38
43
  def to_gnu(**options)
39
44
  return value.to_gnu(options) if value
45
+
40
46
  (gnuplot || name).to_s
41
47
  end
42
48
 
@@ -45,4 +51,3 @@ module Danica
45
51
  end
46
52
  end
47
53
  end
48
-
@@ -0,0 +1,6 @@
1
+ #! /bin/bash
2
+
3
+ PROJECT=danica
4
+ VERSION=$(grep VERSION lib/$PROJECT/version.rb | sed -e "s/.*'\(.*\)'/\1/g")
5
+
6
+ grep https://www.rubydoc.info/gems/$PROJECT/$VERSION README.md
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+
3
+ DIFF_LIST=$(git diff --name-only $CIRCLE_SHA1 $(git merge-base $CIRCLE_SHA1 origin/master) | grep "^lib/")
4
+
5
+ if [ ! -z "$DIFF_LIST" ]; then
6
+ mkdir -p tmp/rubycritic/compare
7
+ bundle exec rubycritic --format console --branch origin/master -t 0 --maximum-decrease 1 $DIFF_LIST
8
+ else
9
+ echo "No changes detected. Skipping rubycritic..."
10
+ fi
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Danica::Formatted do
6
+ describe 'integration of formatted objects' do
7
+ subject do
8
+ variable.tex
9
+ end
10
+
11
+ let(:variable) { Danica.build(:v) { v } }
12
+
13
+ context 'when interacting with a multiplication' do
14
+ let(:other) do
15
+ Danica.build(:x, :y) { x * y }
16
+ end
17
+
18
+ context 'when multipling another multiplication' do
19
+ let(:result) { subject * other }
20
+
21
+ it do
22
+ expect(result).to be_a(described_class)
23
+ end
24
+
25
+ it 'knows how to convert it to string' do
26
+ expect(result.to_s).to eq('v \\cdot x \\cdot y')
27
+ end
28
+ end
29
+
30
+ context 'when multiplicated by another multiplication' do
31
+ let(:result) { other * subject }
32
+
33
+ it do
34
+ expect(result).to be_a(described_class)
35
+ end
36
+
37
+ it 'knows how to convert it to string' do
38
+ expect(result.to_s).to eq('x \\cdot y \\cdot v')
39
+ end
40
+ end
41
+ end
42
+
43
+ context 'when interacting with a sum' do
44
+ let(:other) do
45
+ Danica.build(:x, :y) { x + y }
46
+ end
47
+
48
+ context 'when summing another sum' do
49
+ let(:result) { subject + other }
50
+
51
+ it do
52
+ expect(result).to be_a(described_class)
53
+ end
54
+
55
+ it 'knows how to convert it to string' do
56
+ expect(result.to_s).to eq('v + x + y')
57
+ end
58
+ end
59
+
60
+ context 'when added by another sum' do
61
+ let(:result) { other + subject }
62
+
63
+ it do
64
+ expect(result).to be_a(described_class)
65
+ end
66
+
67
+ it 'knows how to convert it to string' do
68
+ expect(result.to_s).to eq('x + y + v')
69
+ end
70
+ end
71
+ end
72
+
73
+ context 'when operating multiplication and subtraction all toguether' do
74
+ let(:variable) { Danica::Wrapper::Variable.new(:v) }
75
+ let(:x) { Danica::Wrapper::Variable.new(:x) }
76
+ let(:result) { x * -subject }
77
+
78
+ it do
79
+ expect(result).to be_a(described_class)
80
+ end
81
+
82
+ it 'knows how to convert it to string' do
83
+ expect(result.to_s).to eq('x \cdot \left(-v\right)')
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Danica::Operator::Addition do
6
+ describe 'integration' do
7
+ describe 'with negative and positivenegative (+/-) numbers' do
8
+ subject do
9
+ described_class.new(
10
+ Danica::Wrapper::Negative.new(1),
11
+ 2,
12
+ -3,
13
+ 4,
14
+ Danica::Wrapper::PlusMinus.new(5),
15
+ Danica::Wrapper::Number.new(-6)
16
+ )
17
+ end
18
+
19
+ describe '#to_gnu' do
20
+ it 'returns the correct string' do
21
+ expect(subject.to_gnu).to eq('-1 + 2 -3 + 4 + 5 -6')
22
+ end
23
+ end
24
+
25
+ describe '#to_tex' do
26
+ it 'returns the correct string' do
27
+ expect(subject.to_tex).to eq('-1 + 2 -3 + 4 \pm 5 -6')
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Danica::Operator::Multiplication do
6
+ describe 'of number and addition' do
7
+ subject do
8
+ described_class.new(
9
+ 3, Danica::Operator::Addition.new(2, 4)
10
+ )
11
+ end
12
+
13
+ describe '#to_gnu' do
14
+ it 'returns the correct string' do
15
+ expect(subject.to_gnu).to eq('3 * (2 + 4)')
16
+ end
17
+ end
18
+
19
+ describe '#to_gnu' do
20
+ it 'returns the correct string' do
21
+ expect(subject.to_tex).to eq('3 \cdot \left(2 + 4\right)')
22
+ end
23
+ end
24
+ end
25
+
26
+ describe 'of additions' do
27
+ subject do
28
+ described_class.new(
29
+ Danica::Operator::Addition.new(1, 2),
30
+ Danica::Operator::Addition.new(3, 4)
31
+ )
32
+ end
33
+
34
+ describe '#to_gnu' do
35
+ it 'returns the correct string' do
36
+ expect(subject.to_gnu).to eq('(1 + 2) * (3 + 4)')
37
+ end
38
+ end
39
+
40
+ describe '#to_tex' do
41
+ it 'returns the correct string' do
42
+ expect(subject.to_tex).to eq('\left(1 + 2\right) \cdot \left(3 + 4\right)')
43
+ end
44
+ end
45
+ end
46
+
47
+ describe 'when calling * operator' do
48
+ subject do
49
+ described_class.new(:x, :y)
50
+ end
51
+
52
+ let(:variable) { Danica::Wrapper::Variable.new(:v) }
53
+ let(:result) { subject * variable }
54
+
55
+ it do
56
+ expect(result).to be_a(described_class)
57
+ end
58
+
59
+ it 'knows how to order variables' do
60
+ expect(result.to_gnu).to eq('x * y * v')
61
+ end
62
+
63
+ context 'when called from the other' do
64
+ let(:result) { variable * subject }
65
+
66
+ it do
67
+ expect(result).to be_a(described_class)
68
+ end
69
+
70
+ it 'knows how to order variables' do
71
+ expect(result.to_gnu).to eq('v * x * y')
72
+ end
73
+ end
74
+ end
75
+
76
+ context 'when multiplicating a negative number' do
77
+ let(:x) { Danica::Wrapper::Variable.new(:x) }
78
+ let(:y) { Danica::Wrapper::Variable.new(:y) }
79
+ let(:negative) { -y }
80
+ let(:result) { x * negative }
81
+
82
+ it do
83
+ expect(result).to be_a(described_class)
84
+ end
85
+
86
+ it 'knows how to order variables' do
87
+ expect(result.to_gnu).to eq('x * (-y)')
88
+ end
89
+
90
+ context 'when negative parcel is an expression' do
91
+ let(:negative) { Danica.build(:y) { -y } }
92
+
93
+ it 'knows how to order variables' do
94
+ expect(result.to_gnu).to eq('x * (-y)')
95
+ end
96
+ end
97
+
98
+ context 'when negative is the negative of an expression' do
99
+ let(:negative) { -Danica.build(:y) { y } }
100
+
101
+ it 'knows how to order variables' do
102
+ expect(result.to_gnu).to eq('x * (-y)')
103
+ end
104
+ end
105
+ end
106
+ end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
- describe 'integration of power' do
5
+ describe Danica::Operator::Power do
4
6
  describe 'of additions' do
5
7
  subject do
6
- Danica::Operator::Power.new(
8
+ described_class.new(
7
9
  Danica::Operator::Addition.new(3, 4),
8
10
  Danica::Operator::Addition.new(5, 6)
9
11
  )
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Danica::Wrapper::Negative do
6
+ describe 'with a addition' do
7
+ subject do
8
+ described_class.new(
9
+ Danica::Operator::Addition.new(1, 2, 3)
10
+ )
11
+ end
12
+
13
+ describe '#to_gnu' do
14
+ it 'returns the correct string' do
15
+ expect(subject.to_gnu).to eq('-(1 + 2 + 3)')
16
+ end
17
+ end
18
+
19
+ describe '#to_tex' do
20
+ it 'returns the correct string' do
21
+ expect(subject.to_tex).to eq('-\left(1 + 2 + 3\right)')
22
+ end
23
+ end
24
+
25
+ describe 'when it is the result of an expression' do
26
+ subject do
27
+ x - negative_parcel
28
+ end
29
+
30
+ let(:x) { Danica::Wrapper::Variable.new(:x) }
31
+ let(:y) { Danica::Wrapper::Variable.new(:y) }
32
+ let(:z) { Danica::Wrapper::Variable.new(:z) }
33
+ let(:negative_parcel) { y + z }
34
+
35
+ it 'wraps parcel into a group' do
36
+ expect(subject.to_gnu).to eq('x -(y + z)')
37
+ end
38
+
39
+ context 'when the negative parcel is an expression' do
40
+ let(:negative_parcel) { Danica.build(:y, :z) { y + z } }
41
+
42
+ it 'wraps parcel into a group' do
43
+ expect(subject.to_gnu).to eq('x -(y + z)')
44
+ end
45
+
46
+ context 'when negative has just one element' do
47
+ let(:negative_parcel) { Danica.build(:y) { y } }
48
+
49
+ it 'wraps parcel into a group' do
50
+ expect(subject.to_gnu).to eq('x -y')
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end