danica 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/danica/function.rb +13 -0
- data/lib/danica/version.rb +1 -1
- data/spec/lib/danica/function_spec.rb +34 -0
- data/spec/support/models/functions/baskara.rb +2 -3
- data/spec/support/models/functions/gauss.rb +2 -3
- data/spec/support/models/functions/spatial.rb +2 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c83cfc75834923aafa5160c20aaa1f45b125274d
|
4
|
+
data.tar.gz: 9a7933dd0986b110dee4ee7156452a3ba4027f21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48ccbce0f6aa35e90078d8a9006f8f9e2e33119e26abd91cacfdd2496f068f4e4c09bf34a7c89aa109d13807812a2157fd3f4a48bbc2681898445e559d02a37e
|
7
|
+
data.tar.gz: c505f5b99d34053f28b1c5e5c2d1406814acf2f6935d2eb3e9b6f7fd9d7168a9010282fadf0c514f086463206d3bd262298c4551a6c935ebdcad1f7167f15f30
|
data/lib/danica/function.rb
CHANGED
@@ -8,6 +8,19 @@ module Danica
|
|
8
8
|
|
9
9
|
default_value :priority, 3
|
10
10
|
default_value :is_grouped?, false
|
11
|
+
delegate :to_f, :to_tex, :to_gnu, to: :function
|
12
|
+
|
13
|
+
def self.build(*vars, &block)
|
14
|
+
Class.new(self) do
|
15
|
+
variables(*vars)
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
define_method :function do
|
20
|
+
@function ||= instance_eval(&block)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
11
24
|
|
12
25
|
def initialize(*args)
|
13
26
|
options = args.extract_options!
|
data/lib/danica/version.rb
CHANGED
@@ -1,6 +1,40 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Danica::Function do
|
4
|
+
describe '.build' do
|
5
|
+
let(:variables) { %i(x y) }
|
6
|
+
let(:function_class) do
|
7
|
+
described_class.build(*variables) do
|
8
|
+
Danica::Power.new(x, y)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
let(:function) do
|
12
|
+
function_class.new
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'returns a function class' do
|
16
|
+
expect(function_class.superclass).to eq(described_class)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'returns a class whose instance responds to the variables' do
|
20
|
+
variables.each do |variable|
|
21
|
+
expect(function).to respond_to(variable)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'returns a function that uses the block to process to_tex' do
|
26
|
+
expect(function.to_tex).to eq('x^{y}')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns a function that uses the block to process to_gnu' do
|
30
|
+
expect(function.to_gnu).to eq('x**(y)')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns a function thtat knows how to calculate' do
|
34
|
+
expect(function.calculate(x: 2, y: 3)).to eq(8)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
4
38
|
describe 'spatial' do
|
5
39
|
let(:variables) do
|
6
40
|
{
|
@@ -1,12 +1,11 @@
|
|
1
1
|
module Danica
|
2
2
|
class Function::Baskara < Function
|
3
3
|
variables :a, :b, :c
|
4
|
-
delegate :to_f, :to_tex, :to_gnu, to: :division
|
5
4
|
|
6
5
|
private
|
7
6
|
|
8
|
-
def
|
9
|
-
numerator / denominator
|
7
|
+
def function
|
8
|
+
@function ||= numerator / denominator
|
10
9
|
end
|
11
10
|
|
12
11
|
def numerator
|
@@ -1,12 +1,11 @@
|
|
1
1
|
module Danica
|
2
2
|
class Function::Gauss < Function
|
3
3
|
variables :x, median: :u, variance_root: { latex: '\theta', gnu: :v }
|
4
|
-
delegate :to_f, :to_tex, :to_gnu, to: :product
|
5
4
|
|
6
5
|
private
|
7
6
|
|
8
|
-
def
|
9
|
-
@
|
7
|
+
def function
|
8
|
+
@function ||= Product.new(parcels)
|
10
9
|
end
|
11
10
|
|
12
11
|
def parcels
|
@@ -1,12 +1,11 @@
|
|
1
1
|
module Danica
|
2
2
|
class Function::Spatial < Function
|
3
3
|
variables :time, :acceleration, :initial_space, :initial_velocity
|
4
|
-
delegate :to_f, :to_tex, :to_gnu, to: :sum
|
5
4
|
|
6
5
|
private
|
7
6
|
|
8
|
-
def
|
9
|
-
@
|
7
|
+
def function
|
8
|
+
@function ||= Sum.new(parcels)
|
10
9
|
end
|
11
10
|
|
12
11
|
def parcels
|