danica 2.4.2 → 2.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/danica/common.rb +26 -4
- data/lib/danica/dsl.rb +1 -0
- data/lib/danica/exception.rb +3 -1
- data/lib/danica/function.rb +18 -4
- data/lib/danica/function/gauss.rb +6 -20
- data/lib/danica/operator.rb +1 -1
- data/lib/danica/operator/addition.rb +2 -6
- data/lib/danica/operator/chained.rb +11 -11
- data/lib/danica/operator/multiplication.rb +2 -7
- data/lib/danica/variables_holder.rb +1 -7
- data/lib/danica/version.rb +1 -1
- data/lib/danica/wrapper/constant.rb +1 -0
- data/lib/danica/wrapper/group.rb +1 -1
- data/lib/danica/wrapper/negative.rb +4 -7
- data/lib/danica/wrapper/number.rb +5 -3
- data/lib/danica/wrapper/plus_minus.rb +2 -1
- data/spec/integration/addition_spec.rb +4 -3
- data/spec/lib/danica/common_spec.rb +88 -0
- data/spec/lib/danica/dsl_spec.rb +1 -0
- data/spec/lib/danica/function_spec.rb +62 -2
- data/spec/lib/danica/operator/addition_spec.rb +2 -2
- data/spec/lib/danica/operator/multiplication_spec.rb +2 -2
- data/spec/lib/danica/variables_holder_spec.rb +1 -1
- data/spec/lib/danica/wrapper/constant_spec.rb +30 -0
- data/spec/lib/danica/wrapper/number_spec.rb +10 -0
- data/spec/support/shared_examples/operator/chained.rb +10 -10
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88c93cc9b46fa1f9ced587a49535bc0eeec427cc
|
4
|
+
data.tar.gz: af6ae43ee59d5b15f204203f2a56c6978fec5125
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a547b35c6f1d7c14534ab87ee7d1c6a08222cdcbbb166f435276355a99decfe0bcc458e4aef8e4a011ec79203363fc3fc4f8aa22d80cea260c45c45aedd9ce8f
|
7
|
+
data.tar.gz: 7c168e661e244debbd6e7c68ca0b3acadebb59cc9f9920ce76f6b632ba7c16e6eb102a70259970887477469bbda3cb23a02ef71a3a605e02ef2c902f0880394e
|
data/lib/danica/common.rb
CHANGED
@@ -6,21 +6,43 @@ module Danica
|
|
6
6
|
|
7
7
|
class << self
|
8
8
|
def default_value(name, value)
|
9
|
-
define_method(name) { value }
|
9
|
+
define_method(name) { |*_| value }
|
10
10
|
end
|
11
11
|
end
|
12
|
+
|
13
|
+
default_value :constant?, false
|
14
|
+
default_value :signaled?, false
|
12
15
|
end
|
13
16
|
|
14
17
|
def to_f
|
15
|
-
raise
|
18
|
+
raise Exception::NotImplemented
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_tex
|
22
|
+
to(:tex)
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_gnu
|
26
|
+
to(:gnu)
|
16
27
|
end
|
17
|
-
|
28
|
+
|
29
|
+
def to(format)
|
30
|
+
case format.to_sym
|
31
|
+
when :tex
|
32
|
+
to_tex
|
33
|
+
when :gnu
|
34
|
+
to_gnu
|
35
|
+
else
|
36
|
+
raise Exception::FormatNotFound.new
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
18
40
|
def valued?
|
19
41
|
to_f.present?
|
20
42
|
rescue Exception::NotDefined
|
21
43
|
false
|
22
44
|
end
|
23
|
-
|
45
|
+
|
24
46
|
private
|
25
47
|
|
26
48
|
def wrap_as_group(value)
|
data/lib/danica/dsl.rb
CHANGED
data/lib/danica/exception.rb
CHANGED
data/lib/danica/function.rb
CHANGED
@@ -3,12 +3,12 @@ module Danica
|
|
3
3
|
include Common
|
4
4
|
include VariablesHolder
|
5
5
|
include DSL
|
6
|
-
|
6
|
+
|
7
7
|
attr_accessor :name
|
8
8
|
|
9
9
|
default_value :priority, 3
|
10
10
|
default_value :is_grouped?, false
|
11
|
-
delegate :to_f, :
|
11
|
+
delegate :to_f, :to, to: :function_block
|
12
12
|
|
13
13
|
def self.build(*vars, &block)
|
14
14
|
Class.new(self) do
|
@@ -48,14 +48,28 @@ module Danica
|
|
48
48
|
self.class.new(vars_map).to_f
|
49
49
|
end
|
50
50
|
|
51
|
+
def describe(format)
|
52
|
+
"#{name}(#{description_variables(format)}) = #{to(format)}"
|
53
|
+
end
|
54
|
+
|
51
55
|
def describe_tex
|
52
|
-
|
56
|
+
describe(:tex)
|
53
57
|
end
|
54
58
|
|
55
59
|
def describe_gnu
|
56
|
-
|
60
|
+
describe(:gnu)
|
57
61
|
end
|
58
62
|
|
59
63
|
autoload :Gauss, 'danica/function/gauss'
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def description_variables(format)
|
68
|
+
non_constant_variables.map { |v| v.to(format) }.join(', ')
|
69
|
+
end
|
70
|
+
|
71
|
+
def non_constant_variables
|
72
|
+
variables.reject(&:constant?)
|
73
|
+
end
|
60
74
|
end
|
61
75
|
end
|
@@ -1,35 +1,21 @@
|
|
1
1
|
module Danica
|
2
|
-
class Function::Gauss < Function.build(:x, average: { latex: '\mu', gnu: :u }, variance_root: { latex: '\sigma', gnu: :v }) {
|
2
|
+
class Function::Gauss < Function.build(:x, average: { latex: '\mu', gnu: :u }, variance_root: { latex: '\sigma', gnu: :v }) { num(1) / denominator * exponential(exp) }
|
3
3
|
|
4
4
|
private
|
5
5
|
|
6
|
-
def elements
|
7
|
-
[
|
8
|
-
division(1, denominator),
|
9
|
-
exponential(exp)
|
10
|
-
]
|
11
|
-
end
|
12
|
-
|
13
6
|
def denominator
|
14
|
-
variance_root *
|
15
|
-
squared_root(
|
16
|
-
multiplication(2, PI),
|
17
|
-
)
|
7
|
+
variance_root * sqrt(num(2) * PI)
|
18
8
|
end
|
19
9
|
|
20
10
|
def exp
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
addition(x, negative(average))
|
25
|
-
), 2),
|
26
|
-
multiplication(2, variance)
|
27
|
-
)
|
11
|
+
- (
|
12
|
+
((x - average) ** 2) /
|
13
|
+
(num(2) * variance)
|
28
14
|
)
|
29
15
|
end
|
30
16
|
|
31
17
|
def variance
|
32
|
-
@variance ||=
|
18
|
+
@variance ||= variance_root ** 2
|
33
19
|
end
|
34
20
|
end
|
35
21
|
end
|
data/lib/danica/operator.rb
CHANGED
@@ -8,19 +8,15 @@ module Danica
|
|
8
8
|
|
9
9
|
private
|
10
10
|
|
11
|
-
|
12
|
-
'+'
|
13
|
-
end
|
11
|
+
default_value :symbol, :+
|
14
12
|
|
15
13
|
def chain_operation(a, b)
|
16
14
|
a + b
|
17
15
|
end
|
18
16
|
|
19
|
-
alias_method :gnu_symbol, :tex_symbol
|
20
|
-
|
21
17
|
def join_proc(symbol)
|
22
18
|
proc do |_, value|
|
23
|
-
value.
|
19
|
+
value.signaled? ? ' ' : " #{symbol} "
|
24
20
|
end
|
25
21
|
end
|
26
22
|
end
|
@@ -16,20 +16,20 @@ module Danica
|
|
16
16
|
variables.include?(value)
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
def to_gnu
|
24
|
-
to_string(:gnu)
|
19
|
+
def to(format)
|
20
|
+
extractor = string_extractor(format)
|
21
|
+
variables.procedural_join(extractor, &join_proc(symbol(format)))
|
25
22
|
end
|
26
23
|
|
27
24
|
private
|
28
25
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
def symbol(format)
|
27
|
+
case format.to_sym
|
28
|
+
when :tex
|
29
|
+
tex_symbol
|
30
|
+
when :gnu
|
31
|
+
gnu_symbol
|
32
|
+
end
|
33
33
|
end
|
34
34
|
|
35
35
|
def join_proc(symbol)
|
@@ -39,7 +39,7 @@ module Danica
|
|
39
39
|
def string_extractor(method)
|
40
40
|
proc do |parcel|
|
41
41
|
parcel = wrap_as_group(parcel)
|
42
|
-
parcel.
|
42
|
+
parcel.to(method)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -27,7 +27,7 @@ module Danica
|
|
27
27
|
def variables
|
28
28
|
variables_hash.values
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def variables_hash
|
32
32
|
@variables_hash ||= {}.merge(self.class.variables_hash)
|
33
33
|
end
|
@@ -37,11 +37,5 @@ module Danica
|
|
37
37
|
var.try(:value)
|
38
38
|
end.as_hash(self.class.variables_names)
|
39
39
|
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def non_valued_variables
|
44
|
-
variables.reject(&:valued?)
|
45
|
-
end
|
46
40
|
end
|
47
41
|
end
|
data/lib/danica/version.rb
CHANGED
data/lib/danica/wrapper/group.rb
CHANGED
@@ -8,7 +8,8 @@ module Danica
|
|
8
8
|
|
9
9
|
default_value :priority, 2
|
10
10
|
default_value :is_grouped?, false
|
11
|
-
|
11
|
+
default_value :signaled?, true
|
12
|
+
|
12
13
|
delegate :valued?, to: :value
|
13
14
|
|
14
15
|
def initialize(value)
|
@@ -19,12 +20,8 @@ module Danica
|
|
19
20
|
-value.to_f
|
20
21
|
end
|
21
22
|
|
22
|
-
def
|
23
|
-
"-#{wrap_as_group(value).
|
24
|
-
end
|
25
|
-
|
26
|
-
def to_gnu
|
27
|
-
"-#{wrap_as_group(value).to_gnu}"
|
23
|
+
def to(format)
|
24
|
+
"-#{wrap_as_group(value).to(format)}"
|
28
25
|
end
|
29
26
|
|
30
27
|
def ==(other)
|
@@ -13,7 +13,7 @@ module Danica
|
|
13
13
|
@value = value
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def to(_)
|
17
17
|
return value.to_i.to_s if value.to_i == value
|
18
18
|
value.to_s
|
19
19
|
end
|
@@ -22,12 +22,14 @@ module Danica
|
|
22
22
|
value.present?
|
23
23
|
end
|
24
24
|
|
25
|
+
def signaled?
|
26
|
+
value < 0
|
27
|
+
end
|
28
|
+
|
25
29
|
def ==(other)
|
26
30
|
return false unless other.class == self.class
|
27
31
|
value == other.value
|
28
32
|
end
|
29
|
-
|
30
|
-
alias_method :to_gnu, :to_tex
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
@@ -8,19 +8,20 @@ describe 'integration of addition' do
|
|
8
8
|
2,
|
9
9
|
-3,
|
10
10
|
4,
|
11
|
-
Danica::Wrapper::PlusMinus.new(5)
|
11
|
+
Danica::Wrapper::PlusMinus.new(5),
|
12
|
+
Danica::Wrapper::Number.new(-6)
|
12
13
|
)
|
13
14
|
end
|
14
15
|
|
15
16
|
describe '#to_gnu' do
|
16
17
|
it 'returns the correct string' do
|
17
|
-
expect(subject.to_gnu).to eq('-1 + 2 -3 + 4 + 5')
|
18
|
+
expect(subject.to_gnu).to eq('-1 + 2 -3 + 4 + 5 -6')
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
22
|
describe '#to_tex' do
|
22
23
|
it 'returns the correct string' do
|
23
|
-
expect(subject.to_tex).to eq('-1 + 2 -3 + 4 \pm 5')
|
24
|
+
expect(subject.to_tex).to eq('-1 + 2 -3 + 4 \pm 5 -6')
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Danica
|
4
|
+
module Common
|
5
|
+
class Dummy
|
6
|
+
include Common
|
7
|
+
|
8
|
+
def to_tex
|
9
|
+
'tex'
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_gnu
|
13
|
+
'gnu'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Dummy2
|
18
|
+
include Common
|
19
|
+
|
20
|
+
def to(format)
|
21
|
+
"formatted: #{format}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe Danica::Common do
|
28
|
+
let(:clazz) { described_class::Dummy }
|
29
|
+
subject { clazz.new }
|
30
|
+
|
31
|
+
describe '#to_f' do
|
32
|
+
it do
|
33
|
+
expect do
|
34
|
+
subject.to_f
|
35
|
+
end.to raise_error(Danica::Exception::NotImplemented)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#to' do
|
40
|
+
context 'when defining to_tex and to_gnu' do
|
41
|
+
context 'when requesting :tex' do
|
42
|
+
it 'has a string for latex' do
|
43
|
+
expect(subject.to(:tex)).to eq('tex')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
context "when requesting 'tex'" do
|
47
|
+
it 'has a string for latex' do
|
48
|
+
expect(subject.to('tex')).to eq('tex')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
context 'when requesting :gnu' do
|
52
|
+
it 'has a string for gnu' do
|
53
|
+
expect(subject.to(:gnu)).to eq('gnu')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
context "when requesting 'gnu'" do
|
57
|
+
it 'has a string for gnu' do
|
58
|
+
expect(subject.to('gnu')).to eq('gnu')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
context "when requesting wrong format" do
|
62
|
+
it do
|
63
|
+
expect do
|
64
|
+
subject.to('format')
|
65
|
+
end.to raise_error(Danica::Exception::FormatNotFound)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '#to_tex' do
|
72
|
+
context 'when defined the #to method' do
|
73
|
+
let(:clazz) { described_class::Dummy2 }
|
74
|
+
it 'returns the call of #to(:tex)' do
|
75
|
+
expect(subject.to_tex).to eq('formatted: tex')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#to_gnu' do
|
81
|
+
context 'when defined the #to method' do
|
82
|
+
let(:clazz) { described_class::Dummy2 }
|
83
|
+
it 'returns the call of #to(:gnu)' do
|
84
|
+
expect(subject.to_gnu).to eq('formatted: gnu')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/spec/lib/danica/dsl_spec.rb
CHANGED
@@ -126,9 +126,39 @@ describe Danica::Function do
|
|
126
126
|
function_class.new(name: :f, x: Danica::PI)
|
127
127
|
end
|
128
128
|
|
129
|
-
it do
|
129
|
+
it 'ignores the constant in the definition' do
|
130
130
|
expect(function.describe_tex).to eq('f(y) = \pi^{y}')
|
131
131
|
end
|
132
|
+
|
133
|
+
context 'from a hash' do
|
134
|
+
let(:function) do
|
135
|
+
function_class.new(name: :f, x: { latex: '\pi', gnu: 'pi', value: 3.14 })
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'ignores the constant in the definition' do
|
139
|
+
expect(function.describe_tex).to eq('f(y) = \pi^{y}')
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'when a variable is a number' do
|
145
|
+
let(:function) do
|
146
|
+
function_class.new(name: :f, x: 2)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'sohws the variable as number' do
|
150
|
+
expect(function.describe_tex).to eq('f(2, y) = 2^{y}')
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'when a variable has value' do
|
155
|
+
let(:function) do
|
156
|
+
function_class.new(name: :f, x: 2)
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'sohws the variable as number' do
|
160
|
+
expect(function.describe_tex).to eq('f(2, y) = 2^{y}')
|
161
|
+
end
|
132
162
|
end
|
133
163
|
end
|
134
164
|
|
@@ -148,9 +178,39 @@ describe Danica::Function do
|
|
148
178
|
function_class.new(name: :f, x: Danica::PI)
|
149
179
|
end
|
150
180
|
|
151
|
-
it do
|
181
|
+
it 'ignores the constant in the definition' do
|
152
182
|
expect(function.describe_gnu).to eq('f(y) = pi**(y)')
|
153
183
|
end
|
184
|
+
|
185
|
+
context 'from a hash' do
|
186
|
+
let(:function) do
|
187
|
+
function_class.new(name: :f, x: { latex: '\pi', gnu: 'pi', value: 3.14 })
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'ignores the constant in the definition' do
|
191
|
+
expect(function.describe_gnu).to eq('f(y) = pi**(y)')
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
context 'when a variable has value' do
|
197
|
+
let(:function) do
|
198
|
+
function_class.new(name: :f, x: { name: :x, value: 2 })
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'sohws the variable as number' do
|
202
|
+
expect(function.describe_gnu).to eq('f(2, y) = 2**(y)')
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context 'when a variable is a number' do
|
207
|
+
let(:function) do
|
208
|
+
function_class.new(name: :f, x: 2)
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'sohws the variable as number' do
|
212
|
+
expect(function.describe_gnu).to eq('f(2, y) = 2**(y)')
|
213
|
+
end
|
154
214
|
end
|
155
215
|
end
|
156
216
|
|
@@ -30,12 +30,12 @@ describe Danica::Operator::Addition do
|
|
30
30
|
it_behaves_like 'a operator that joins many variables with same operation', {
|
31
31
|
calculated: 10,
|
32
32
|
numeric_variables: [ 1.5, 3.0, 3.5 ],
|
33
|
-
|
33
|
+
tex: {
|
34
34
|
string_expected: 'X1 + X2 + X3 + X4',
|
35
35
|
integer_expected: '1.5 + 3 + X3 + X4',
|
36
36
|
float_expected: '1.5 + 3 + 3.5 + X4'
|
37
37
|
},
|
38
|
-
|
38
|
+
gnu: {
|
39
39
|
string_expected: 'X1 + X2 + X3 + X4',
|
40
40
|
integer_expected: '1.5 + 3 + X3 + X4',
|
41
41
|
float_expected: '1.5 + 3 + 3.5 + X4'
|
@@ -27,12 +27,12 @@ describe Danica::Operator::Multiplication do
|
|
27
27
|
it_behaves_like 'a operator that joins many variables with same operation', {
|
28
28
|
calculated: 24,
|
29
29
|
numeric_variables: [ 1.5, 2, 3.5 ],
|
30
|
-
|
30
|
+
tex: {
|
31
31
|
string_expected: %w(X1 X2 X3 X4).join(' \cdot '),
|
32
32
|
integer_expected: %w(1.5 2 X3 X4).join(' \cdot '),
|
33
33
|
float_expected: %w(1.5 2 3.5 X4).join(' \cdot ')
|
34
34
|
},
|
35
|
-
|
35
|
+
gnu: {
|
36
36
|
string_expected: %w(X1 X2 X3 X4).join(' * '),
|
37
37
|
integer_expected: %w(1.5 2 X3 X4).join(' * '),
|
38
38
|
float_expected: %w(1.5 2 3.5 X4).join(' * '),
|
@@ -19,6 +19,36 @@ describe Danica::Wrapper::Constant do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
describe '#to' do
|
23
|
+
context 'when requesting :tex' do
|
24
|
+
it 'has a string for latex' do
|
25
|
+
expect(subject.to(:tex)).to eq('M')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
context "when requesting 'tex'" do
|
29
|
+
it 'has a string for latex' do
|
30
|
+
expect(subject.to('tex')).to eq('M')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
context 'when requesting :gnu' do
|
34
|
+
it 'has a string for gnu' do
|
35
|
+
expect(subject.to(:gnu)).to eq('m')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
context "when requesting 'gnu'" do
|
39
|
+
it 'has a string for gnu' do
|
40
|
+
expect(subject.to('gnu')).to eq('m')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
context "when requesting wrong format" do
|
44
|
+
it do
|
45
|
+
expect do
|
46
|
+
subject.to('format')
|
47
|
+
end.to raise_error(Danica::Exception::FormatNotFound)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
22
52
|
describe '#to_gnu' do
|
23
53
|
it 'has a string for gnu' do
|
24
54
|
expect(subject.to_gnu).to eq('m')
|
@@ -8,6 +8,16 @@ describe Danica::Wrapper::Number do
|
|
8
8
|
|
9
9
|
it_behaves_like 'an object with basic operation'
|
10
10
|
|
11
|
+
describe '#valued?' do
|
12
|
+
context 'when value is present' do
|
13
|
+
it { expect(subject.valued?).to be_truthy }
|
14
|
+
end
|
15
|
+
context 'when value is not present' do
|
16
|
+
let(:value) { false }
|
17
|
+
it { expect(subject.valued?).to be_falsey }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
11
21
|
describe '#to_f' do
|
12
22
|
it 'returns the float of value' do
|
13
23
|
expect(subject.to_f).to eq(10)
|
@@ -38,26 +38,26 @@ shared_examples 'a operator that knows how to calculate' do |arguments|
|
|
38
38
|
end
|
39
39
|
|
40
40
|
shared_examples 'a operator that knows how to write to tex' do |arguments|
|
41
|
-
it_behaves_like 'a operator that knows how to write to a string', :
|
41
|
+
it_behaves_like 'a operator that knows how to write to a string', :tex, arguments
|
42
42
|
end
|
43
43
|
|
44
44
|
shared_examples 'a operator that knows how to write to gnu' do |arguments|
|
45
|
-
it_behaves_like 'a operator that knows how to write to a string', :
|
45
|
+
it_behaves_like 'a operator that knows how to write to a string', :gnu, arguments
|
46
46
|
end
|
47
47
|
|
48
|
-
shared_examples 'a operator that knows how to write to a string' do |
|
48
|
+
shared_examples 'a operator that knows how to write to a string' do |format, arguments|
|
49
49
|
let(:numeric_variables) { arguments[:numeric_variables] }
|
50
|
-
include_context 'variables are initialized', arguments[
|
50
|
+
include_context 'variables are initialized', arguments[format], *%w(integer_expected string_expected float_expected)
|
51
51
|
subject { described_class.new(*variables) }
|
52
52
|
|
53
|
-
describe "#{
|
53
|
+
describe "#to(#{format})" do
|
54
54
|
let(:variables) do
|
55
55
|
(1..4).map { |i| "X#{i}" }
|
56
56
|
end
|
57
57
|
|
58
58
|
context 'when variables have no value' do
|
59
59
|
it 'outputs a text format' do
|
60
|
-
expect(subject.
|
60
|
+
expect(subject.to(format)).to eq(string_expected)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -70,14 +70,14 @@ shared_examples 'a operator that knows how to write to a string' do |command, ar
|
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'outputs a latex format with colapsed numbers' do
|
73
|
-
expect(subject.
|
73
|
+
expect(subject.to(format)).to eq(integer_expected)
|
74
74
|
end
|
75
75
|
|
76
76
|
context 'when numeric variables calculated is a float value' do
|
77
77
|
let(:numeric_variables_index) { 2 }
|
78
78
|
|
79
79
|
it 'outputs a text format with colapsed numbers' do
|
80
|
-
expect(subject.
|
80
|
+
expect(subject.to(format)).to eq(float_expected)
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
@@ -91,14 +91,14 @@ shared_examples 'a operator that knows how to write to a string' do |command, ar
|
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'outputs a text format of numbers' do
|
94
|
-
expect(subject.
|
94
|
+
expect(subject.to(format)).to eq(integer_expected)
|
95
95
|
end
|
96
96
|
|
97
97
|
context 'when numeric variables are a float value' do
|
98
98
|
let(:numeric_variables_index) { 2 }
|
99
99
|
|
100
100
|
it 'outputs a text format of numbers' do
|
101
|
-
expect(subject.
|
101
|
+
expect(subject.to(format)).to eq(float_expected)
|
102
102
|
end
|
103
103
|
end
|
104
104
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danica
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darthjee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -172,6 +172,7 @@ files:
|
|
172
172
|
- spec/integration/negative_spec.rb
|
173
173
|
- spec/integration/plus_minus_spec.rb
|
174
174
|
- spec/integration/power_spec.rb
|
175
|
+
- spec/lib/danica/common_spec.rb
|
175
176
|
- spec/lib/danica/dsl_spec.rb
|
176
177
|
- spec/lib/danica/function/gauss_spec.rb
|
177
178
|
- spec/lib/danica/function_spec.rb
|
@@ -233,6 +234,7 @@ test_files:
|
|
233
234
|
- spec/integration/negative_spec.rb
|
234
235
|
- spec/integration/plus_minus_spec.rb
|
235
236
|
- spec/integration/power_spec.rb
|
237
|
+
- spec/lib/danica/common_spec.rb
|
236
238
|
- spec/lib/danica/dsl_spec.rb
|
237
239
|
- spec/lib/danica/function/gauss_spec.rb
|
238
240
|
- spec/lib/danica/function_spec.rb
|