danica 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c3aa11c78083f2cf4dbf106b5edc4ae7370dc2a
4
- data.tar.gz: d16d37bfebfd039a1469dec4029f927cd5374fed
3
+ metadata.gz: d9452b255fbf76168b5420387cfc63e578f61e2d
4
+ data.tar.gz: 52e4a1dc89abe24a06b337d6fee11a09670455d4
5
5
  SHA512:
6
- metadata.gz: ec1d1e75b021be3608dd5f2aae2662fc8104d9cbd4b10e27fb4d6ca8aeb8c5c09542e58443799284c30965f4d3d5b5d2d5f5dbd659645c7b36d87b143f1d933a
7
- data.tar.gz: de6db957793d4f43a74b5c9c311ed82cafdd6f016dbe260b7d09d66418297d1d35eacf47a6909d8376efaf3ab33f3201c190d5bc48e40dcbe546b1a6d1729083
6
+ metadata.gz: 8e703c6ebbecb67468d686145e91546209a1330c68e2f02992313b7255ea6439970fdd817addaa00e0f88e9bf6cece0fdb00ce0c1ea7c9e99d383ac3b48c4fef
7
+ data.tar.gz: 3e495695b72e62546b941d7a6838657574dbd54bc94044177dd90c39a77dbad1170cac77ccea7be96eaa9843145f68789f3e0b2c7e543db50dc86320ea873f05
data/README.md CHANGED
@@ -41,12 +41,12 @@ class MyOperator < Danica::Operator
41
41
 
42
42
  private
43
43
 
44
- def tex_string
45
- #implement tex_string here
44
+ def to_tex
45
+ #implement to_tex here
46
46
  end
47
47
 
48
- def gnu_string
49
- #implement gnu_string here
48
+ def to_gnu
49
+ #implement to_gnu here
50
50
  end
51
51
  end
