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,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe
|
5
|
+
describe Danica::Wrapper::PlusMinus do
|
4
6
|
describe 'with a addition' do
|
5
7
|
subject do
|
6
|
-
|
7
|
-
Danica::Operator::Addition.new(1,2,3)
|
8
|
+
described_class.new(
|
9
|
+
Danica::Operator::Addition.new(1, 2, 3)
|
8
10
|
)
|
9
11
|
end
|
10
12
|
|
@@ -21,4 +23,3 @@ describe 'integration of positive negative' do
|
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
24
|
-
|
@@ -1,9 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Danica::Wrapper::Constant do
|
4
6
|
subject do
|
5
|
-
|
7
|
+
described_class.new(gnuplot: 'pi', latex: '\pi', value: 3.141592)
|
6
8
|
end
|
9
|
+
|
7
10
|
let(:output) do
|
8
11
|
{
|
9
12
|
tex: '\pi',
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Danica::Formatted do
|
6
|
+
describe 'formatting' do
|
7
|
+
subject do
|
8
|
+
expression.tex(decimals: 3)
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:expression) do
|
12
|
+
value = 1 / 3.0
|
13
|
+
Danica.build(:x) do
|
14
|
+
x + value
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#to_tex' do
|
19
|
+
it 'formats the output' do
|
20
|
+
expect(subject.to_s).to eq('x + 0.333')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,11 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Danica do
|
6
|
+
describe 'formatting' do
|
7
|
+
subject do
|
8
|
+
value = 1 / 3.0
|
9
|
+
described_class.build(:x) do
|
10
|
+
x + value
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#to_tex' do
|
15
|
+
it 'formats the output' do
|
16
|
+
expect(subject.to_tex(decimals: 3)).to eq('x + 0.333')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
4
21
|
describe '.build' do
|
5
22
|
context 'when building an expression' do
|
6
23
|
let(:expression) do
|
7
|
-
|
8
|
-
(number(1) + 2) * power(3,4)
|
24
|
+
described_class.build do
|
25
|
+
(number(1) + 2) * power(3, 4)
|
9
26
|
end
|
10
27
|
end
|
11
28
|
|
@@ -16,7 +33,7 @@ describe Danica do
|
|
16
33
|
|
17
34
|
context 'when building a function' do
|
18
35
|
let(:function) do
|
19
|
-
|
36
|
+
described_class.build do
|
20
37
|
Danica::Function.create(:x, :y) do
|
21
38
|
(number(1) + x) * power(3, y)
|
22
39
|
end
|
@@ -29,4 +46,3 @@ describe Danica do
|
|
29
46
|
end
|
30
47
|
end
|
31
48
|
end
|
32
|
-
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Danica::Equation do
|
4
6
|
subject do
|
5
7
|
described_class.build(:x, :y, :z) do
|
6
|
-
left { x
|
7
|
-
right { number(1) - z
|
8
|
+
left { x**2 + y**2 }
|
9
|
+
right { number(1) - z**2 }
|
8
10
|
end.new
|
9
11
|
end
|
10
12
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Danica::Expression::Baskara do
|
@@ -9,18 +11,19 @@ describe Danica::Expression::Baskara do
|
|
9
11
|
end
|
10
12
|
|
11
13
|
describe Danica::Expression do
|
14
|
+
subject { clazz.new }
|
15
|
+
|
12
16
|
let(:clazz) do
|
13
17
|
described_class.build(:a, :b, :c) do
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
(
|
19
|
+
negative(b) + Danica::Wrapper::PlusMinus.new(
|
20
|
+
squared_root(
|
21
|
+
power(b, 2) - multiplication(4, a, c)
|
22
|
+
)
|
23
|
+
)
|
24
|
+
) / (number(2) * a)
|
21
25
|
end
|
22
26
|
end
|
23
|
-
subject { clazz.new }
|
24
27
|
|
25
28
|
describe 'to_tex' do
|
26
29
|
it 'returns bascara tex string' do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Danica::Function::Spatial do
|
@@ -13,19 +15,20 @@ describe Danica::Function::Spatial do
|
|
13
15
|
let(:name) { :f }
|
14
16
|
|
15
17
|
context 'when using it as default' do
|
18
|
+
subject { described_class.new }
|
19
|
+
|
16
20
|
let(:left) { "#{name}(time, acceleration, initial_space, initial_velocity)" }
|
17
21
|
let(:right) { 'initial_space + initial_velocity * time + (acceleration * time**(2))/(2)' }
|
18
22
|
|
19
|
-
subject { described_class.new }
|
20
|
-
|
21
23
|
it 'knows how to return to gnu format' do
|
22
24
|
expect(subject.to_gnu).to eq("#{left} = #{right}")
|
23
25
|
end
|
24
26
|
|
25
27
|
context 'when changing the name' do
|
26
|
-
let(:name) { :g }
|
27
28
|
subject { described_class.new(name: name) }
|
28
29
|
|
30
|
+
let(:name) { :g }
|
31
|
+
|
29
32
|
it 'knows how to return to gnu format' do
|
30
33
|
expect(subject.to_gnu).to eq("#{left} = #{right}")
|
31
34
|
end
|
@@ -33,14 +36,14 @@ describe Danica::Function::Spatial do
|
|
33
36
|
end
|
34
37
|
|
35
38
|
context 'when setting the variables' do
|
39
|
+
subject { described_class.new(variables) }
|
40
|
+
|
36
41
|
let(:variables) do
|
37
42
|
{ time: :t, acceleration: :a, initial_space: :s0, initial_velocity: :v0 }
|
38
43
|
end
|
39
44
|
let(:left) { "#{name}(t, a, s0, v0)" }
|
40
45
|
let(:right) { 's0 + v0 * t + (a * t**(2))/(2)' }
|
41
46
|
|
42
|
-
subject { described_class.new(variables) }
|
43
|
-
|
44
47
|
it 'knows how to return to gnu format' do
|
45
48
|
expect(subject.to_gnu).to eq("#{left} = #{right}")
|
46
49
|
end
|
@@ -76,13 +79,14 @@ end
|
|
76
79
|
describe Danica::Function::QuadraticSum do
|
77
80
|
describe '#to_tex' do
|
78
81
|
it 'creates a funcion out of an expression' do
|
79
|
-
expect(subject.to_tex).to eq(
|
82
|
+
expect(subject.to_tex).to eq('f(x, y) = \\left(x + y\\right)^{2}')
|
80
83
|
end
|
81
84
|
end
|
82
85
|
end
|
83
86
|
|
84
87
|
describe Danica::Function do
|
85
|
-
subject { described_class.build(:x, :y, :z) { z*(x
|
88
|
+
subject { described_class.build(:x, :y, :z) { z * (x**y) }.new(y: 3, z: Danica::PI) }
|
89
|
+
|
86
90
|
describe '#to_tex' do
|
87
91
|
it do
|
88
92
|
expect(subject.to_tex).to eq('f(x, 3) = \pi \cdot x^{3}')
|
@@ -1,16 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Danica::Wrapper::Number do
|
4
|
-
let(:number) do
|
5
|
-
Danica::Wrapper::Number.new(3)
|
6
|
-
end
|
7
|
-
|
8
6
|
subject do
|
9
7
|
Danica::DSL.build do
|
10
8
|
number(3)
|
11
9
|
end
|
12
10
|
end
|
13
11
|
|
12
|
+
let(:number) do
|
13
|
+
described_class.new(3)
|
14
|
+
end
|
15
|
+
|
14
16
|
it do
|
15
17
|
expect(subject).to eq(number)
|
16
18
|
end
|
@@ -25,10 +27,10 @@ describe Danica::Wrapper::Number do
|
|
25
27
|
let(:expected) do
|
26
28
|
Danica::Operator::Addition.new(
|
27
29
|
Danica::Operator::Power.new(
|
28
|
-
Danica::Wrapper::Variable.new(:x),
|
29
|
-
|
30
|
+
Danica::Wrapper::Variable.new(:x),
|
31
|
+
described_class.new(2)
|
30
32
|
),
|
31
|
-
|
33
|
+
described_class.new(3)
|
32
34
|
)
|
33
35
|
end
|
34
36
|
|
@@ -37,4 +39,3 @@ describe Danica::Wrapper::Number do
|
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
40
|
-
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe MyOperator do
|
@@ -17,7 +19,7 @@ describe MyOperator do
|
|
17
19
|
subject { described_class.new(x: 2) }
|
18
20
|
|
19
21
|
it 'returns the result of the operation' do
|
20
|
-
expect(subject.to_f).to eq(2
|
22
|
+
expect(subject.to_f).to eq(2**Math::PI)
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Danica::Wrapper::Variable do
|
4
6
|
describe '#to_tex' do
|
5
7
|
context 'when initializing with the name' do
|
6
8
|
subject do
|
7
|
-
|
9
|
+
described_class.new(:x)
|
8
10
|
end
|
9
11
|
|
10
12
|
it do
|
@@ -14,7 +16,7 @@ describe Danica::Wrapper::Variable do
|
|
14
16
|
|
15
17
|
context 'when initializing with a hash' do
|
16
18
|
subject do
|
17
|
-
|
19
|
+
described_class.new(name: :x)
|
18
20
|
end
|
19
21
|
|
20
22
|
it do
|
@@ -102,17 +104,17 @@ describe Danica::Wrapper::Variable do
|
|
102
104
|
describe 'automatic wrapp' do
|
103
105
|
let(:sum) do
|
104
106
|
Danica::DSL.build do
|
105
|
-
power(:x,
|
107
|
+
power(:x, name: :y) + :z
|
106
108
|
end
|
107
109
|
end
|
108
110
|
|
109
111
|
let(:expected) do
|
110
112
|
Danica::Operator::Addition.new(
|
111
113
|
Danica::Operator::Power.new(
|
112
|
-
|
113
|
-
|
114
|
+
described_class.new(:x),
|
115
|
+
described_class.new(:y)
|
114
116
|
),
|
115
|
-
|
117
|
+
described_class.new(:z)
|
116
118
|
)
|
117
119
|
end
|
118
120
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Danica
|
@@ -17,7 +19,7 @@ module Danica
|
|
17
19
|
class Dummy2
|
18
20
|
include Common
|
19
21
|
|
20
|
-
def to(format, **
|
22
|
+
def to(format, **_options)
|
21
23
|
"formatted: #{format}"
|
22
24
|
end
|
23
25
|
end
|
@@ -25,8 +27,10 @@ module Danica
|
|
25
27
|
end
|
26
28
|
|
27
29
|
describe Danica::Common do
|
28
|
-
let(:clazz) { described_class::Dummy }
|
29
30
|
subject { clazz.new }
|
31
|
+
|
32
|
+
let(:clazz) { described_class::Dummy }
|
33
|
+
|
30
34
|
it_behaves_like 'an object that respond to basic_methods'
|
31
35
|
|
32
36
|
describe '#to_f' do
|
@@ -44,31 +48,36 @@ describe Danica::Common do
|
|
44
48
|
expect(subject.to(:tex)).to eq('tex')
|
45
49
|
end
|
46
50
|
end
|
51
|
+
|
47
52
|
context "when requesting 'tex'" do
|
48
53
|
it 'has a string for latex' do
|
49
54
|
expect(subject.to('tex')).to eq('tex')
|
50
55
|
end
|
51
56
|
end
|
57
|
+
|
52
58
|
context 'when requesting :gnu' do
|
53
59
|
it 'has a string for gnu' do
|
54
60
|
expect(subject.to(:gnu)).to eq('gnu')
|
55
61
|
end
|
56
62
|
end
|
63
|
+
|
57
64
|
context "when requesting 'gnu'" do
|
58
65
|
it 'has a string for gnu' do
|
59
66
|
expect(subject.to('gnu')).to eq('gnu')
|
60
67
|
end
|
61
68
|
end
|
62
|
-
|
69
|
+
|
70
|
+
context 'when requesting wrong format' do
|
63
71
|
it do
|
64
72
|
expect do
|
65
73
|
subject.to('format')
|
66
74
|
end.to raise_error(Danica::Exception::FormattedNotFound)
|
67
75
|
end
|
68
76
|
end
|
77
|
+
|
69
78
|
context 'when passing options' do
|
70
79
|
it 'passes the options ahead' do
|
71
|
-
expect(subject.to(:gnu,
|
80
|
+
expect(subject.to(:gnu, opt: 1)).to eq('gnu {:opt=>1}')
|
72
81
|
end
|
73
82
|
end
|
74
83
|
end
|
@@ -77,19 +86,71 @@ describe Danica::Common do
|
|
77
86
|
describe '#to_tex' do
|
78
87
|
context 'when defined the #to method' do
|
79
88
|
let(:clazz) { described_class::Dummy2 }
|
89
|
+
|
80
90
|
it 'returns the call of #to(:tex)' do
|
81
91
|
expect(subject.to_tex).to eq('formatted: tex')
|
82
92
|
end
|
83
93
|
end
|
94
|
+
|
95
|
+
context 'when formatted was generated with gnu and with options' do
|
96
|
+
subject { number.gnu(decimals: 3) }
|
97
|
+
|
98
|
+
let(:number) { Danica::Wrapper::Number.new(1.0 / 3) }
|
99
|
+
|
100
|
+
it 'formats with the current options' do
|
101
|
+
expect(subject.to_tex).to eq('0.333')
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'when overwritting options' do
|
105
|
+
it 'formats with the current options' do
|
106
|
+
expect(subject.to_tex(decimals: 4)).to eq('0.3333')
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
84
110
|
end
|
85
111
|
|
86
112
|
describe '#to_gnu' do
|
87
113
|
context 'when defined the #to method' do
|
88
114
|
let(:clazz) { described_class::Dummy2 }
|
115
|
+
|
89
116
|
it 'returns the call of #to(:gnu)' do
|
90
117
|
expect(subject.to_gnu).to eq('formatted: gnu')
|
91
118
|
end
|
92
119
|
end
|
120
|
+
|
121
|
+
context 'when formatted was generated with tex and with options' do
|
122
|
+
subject { number.tex(decimals: 3) }
|
123
|
+
|
124
|
+
let(:number) { Danica::Wrapper::Number.new(1.0 / 3) }
|
125
|
+
|
126
|
+
it 'formats with the current options' do
|
127
|
+
expect(subject.to_gnu).to eq('0.333')
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'when overwritting options' do
|
131
|
+
it 'formats with the current options' do
|
132
|
+
expect(subject.to_gnu(decimals: 4)).to eq('0.3333')
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe 'to' do
|
139
|
+
context 'when already formatted with options' do
|
140
|
+
subject { number.tex(decimals: 3) }
|
141
|
+
|
142
|
+
let(:number) { Danica::Wrapper::Number.new(1.0 / 3) }
|
143
|
+
|
144
|
+
it 'uses to with options' do
|
145
|
+
expect(subject.to(:gnu)).to eq('0.333')
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'when calling with options' do
|
149
|
+
it 'uses options' do
|
150
|
+
expect(subject.to(:gnu, decimals: 4)).to eq('0.3333')
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
93
154
|
end
|
94
155
|
|
95
156
|
describe '#tex' do
|
@@ -98,12 +159,12 @@ describe Danica::Common do
|
|
98
159
|
end
|
99
160
|
|
100
161
|
it 'knows how to return a tex string' do
|
101
|
-
expect(subject.tex.to_s).to eq('tex {:
|
162
|
+
expect(subject.tex.to_s).to eq('tex {:format=>:tex}')
|
102
163
|
end
|
103
164
|
|
104
165
|
context 'when passing options' do
|
105
166
|
it 'uses the arguments' do
|
106
|
-
expect(subject.tex(decimals: 3).to_s).to eq('tex {:decimals=>3}')
|
167
|
+
expect(subject.tex(decimals: 3).to_s).to eq('tex {:format=>:tex, :decimals=>3}')
|
107
168
|
end
|
108
169
|
end
|
109
170
|
end
|
@@ -114,13 +175,23 @@ describe Danica::Common do
|
|
114
175
|
end
|
115
176
|
|
116
177
|
it 'knows how to return a gnu string' do
|
117
|
-
expect(subject.gnu.to_s).to eq('gnu {:
|
178
|
+
expect(subject.gnu.to_s).to eq('gnu {:format=>:gnu}')
|
118
179
|
end
|
119
180
|
|
120
181
|
context 'when passing options' do
|
121
182
|
it 'uses the arguments' do
|
122
|
-
expect(subject.gnu(decimals: 3).to_s).to eq('gnu {:decimals=>3}')
|
183
|
+
expect(subject.gnu(decimals: 3).to_s).to eq('gnu {:format=>:gnu, :decimals=>3}')
|
123
184
|
end
|
124
185
|
end
|
125
186
|
end
|
187
|
+
|
188
|
+
describe '#formatted' do
|
189
|
+
it do
|
190
|
+
expect(subject.formatted(format: :gnu)).to be_a(Danica::Formatted)
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'knows how to return to build the string string' do
|
194
|
+
expect(subject.formatted(format: :gnu, decimals: 3).to_s).to eq('gnu {:format=>:gnu, :decimals=>3}')
|
195
|
+
end
|
196
|
+
end
|
126
197
|
end
|