danica 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d679c98744cf0b50bc7cdb70cb70e2d08c99dc29
4
- data.tar.gz: d21601f2005622dd2cb2ef9248c1fc42ee4bc9b7
3
+ metadata.gz: 8d8ae393046bb15fcbcd46af8e9430aa50bbbad6
4
+ data.tar.gz: 835a4b71b6348e1a3da11a34771d4b4864a37894
5
5
  SHA512:
6
- metadata.gz: 9b1add172a4a3486cd170bd410a163c613684a6c96897be6b83be1cbe3525e02d78f8efcb259cef544f4ed518460a47fbf545ead9849f6749b97a696083705c3
7
- data.tar.gz: e2402e6dbcd8b71f8ed81c9029aba06ab87a418239a7927ec54f7a631cc1a0d4bb8116d1bf8e477e4cb1e0804197dde9353d50f68c07b3183a26fdcebe2071ff
6
+ metadata.gz: 74eb602d0265187cc3505c25b0870d9564a05bb82e6ae072efdca3cba8be6c9a5b04c243c179a68e8fc94f5f5e73fdfca5c941e547ff1d24e4197f14c78e02ba
7
+ data.tar.gz: a389e884fa35861559a76b78ee907b6525a42a3274ddb6ee25d41a896361b5df5003328b2186fdc6d4a1382b9944b80318c022256e22861b27bd551ec7850425
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danica (0.2.0)
4
+ danica (0.3.0)
5
5
  activemodel
6
6
  activesupport
7
7
 
@@ -6,6 +6,7 @@ class Danica::Function
6
6
  require 'danica/function/sum'
7
7
  require 'danica/function/division'
8
8
  require 'danica/function/power'
9
+ require 'danica/function/square_root'
9
10
 
10
11
  attr_accessor :name, :variables
11
12
 
@@ -8,6 +8,8 @@ module Danica
8
8
  end
9
9
 
10
10
  def to_tex
11
+ Number.new(to_f).to_tex
12
+ rescue NotDefined
11
13
  "\\frac{#{numerator.to_tex}}{#{denominator.to_tex}}"
12
14
  end
13
15
 
@@ -8,7 +8,9 @@ module Danica
8
8
  end
9
9
 
10
10
  def to_tex
11
- [ base, exponent ].map(&:to_tex).join('^')
11
+ Number.new(to_f).to_tex
12
+ rescue NotDefined
13
+ "#{base.to_tex}^{#{exponent.to_tex}}"
12
14
  end
13
15
 
14
16
  def base=(value)
@@ -0,0 +1,23 @@
1
+ module Danica
2
+ class Function
3
+ class SquareRoot < Function
4
+ attr_reader :variable
5
+
6
+ def to_f
7
+ Math.sqrt(variable.to_f)
8
+ end
9
+
10
+ def to_tex
11
+ Number.new(to_f).to_tex
12
+ rescue NotDefined
13
+ "\\sqrt{#{variable.to_tex}}"
14
+ end
15
+
16
+ def variable=(value)
17
+ @variable = wrap_value(value)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+
@@ -11,8 +11,8 @@ module Danica
11
11
  end
12
12
 
13
13
  def to_tex
14
- return value.to_i if value.to_i == value
15
- value
14
+ return value.to_i.to_s if value.to_i == value
15
+ value.to_s
16
16
  end
17
17
 
18
18
  def valued?
@@ -1,3 +1,3 @@
1
1
  module Danica
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -72,8 +72,8 @@ describe Danica::Function::Division do
72
72
  end
73
73
 
74
74
  context 'when both variables are numeric' do
75
- it 'prints both numbers' do
76
- expect(subject.to_tex).to eq('\frac{2}{4}')
75
+ it 'prints the result of the division' do
76
+ expect(subject.to_tex).to eq('0.5')
77
77
  end
78
78
  end
79
79
 
@@ -14,7 +14,7 @@ describe Danica::Function::Power do
14
14
 
15
15
  describe 'to_f' do
16
16
  context 'when variables are not numbers but have value' do
17
- it 'returns the division of the values' do
17
+ it 'returns the power of the values' do
18
18
  expect(subject.to_f).to eq(9.0)
19
19
  end
20
20
 
@@ -26,7 +26,7 @@ describe Danica::Function::Power do
26
26
  context 'when all the variables are numbers' do
27
27
  let(:variables) { [ 3, 2 ] }
28
28
 
29
- it 'returns the division of the values' do
29
+ it 'returns the power of the values' do
30
30
  expect(subject.to_f).to eq(9.0)
31
31
  end
32
32
 
@@ -40,7 +40,7 @@ describe Danica::Function::Power do
40
40
  variables[0] = 3
41
41
  end
42
42
 
43
- it 'returns the division of the values' do
43
+ it 'returns the power of the values' do
44
44
  expect(subject.to_f).to eq(9.0)
45
45
  end
46
46
 
@@ -57,7 +57,7 @@ describe Danica::Function::Power do
57
57
  end
58
58
 
59
59
  it 'returns a latex format fraction' do