52
52
  ```
@@ -61,11 +61,11 @@ class Danica::Inverse
61
61
 
62
62
  private
63
63
 
64
- def tex_string
64
+ def to_tex
65
65
  "(#{value.to_tex})^{-1}"
66
66
  end
67
67
 
68
- def gnu_string
68
+ def to_gnu
69
69
  "(#{value.to_gnu}) ** -1"
70
70
  end
71
71
  end
@@ -10,18 +10,6 @@ module Danica
10
10
  raise 'Not IMplemented yet'
11
11
  end
12
12
 
13
- def to_tex
14
- Number.new(to_f).to_tex
15
- rescue Exception::NotDefined
16
- tex_string
17
- end
18
-
19
- def to_gnu
20
- Number.new(to_f).to_gnu
21
- rescue Exception::NotDefined
22
- gnu_string
23
- end
24
-
25
13
  def variables=(variables)
26
14
  @variables = variables.map { |v| wrap_value(v) }
27
15
  end
@@ -49,14 +37,6 @@ module Danica
49
37
  def non_valued_variables
50
38
  variables.reject(&:valued?)
51
39
  end
52
-
53
- def tex_string
54
- raise 'Not IMplemented yet'
55
- end
56
-
57
- def gnu_string
58
- raise 'Not IMplemented yet'
59
- end
60
40
 
61
41
  def wrap_value(value)
62
42
  return Number.new(value) if value.is_a?(Numeric)
@@ -6,13 +6,11 @@ module Danica
6
6
  Math.cos(variable.to_f)
7
7
  end
8
8
 
9
- private
10
-
11
- def tex_string
9
+ def to_tex
12
10
  "cos(#{variable.to_tex})"
13
11
  end
14
12
 
15
- def gnu_string
13
+ def to_gnu
16
14
  "cos(#{variable.to_gnu})"
17
15
  end
18
16
  end
@@ -6,13 +6,11 @@ module Danica
6
6
  numerator.to_f / denominator.to_f
7
7
  end
8
8
 
9
- private
10
-
11
- def tex_string
9
+ def to_tex
12
10
  "\\frac{#{numerator.to_tex}}{#{denominator.to_tex}}"
13
11
  end
14
12
 
15
- def gnu_string
13
+ def to_gnu
16
14
  "#{numerator.to_gnu}/#{denominator.to_gnu}"
17
15
  end
18
16
  end
@@ -6,13 +6,11 @@ module Danica
6
6
  Math.exp(exponent.to_f)
7
7
  end
8
8
 
9
- private
10
-
11
- def tex_string
9
+ def to_tex
12
10
  "e^{#{exponent.to_tex}}"
13
11
  end
14
12
 
15
- def gnu_string
13
+ def to_gnu
16
14
  "exp(#{exponent.to_gnu})"
17
15
  end
18
16
  end
@@ -11,10 +11,12 @@ module Danica
11
11
  end
12
12
 
13
13
  def to_tex
14
- "(#{value.to_tex})"
14
+ "\\left(#{value.to_tex}\\right)"
15
15
  end
16
16
 
17
- alias_method :to_gnu, :to_tex
17
+ def to_gnu
18
+ "(#{value.to_gnu})"
19
+ end
18
20
  end
19
21
  end
20
22
 
@@ -10,27 +10,19 @@ module Danica
10
10
  variables.include?(value)
11
11
  end
12
12
 
13
- private
14
-
15
- def repack(other)
16
- other_variables = other.is_a?(self.class) ? other.variables : [ other ]
17
- self.class.new(variables + other_variables)
18
- end
19
-
20
- def tex_string
21
- (numeric_to_tex + non_numeric_variables.map(&:to_tex)).join(" #{tex_symbol} ")
13
+ def to_tex
14
+ variables.map(&:to_tex).join(" #{tex_symbol} ")
22
15
  end
23
16
 
24
- def gnu_string
25
- (numeric_to_tex + non_numeric_variables.map(&:to_gnu)).join(" #{gnu_symbol} ")
17
+ def to_gnu
18
+ variables.map(&:to_gnu).join(" #{gnu_symbol} ")
26
19
  end
27
20
 
28
- def numeric_variables
29
- variables.select { |v| v.valued? }
30
- end
21
+ private
31
22
 
32
- def non_numeric_variables
33
- variables.reject { |v| v.valued? }
23
+ def repack(other)
24
+ other_variables = other.is_a?(self.class) ? other.variables : [ other ]
25
+ self.class.new(variables + other_variables)
34
26
  end
35
27
 
36
28
  def chain(numbers)
@@ -38,11 +30,6 @@ module Danica
38
30
  chain_operation(a,b)
39
31
  end.to_f
40
32
  end
41
-
42
- def numeric_to_tex
43
- return [] if numeric_variables.empty?
44
- [ Number.new(chain(numeric_variables.map(&:to_f))).to_tex ]
45
- end
46
33
  end
47
34
  end
48
35
  end
@@ -6,13 +6,11 @@ module Danica
6
6
  base.to_f ** exponent.to_f
7
7
  end
8
8
 
9
- private
10
-
11
- def tex_string
9
+ def to_tex
12
10
  "#{base.to_tex}^{#{exponent.to_tex}}"
13
11
  end
14
12
 
15
- def gnu_string
13
+ def to_gnu
16
14
  "#{base.to_gnu}**#{exponent.to_gnu}"
17
15
  end
18
16
  end
@@ -6,13 +6,11 @@ module Danica
6
6
  Math.sin(variable.to_f)
7
7
  end
8
8
 
9
- private
10
-
11
- def tex_string
9
+ def to_tex
12
10
  "sin(#{variable.to_tex})"
13
11
  end
14
12
 
15
- def gnu_string
13
+ def to_gnu
16
14
  "sin(#{variable.to_gnu})"
17
15
  end
18
16
  end
@@ -6,13 +6,11 @@ module Danica
6
6
  Math.sqrt(variable.to_f)
7
7
  end
8
8
 
9
- private
10
-
11
- def tex_string
9
+ def to_tex
12
10
  "\\sqrt{#{variable.to_tex}}"
13
11
  end
14
12
 
15
- def gnu_string
13
+ def to_gnu
16
14
  "sqrt(#{variable.to_gnu})"
17
15
  end
18
16
  end
@@ -12,13 +12,11 @@ module Danica
12
12
  '+'
13
13
  end
14
14
 
15
- def gnu_symbol
16
- '+'
17
- end
18
-
19
15
  def chain_operation(a, b)
20
16
  a + b
21
17
  end
18
+
19
+ alias_method :gnu_symbol, :tex_symbol
22
20
  end
23
21
  end
24
22
 
@@ -1,3 +1,3 @@
1
1
  module Danica
2
- VERSION = '2.0.4'
2
+ VERSION = '2.0.5'
3
3
  end
@@ -9,7 +9,8 @@ describe Danica::Cos do
9
9
  it_behaves_like 'a operator with a single input value', {
10
10
  variable_value: Math::PI,
11
11
  expected_number: -1.0,
12
- expected_number_text: '-1',
12
+ expected_number_tex: 'cos(3.141592653589793)',
13
+ expected_number_gnu: 'cos(3.141592653589793)',
13
14
  expected_tex: 'cos(X)',
14
15
  expected_gnu: 'cos(X)'
15
16
  }
@@ -12,12 +12,12 @@ describe Danica::Division do
12
12
  calculated: 1.0 / 2.0,
13
13
  to_tex: {
14
14
  string_expected: '\frac{X1}{X2}',
15
- numeric_string_expected: '0.5',
15
+ numeric_string_expected: '\frac{2}{4}',
16
16
  partial_string_expected: '\frac{2}{X2}'
17
17
  },
18
18
  to_gnu: {
19
19
  string_expected: 'X1/X2',
20
- numeric_string_expected: '0.5',
20
+ numeric_string_expected: '2/4',
21
21
  partial_string_expected: '2/X2'
22
22
  }
23
23
  }
@@ -9,7 +9,8 @@ describe Danica::Exponential do
9
9
  it_behaves_like 'a operator with a single input value', {
10
10
  variable_value: 2,
11
11
  expected_number: Math.exp(2),
12
- expected_number_text: Math.exp(2).to_s,
12
+ expected_number_tex: 'e^{2}',
13
+ expected_number_gnu: 'exp(2)',
13
14
  expected_tex: 'e^{X}',
14
15
  expected_gnu: 'exp(X)'
15
16
  }
@@ -231,7 +231,7 @@ describe Danica::Function do
231
231
 
232
232
  describe '#to_tex' do
233
233
  context 'when creating the spatial operator for constantly accelerated movement' do
234
- let(:expected) { '\frac{1}{\sqrt{6.283185307179586 \cdot v^{2}}} \cdot e^{-\frac{(x + -u)^{2}}{2 \cdot v^{2}}}' }
234
+ let(:expected) { '\frac{1}{\sqrt{2 \cdot \pi \cdot v^{2}}} \cdot e^{-\frac{\left(x + -u\right)^{2}}{2 \cdot v^{2}}}' }
235
235
 
236
236
  it 'return the latex format CAM' do
237
237
  expect(subject.to_tex).to eq(expected)
@@ -241,7 +241,7 @@ describe Danica::Function do
241
241
 
242
242
  describe '#to_gnu' do
243
243
  context 'when creating the spatial operator for constantly accelerated movement' do
244
- let(:expected) { '1/sqrt(6.283185307179586 * v**2) * exp(-(x + -u)**2/2 * v**2)' }
244
+ let(:expected) { '1/sqrt(2 * pi * v**2) * exp(-(x + -u)**2/2 * v**2)' }
245
245
 
246
246
  it 'return the latex format CAM' do
247
247
  expect(subject.to_gnu).to eq(expected)
@@ -12,12 +12,12 @@ describe Danica::Power do
12
12
  calculated: 9.0,
13
13
  to_tex: {
14
14
  string_expected: 'X1^{X2}',
15
- numeric_string_expected: '9',
15
+ numeric_string_expected: '3^{2}',
16
16
  partial_string_expected: '3^{X2}'
17
17
  },
18
18
  to_gnu: {
19
19
  string_expected: 'X1**X2',
20
- numeric_string_expected: '9',
20
+ numeric_string_expected: '3**2',
21
21
  partial_string_expected: '3**X2'
22
22
  }
23
23
  }
@@ -22,13 +22,13 @@ describe Danica::Product do
22
22
  numeric_variables: [ 1.5, 2, 3.5 ],
23
23
  to_tex: {
24
24
  string_expected: %w(X1 X2 X3 X4).join(' \cdot '),
25
- integer_expected: %w(3 X3 X4).join(' \cdot '),
26
- float_expected: '10.5 \cdot X4'
25
+ integer_expected: %w(1.5 2 X3 X4).join(' \cdot '),
26
+ float_expected: %w(1.5 2 3.5 X4).join(' \cdot ')
27
27
  },
28
28
  to_gnu: {
29
29
  string_expected: %w(X1 X2 X3 X4).join(' * '),
30
- integer_expected: %w(3 X3 X4).join(' * '),
31
- float_expected: '10.5 * X4'
30
+ integer_expected: %w(1.5 2 X3 X4).join(' * '),
31
+ float_expected: %w(1.5 2 3.5 X4).join(' * '),
32
32
  }
33
33
  }
34
34
  end
@@ -9,7 +9,8 @@ describe Danica::Sin do
9
9
  it_behaves_like 'a operator with a single input value', {
10
10
  variable_value: Math::PI / 2.0,
11
11
  expected_number: 1.0,
12
- expected_number_text: '1',
12
+ expected_number_tex: 'sin(1.5707963267948966)',
13
+ expected_number_gnu: 'sin(1.5707963267948966)',
13
14
  expected_tex: 'sin(X)',
14
15
  expected_gnu: 'sin(X)'
15
16
  }
@@ -9,7 +9,8 @@ describe Danica::SquaredRoot do
9
9
  it_behaves_like 'a operator with a single input value', {
10
10
  variable_value: 9,
11
11
  expected_number: 3.0,
12
- expected_number_text: '3',
12
+ expected_number_tex: '\sqrt{9}',
13
+ expected_number_gnu: 'sqrt(9)',
13
14
  expected_tex: '\sqrt{X}',
14
15
  expected_gnu: 'sqrt(X)'
15
16
  }
@@ -23,16 +23,16 @@ describe Danica::Sum do
23
23
 
24
24
  it_behaves_like 'a operator that joins many variables with same operation', {
25
25
  calculated: 10,
26
- numeric_variables: [ 1.5, 2.5, 3.5 ],
26
+ numeric_variables: [ 1.5, 3.0, 3.5 ],
27
27
  to_tex: {
28
28
  string_expected: 'X1 + X2 + X3 + X4',
29
- integer_expected: '4 + X3 + X4',
30
- float_expected: '7.5 + X4'
29
+ integer_expected: '1.5 + 3 + X3 + X4',
30
+ float_expected: '1.5 + 3 + 3.5 + X4'
31
31
  },
32
32
  to_gnu: {
33
33
  string_expected: 'X1 + X2 + X3 + X4',
34
- integer_expected: '4 + X3 + X4',
35
- float_expected: '7.5 + X4'
34
+ integer_expected: '1.5 + 3 + X3 + X4',
35
+ float_expected: '1.5 + 3 + 3.5 + X4'
36
36
  }
37
37
  }
38
38
  end
@@ -90,14 +90,14 @@ shared_examples 'a operator that knows how to write to a string' do |command, ar
90
90
  end
91
91
  end
92
92
 
93
- it 'outputs a text format with colapsed numbers' do
93
+ it 'outputs a text format of numbers' do
94
94
  expect(subject.public_send(command)).to eq(integer_expected)
95
95
  end
96
96
 
97
- context 'when numeric variables calculated is a float value' do
97
+ context 'when numeric variables are a float value' do
98
98
  let(:numeric_variables_index) { 2 }
99
99
 
100
- it 'outputs a text format with colapsed numbers' do
100
+ it 'outputs a text format of numbers' do
101
101
  expect(subject.public_send(command)).to eq(float_expected)
102
102
  end
103
103
  end
@@ -36,7 +36,7 @@ shared_examples 'a operator that has two terms and knows how to calculate it' do
36
36
  end
37
37
  end
38
38
 
39
- context 'when one the variables are numbers' do
39
+ context 'when one of the variables is number' do
40
40
  before do
41
41
  variables[0] = values[0]
42
42
  end
@@ -1,5 +1,5 @@
1
1
  shared_examples 'a operator with a single input value' do |arguments|
2
- include_context 'variables are initialized', arguments, *%w(variable_value expected_number expected_tex expected_number_text expected_gnu)
2
+ include_context 'variables are initialized', arguments, *%w(variable_value expected_number expected_tex expected_number_tex expected_gnu expected_number_gnu)
3
3
  let(:variable) { { name: "X", value: variable_value } }
4
4
  subject { described_class.new(variable) }
5
5
 
@@ -41,7 +41,7 @@ shared_examples 'a operator with a single input value' do |arguments|
41
41
  subject.variables[0].value = variable_value
42
42
  end
43
43
  it 'prints both numbers' do
44
- expect(subject.to_tex).to eq(expected_number_text)
44
+ expect(subject.to_tex).to eq(expected_number_tex)
45
45
  end
46
46
  end
47
47
  end
@@ -60,7 +60,7 @@ shared_examples 'a operator with a single input value' do |arguments|
60
60
  subject.variables[0].value = variable_value
61
61
  end
62
62
  it 'prints both numbers' do
63
- expect(subject.to_gnu).to eq(expected_number_text)
63
+ expect(subject.to_gnu).to eq(expected_number_gnu)
64
64
  end
65
65
  end
66
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danica
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darthjee