danica 2.4.1 → 2.4.2
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 +4 -4
- data/lib/danica/dsl.rb +1 -1
- data/lib/danica/function.rb +2 -2
- data/lib/danica/version.rb +1 -1
- data/lib/danica/wrapper.rb +14 -5
- data/lib/danica/wrapper/constant.rb +21 -4
- data/spec/integration/addition_spec.rb +1 -1
- data/spec/lib/danica/dsl_spec.rb +2 -1
- data/spec/lib/danica/function_spec.rb +20 -0
- data/spec/lib/danica/wrapper/constant_spec.rb +23 -1
- data/spec/lib/danica/wrapper_spec.rb +49 -0
- 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: 42d3abe8f4cb30ba5f39df22450aa6b258897516
|
4
|
+
data.tar.gz: 556b8f2d44f534d97bbce6d4e0a9d8cfbe9b1af2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6357c1036ab3949b292e94c0835b99812d7eaaeb426372c75e41cf6145b274592c821935e86dffd957b13c193e9875b6caf0824e8de8db862455d09f6f14d443
|
7
|
+
data.tar.gz: df8178314d284efe3d623e40d3c974e5876dfcad6e0a703d5e57d925d2ce8f5ed01ed099618a46195cca08584a2acae35e3724221e79431f8a8d5eb373054b37
|
data/lib/danica/dsl.rb
CHANGED
data/lib/danica/function.rb
CHANGED
@@ -49,11 +49,11 @@ module Danica
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def describe_tex
|
52
|
-
"#{name}(#{variables.map(&:to_tex).join(', ')}) = #{to_tex}"
|
52
|
+
"#{name}(#{variables.reject(&:valued?).map(&:to_tex).join(', ')}) = #{to_tex}"
|
53
53
|
end
|
54
54
|
|
55
55
|
def describe_gnu
|
56
|
-
"#{name}(#{variables.map(&:to_gnu).join(', ')}) = #{to_gnu}"
|
56
|
+
"#{name}(#{variables.reject(&:valued?).map(&:to_gnu).join(', ')}) = #{to_gnu}"
|
57
57
|
end
|
58
58
|
|
59
59
|
autoload :Gauss, 'danica/function/gauss'
|
data/lib/danica/version.rb
CHANGED
data/lib/danica/wrapper.rb
CHANGED
@@ -1,11 +1,20 @@
|
|
1
1
|
module Danica
|
2
2
|
module Wrapper
|
3
3
|
def wrap_value(value)
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
case value
|
5
|
+
when Numeric
|
6
|
+
return negative(number(-value)) if value < 0
|
7
|
+
number(value)
|
8
|
+
when Hash
|
9
|
+
return constant(value) if value.keys.map(&:to_sym).sort == %i(gnu latex value)
|
10
|
+
variable(value)
|
11
|
+
when String, Symbol
|
12
|
+
variable(name: value)
|
13
|
+
when NilClass
|
14
|
+
variable
|
15
|
+
else
|
16
|
+
value
|
17
|
+
end
|
9
18
|
end
|
10
19
|
|
11
20
|
autoload :Number, 'danica/wrapper/number'
|
@@ -9,10 +9,13 @@ module Danica
|
|
9
9
|
default_value :valued?, true
|
10
10
|
default_value :is_grouped?, false
|
11
11
|
|
12
|
-
def initialize(
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def initialize(*args)
|
13
|
+
attrs = args.extract_options!
|
14
|
+
attrs = args.as_hash(%i(value latex gnu)).merge(attrs)
|
15
|
+
|
16
|
+
attrs.each do |key, value|
|
17
|
+
self.send("#{key}=", value)
|
18
|
+
end
|
16
19
|
end
|
17
20
|
|
18
21
|
def to_f
|
@@ -31,6 +34,20 @@ module Danica
|
|
31
34
|
def to_gnu
|
32
35
|
gnu.to_s
|
33
36
|
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def value=(value)
|
41
|
+
@value = value
|
42
|
+
end
|
43
|
+
|
44
|
+
def latex=(latex)
|
45
|
+
@latex = latex
|
46
|
+
end
|
47
|
+
|
48
|
+
def gnu=(gnu)
|
49
|
+
@gnu = gnu
|
50
|
+
end
|
34
51
|
end
|
35
52
|
|
36
53
|
E = Wrapper::Constant.new(Math::E, :e, 'exp(1)')
|
data/spec/lib/danica/dsl_spec.rb
CHANGED
@@ -30,7 +30,8 @@ shared_context 'a class with mapped dsl' do
|
|
30
30
|
negative: Danica::Wrapper::Negative,
|
31
31
|
number: Danica::Wrapper::Number,
|
32
32
|
num: Danica::Wrapper::Number,
|
33
|
-
plus_minus: Danica::Wrapper::PlusMinus
|
33
|
+
plus_minus: Danica::Wrapper::PlusMinus,
|
34
|
+
constant: Danica::Wrapper::Constant
|
34
35
|
}.each do |aliaz, clazz|
|
35
36
|
it_behaves_like 'a class with alias to a clazz', aliaz, clazz, 9
|
36
37
|
end
|
@@ -120,6 +120,16 @@ describe Danica::Function do
|
|
120
120
|
expect(function.describe_tex).to eq('f(x, y) = x^{y}')
|
121
121
|
end
|
122
122
|
end
|
123
|
+
|
124
|
+
context 'when a variable is set as a constant' do
|
125
|
+
let(:function) do
|
126
|
+
function_class.new(name: :f, x: Danica::PI)
|
127
|
+
end
|
128
|
+
|
129
|
+
it do
|
130
|
+
expect(function.describe_tex).to eq('f(y) = \pi^{y}')
|
131
|
+
end
|
132
|
+
end
|
123
133
|
end
|
124
134
|
|
125
135
|
describe '#describe_gnu' do
|
@@ -132,6 +142,16 @@ describe Danica::Function do
|
|
132
142
|
expect(function.describe_gnu).to eq('f(x, y) = x**(y)')
|
133
143
|
end
|
134
144
|
end
|
145
|
+
|
146
|
+
context 'when a variable is set as a constant' do
|
147
|
+
let(:function) do
|
148
|
+
function_class.new(name: :f, x: Danica::PI)
|
149
|
+
end
|
150
|
+
|
151
|
+
it do
|
152
|
+
expect(function.describe_gnu).to eq('f(y) = pi**(y)')
|
153
|
+
end
|
154
|
+
end
|
135
155
|
end
|
136
156
|
|
137
157
|
describe 'spatial' do
|
@@ -25,12 +25,34 @@ describe Danica::Wrapper::Constant do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
describe '
|
28
|
+
describe 'attr_setters' do
|
29
29
|
it { expect(subject).not_to respond_to(:value=) }
|
30
30
|
it { expect(subject).not_to respond_to(:latex=) }
|
31
31
|
it { expect(subject).not_to respond_to(:gnu=) }
|
32
32
|
end
|
33
33
|
|
34
|
+
context 'when initializing from hash' do
|
35
|
+
subject { described_class.new(value: 2.5, latex: :M, gnu: :m) }
|
36
|
+
|
37
|
+
it 'initialize normaly' do
|
38
|
+
expect do
|
39
|
+
described_class.new(value: 2.5, latex: :M, gnu: :m)
|
40
|
+
end.not_to raise_error
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'sets the value' do
|
44
|
+
expect(subject.value).to eq(2.5)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'sets the latex' do
|
48
|
+
expect(subject.to_tex).to eq('M')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'sets the gnu' do
|
52
|
+
expect(subject.to_gnu).to eq('m')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
34
56
|
describe '==' do
|
35
57
|
context 'when comparing with the same object' do
|
36
58
|
it { expect(subject).to eq(subject) }
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Danica::Wrapper::Dummy
|
4
|
+
include Danica::DSL
|
5
|
+
include Danica::Wrapper
|
6
|
+
|
7
|
+
attr_reader :wrapped_value
|
8
|
+
|
9
|
+
def initialize(value)
|
10
|
+
@wrapped_value = wrap_value(value)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
shared_examples 'a value wrapper' do |examples|
|
15
|
+
examples.each do |val, expected|
|
16
|
+
context "when value is a #{val.class}" do
|
17
|
+
let(:value) { val }
|
18
|
+
|
19
|
+
it do
|
20
|
+
expect(subject.wrapped_value).to be_a(expected)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe Danica::Wrapper do
|
27
|
+
let(:clazz) { described_class::Dummy }
|
28
|
+
subject { clazz.new(value) }
|
29
|
+
|
30
|
+
describe 'wrap_value' do
|
31
|
+
it_behaves_like 'a value wrapper', {
|
32
|
+
x: Danica::Wrapper::Variable,
|
33
|
+
'x' => Danica::Wrapper::Variable,
|
34
|
+
10 => Danica::Wrapper::Number,
|
35
|
+
-10 => Danica::Wrapper::Negative,
|
36
|
+
{ name: :x } => Danica::Wrapper::Variable
|
37
|
+
}
|
38
|
+
|
39
|
+
context 'when value is a Hash' do
|
40
|
+
context 'but it is a constant' do
|
41
|
+
let(:value) { { value: 10, latex: :x, gnu: :X } }
|
42
|
+
|
43
|
+
it do
|
44
|
+
expect(subject.wrapped_value).to be_a(Danica::Wrapper::Constant)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
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.2
|
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-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -191,6 +191,7 @@ files:
|
|
191
191
|
- spec/lib/danica/wrapper/number_spec.rb
|
192
192
|
- spec/lib/danica/wrapper/plus_minus_spec.rb
|
193
193
|
- spec/lib/danica/wrapper/variable_spec.rb
|
194
|
+
- spec/lib/danica/wrapper_spec.rb
|
194
195
|
- spec/lib/danica_spec.rb
|
195
196
|
- spec/spec_helper.rb
|
196
197
|
- spec/support/models/functions/baskara.rb
|
@@ -251,6 +252,7 @@ test_files:
|
|
251
252
|
- spec/lib/danica/wrapper/number_spec.rb
|
252
253
|
- spec/lib/danica/wrapper/plus_minus_spec.rb
|
253
254
|
- spec/lib/danica/wrapper/variable_spec.rb
|
255
|
+
- spec/lib/danica/wrapper_spec.rb
|
254
256
|
- spec/lib/danica_spec.rb
|
255
257
|
- spec/spec_helper.rb
|
256
258
|
- spec/support/models/functions/baskara.rb
|