60
- expect(subject.to_tex).to eq('X1^X2')
60
+ expect(subject.to_tex).to eq('X1^{X2}')
61
61
  end
62
62
  end
63
63
 
@@ -66,14 +66,14 @@ describe Danica::Function::Power do
66
66
  subject.exponent.value = nil
67
67
  end
68
68
 
69
- it 'returns the number instead of the value' do
70
- expect(subject.to_tex).to eq('3^X2')
69
+ it 'returns both variables' do
70
+ expect(subject.to_tex).to eq('3^{X2}')
71
71
  end
72
72
  end
73
73
 
74
74
  context 'when both variables are numeric' do
75
- it 'prints both numbers' do
76
- expect(subject.to_tex).to eq('3^2')
75
+ it 'prints the final calculation' do
76
+ expect(subject.to_tex).to eq('9')
77
77
  end
78
78
  end
79
79
 
@@ -83,8 +83,8 @@ describe Danica::Function::Power do
83
83
  subject.exponent.value = nil
84
84
  end
85
85
 
86
- it 'prints both numbers' do
87
- expect(subject.to_tex).to eq('1^X2')
86
+ it 'prints both variables' do
87
+ expect(subject.to_tex).to eq('1^{X2}')
88
88
  end
89
89
  end
90
90
  end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe Danica::Function::SquareRoot do
4
+ let(:variables_number) { 4 }
5
+ let(:variable) { { name: "X", value: 9 } }
6
+ let(:subject) do
7
+ described_class.new(variable: variable)
8
+ end
9
+
10
+ describe 'to_f' do
11
+ context 'when variables are not numbers but have value' do
12
+ it 'returns the division of the values' do
13
+ expect(subject.to_f).to eq(3.0)
14
+ end
15
+
16
+ it do
17
+ expect(subject.to_f).to be_a(Float)
18
+ end
19
+ end
20
+
21
+ context 'when the variable is a number' do
22
+ let(:variable) { 9 }
23
+
24
+ it 'returns the squared root of the value' do
25
+ expect(subject.to_f).to eq(3.0)
26
+ end
27
+
28
+ it do
29
+ expect(subject.to_f).to be_a(Float)
30
+ end
31
+ end
32
+ end
33
+
34
+ describe 'to_tex' do
35
+ context 'when variables have no value' do
36
+ let(:variable) { :X }
37
+
38
+ it 'returns a latex format fraction' do
39
+ expect(subject.to_tex).to eq('\sqrt{X}')
40
+ end
41
+ end
42
+
43
+ context 'when the variable is numeric' do
44
+ before do
45
+ subject.variable.value = 9
46
+ end
47
+ it 'prints both numbers' do
48
+ expect(subject.to_tex).to eq('3')
49
+ end
50
+ end
51
+ end
52
+ end
53
+
@@ -46,7 +46,7 @@ describe Danica::Function do
46
46
  end
47
47
 
48
48
  let(:subject) { described_class::Spatial.new(variables) }
49
- let(:expected) { 'S_0 + V_0 \cdot t + \frac{a \cdot t^2}{2}' }
49
+ let(:expected) { 'S_0 + V_0 \cdot t + \frac{a \cdot t^{2}}{2}' }
50
50
 
51
51
  it 'return the latex format CAM' do
52
52
  expect(subject.to_tex).to eq(expected)
@@ -10,7 +10,9 @@ describe Danica::Variable do
10
10
  let(:value) { 100 }
11
11
  let(:subject) { described_class.new(value: value) }
12
12
 
13
- it { expect(subject.to_f).to eq(value) }
13
+ it 'returns the value' do
14
+ expect(subject.to_f).to eq(value)
15
+ end
14
16
  end
15
17
  end
16
18
 
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: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darthjee
@@ -142,6 +142,7 @@ files:
142
142
  - lib/danica/function/division.rb
143
143
  - lib/danica/function/power.rb
144
144
  - lib/danica/function/product.rb
145
+ - lib/danica/function/square_root.rb
145
146
  - lib/danica/function/sum.rb
146
147
  - lib/danica/not_defined.rb
147
148
  - lib/danica/number.rb
@@ -150,6 +151,7 @@ files:
150
151
  - spec/lib/danica/function/division_spec.rb
151
152
  - spec/lib/danica/function/power_spec.rb
152
153
  - spec/lib/danica/function/product_spec.rb
154
+ - spec/lib/danica/function/square_root_spec.rb
153
155
  - spec/lib/danica/function/sum_spec.rb
154
156
  - spec/lib/danica/function_spec.rb
155
157
  - spec/lib/danica/variable_spec.rb
@@ -182,6 +184,7 @@ test_files:
182
184
  - spec/lib/danica/function/division_spec.rb
183
185
  - spec/lib/danica/function/power_spec.rb
184
186
  - spec/lib/danica/function/product_spec.rb
187
+ - spec/lib/danica/function/square_root_spec.rb
185
188
  - spec/lib/danica/function/sum_spec.rb
186
189
  - spec/lib/danica/function_spec.rb
187
190
  - spec/lib/danica/variable_spec.rb