danica 0.1.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 +7 -0
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +64 -0
- data/README.md +68 -0
- data/Rakefile +7 -0
- data/danica.gemspec +28 -0
- data/lib/danica.rb +9 -0
- data/lib/danica/function.rb +34 -0
- data/lib/danica/function/chained.rb +35 -0
- data/lib/danica/function/division.rb +24 -0
- data/lib/danica/function/product.rb +15 -0
- data/lib/danica/function/sum.rb +16 -0
- data/lib/danica/not_defined.rb +2 -0
- data/lib/danica/number.rb +24 -0
- data/lib/danica/variable.rb +19 -0
- data/lib/danica/version.rb +3 -0
- data/spec/lib/danica/function/division_spec.rb +94 -0
- data/spec/lib/danica/function/product_spec.rb +11 -0
- data/spec/lib/danica/function/sum_spec.rb +11 -0
- data/spec/lib/danica/function_spec.rb +52 -0
- data/spec/lib/danica/variable_spec.rb +36 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/support/shared_examples/function.rb +106 -0
- metadata +186 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 696be3ea582e6da09c966a3093aa11d62a26f0f5
|
4
|
+
data.tar.gz: 07b3928209584450ad5b502087bafa160c34ac33
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3ccbabcfd60cfc8f69ccf95ece082fdbfb998eb67b5f4d25ee466adbdd2a14b2f17c7c236a9aba891b59ada13729589ed9c605ff89426486e95ea34b90ecac8b
|
7
|
+
data.tar.gz: a5f0d985343c2c22344c0e7f9b624b0cb104819fa486900d595863cf7587a3914117ddb27ee62fb01c0af856d7e77dbc97ea125bfe542301334398de089669f9
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
coverage
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
danica (0.1.0)
|
5
|
+
activemodel
|
6
|
+
activesupport
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (5.0.0.1)
|
12
|
+
activesupport (= 5.0.0.1)
|
13
|
+
activesupport (5.0.0.1)
|
14
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
|
+
i18n (~> 0.7)
|
16
|
+
minitest (~> 5.1)
|
17
|
+
tzinfo (~> 1.1)
|
18
|
+
coderay (1.1.1)
|
19
|
+
concurrent-ruby (1.0.2)
|
20
|
+
diff-lcs (1.2.5)
|
21
|
+
docile (1.1.5)
|
22
|
+
i18n (0.7.0)
|
23
|
+
json (2.0.2)
|
24
|
+
method_source (0.8.2)
|
25
|
+
minitest (5.9.0)
|
26
|
+
pry (0.10.4)
|
27
|
+
coderay (~> 1.1.0)
|
28
|
+
method_source (~> 0.8.1)
|
29
|
+
slop (~> 3.4)
|
30
|
+
pry-nav (0.2.4)
|
31
|
+
pry (>= 0.9.10, < 0.11.0)
|
32
|
+
rake (11.2.2)
|
33
|
+
rspec (2.99.0)
|
34
|
+
rspec-core (~> 2.99.0)
|
35
|
+
rspec-expectations (~> 2.99.0)
|
36
|
+
rspec-mocks (~> 2.99.0)
|
37
|
+
rspec-core (2.99.2)
|
38
|
+
rspec-expectations (2.99.2)
|
39
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
40
|
+
rspec-mocks (2.99.4)
|
41
|
+
simplecov (0.12.0)
|
42
|
+
docile (~> 1.1.0)
|
43
|
+
json (>= 1.8, < 3)
|
44
|
+
simplecov-html (~> 0.10.0)
|
45
|
+
simplecov-html (0.10.0)
|
46
|
+
slop (3.6.0)
|
47
|
+
thread_safe (0.3.5)
|
48
|
+
tzinfo (1.2.2)
|
49
|
+
thread_safe (~> 0.1)
|
50
|
+
|
51
|
+
PLATFORMS
|
52
|
+
ruby
|
53
|
+
|
54
|
+
DEPENDENCIES
|
55
|
+
bundler (~> 1.6)
|
56
|
+
danica!
|
57
|
+
pry-nav
|
58
|
+
rake
|
59
|
+
rspec (~> 2.14)
|
60
|
+
rspec-mocks
|
61
|
+
simplecov
|
62
|
+
|
63
|
+
BUNDLED WITH
|
64
|
+
1.12.5
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# danica
|
2
|
+
A tool for math formulation on docs
|
3
|
+
|
4
|
+
## How to use
|
5
|
+
Add the gem to your project or just install the gem
|
6
|
+
|
7
|
+
```
|
8
|
+
gem 'danica'
|
9
|
+
```
|
10
|
+
|
11
|
+
```console
|
12
|
+
bundle install danica
|
13
|
+
```
|
14
|
+
|
15
|
+
Now you can use in your project
|
16
|
+
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
class MyFunction < Danica::Function
|
20
|
+
def to_f
|
21
|
+
#implement to float method
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_tex
|
25
|
+
#implement to tex method
|
26
|
+
end
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
|
31
|
+
### Sample
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
class Danica::Function
|
35
|
+
class Spatial < Danica::Function
|
36
|
+
attr_accessor :time, :acceleration, :initial_space, :initial_velocity
|
37
|
+
delegate :to_tex, to: :sum
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def sum
|
42
|
+
@sum ||= Sum.new(variables: parcels)
|
43
|
+
end
|
44
|
+
|
45
|
+
def parcels
|
46
|
+
[
|
47
|
+
initial_space,
|
48
|
+
spatial_velocity,
|
49
|
+
spatial_acceleration
|
50
|
+
]
|
51
|
+
end
|
52
|
+
|
53
|
+
def spatial_velocity
|
54
|
+
Product.new(variables: [ initial_velocity, time ])
|
55
|
+
end
|
56
|
+
|
57
|
+
def spatial_acceleration
|
58
|
+
Division.new(numerator: Product.new(variables: [ acceleration, time, time ]), denominator: 2)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
returns
|
65
|
+
```string
|
66
|
+
S_0 + V_0 \cdot t + \frac{a \cdot t \cdot t}{2}
|
67
|
+
```
|
68
|
+
|
data/Rakefile
ADDED
data/danica.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'danica/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'danica'
|
8
|
+
spec.version = Danica::VERSION
|
9
|
+
spec.authors = ['Darthjee']
|
10
|
+
spec.email = ['darthjee@gmail.com']
|
11
|
+
spec.summary = 'Danica'
|
12
|
+
|
13
|
+
spec.files = `git ls-files -z`.split("\x0")
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.require_paths = ['lib']
|
17
|
+
|
18
|
+
spec.add_runtime_dependency 'activesupport'
|
19
|
+
spec.add_runtime_dependency 'activemodel'
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 2.14'
|
24
|
+
spec.add_development_dependency 'rspec-mocks'
|
25
|
+
spec.add_development_dependency 'pry-nav'
|
26
|
+
spec.add_development_dependency 'simplecov'
|
27
|
+
|
28
|
+
end
|
data/lib/danica.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
class Danica::Function
|
2
|
+
include ActiveModel::Model
|
3
|
+
|
4
|
+
require 'danica/function/chained'
|
5
|
+
require 'danica/function/product'
|
6
|
+
require 'danica/function/sum'
|
7
|
+
require 'danica/function/division'
|
8
|
+
|
9
|
+
attr_accessor :name, :variables
|
10
|
+
|
11
|
+
def to_f
|
12
|
+
raise 'Not IMplemented yet'
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_tex
|
16
|
+
raise 'Not IMplemented yet'
|
17
|
+
end
|
18
|
+
|
19
|
+
def variables=(variables)
|
20
|
+
@variables = variables.map { |v| wrap_value(v) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def valued?
|
24
|
+
to_f.presend?
|
25
|
+
rescue Danica::NotDefined
|
26
|
+
false
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def wrap_value(value)
|
32
|
+
value.is_a?(Numeric) ? Danica::Number.new(value) : value
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Danica
|
2
|
+
class Function
|
3
|
+
class Chained < Function
|
4
|
+
def to_f
|
5
|
+
chain(variables.map(&:to_f))
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_tex
|
9
|
+
(numeric_to_tex + non_numeric_variables.map(&:to_tex)).join(" #{tex_symbol} ")
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def numeric_variables
|
15
|
+
variables.select { |v| v.valued? }
|
16
|
+
end
|
17
|
+
|
18
|
+
def non_numeric_variables
|
19
|
+
variables.reject { |v| v.valued? }
|
20
|
+
end
|
21
|
+
|
22
|
+
def chain(numbers)
|
23
|
+
numbers.inject do |a,b|
|
24
|
+
chain_operation(a,b)
|
25
|
+
end.to_f
|
26
|
+
end
|
27
|
+
|
28
|
+
def numeric_to_tex
|
29
|
+
return [] if numeric_variables.empty?
|
30
|
+
[ Number.new(chain(numeric_variables.map(&:to_f))).to_tex ]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Danica
|
2
|
+
class Function
|
3
|
+
class Division < Function
|
4
|
+
attr_accessor :numerator, :denominator
|
5
|
+
|
6
|
+
def to_f
|
7
|
+
numerator.to_f / denominator.to_f
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_tex
|
11
|
+
"\\frac{#{numerator.to_tex}}{#{denominator.to_tex}}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def numerator=(value)
|
15
|
+
@numerator ||= wrap_value(value)
|
16
|
+
end
|
17
|
+
|
18
|
+
def denominator=(value)
|
19
|
+
@denominator ||= wrap_value(value)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Danica
|
2
|
+
class Number
|
3
|
+
include ActiveModel::Model
|
4
|
+
|
5
|
+
attr_accessor :value
|
6
|
+
|
7
|
+
delegate :to_f, to: :value
|
8
|
+
|
9
|
+
def initialize(value)
|
10
|
+
@value = value
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_tex
|
14
|
+
return value.to_i if value.to_i == value
|
15
|
+
value
|
16
|
+
end
|
17
|
+
|
18
|
+
def valued?
|
19
|
+
value.present?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Danica
|
2
|
+
class Variable
|
3
|
+
include ActiveModel::Model
|
4
|
+
attr_accessor :value, :name, :latex
|
5
|
+
|
6
|
+
def to_f
|
7
|
+
value.nil? ? raise(NotDefined) : value.to_f
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_tex
|
11
|
+
(value || latex || name).to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
def valued?
|
15
|
+
value.present?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Danica::Function::Division do
|
4
|
+
let(:variables_number) { 4 }
|
5
|
+
let(:values) { [ 2, 4 ] }
|
6
|
+
let(:variables) do
|
7
|
+
[ 1, 2 ].map do |i|
|
8
|
+
Danica::Variable.new(name: "X#{i}", value: values[i-1])
|
9
|
+
end
|
10
|
+
end
|
11
|
+
let(:subject) do
|
12
|
+
described_class.new(numerator: variables[0], denominator: variables[1])
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'to_f' do
|
16
|
+
context 'when variables are not numbers but have value' do
|
17
|
+
it 'returns the division of the values' do
|
18
|
+
expect(subject.to_f).to eq(1.0 / 2.0)
|
19
|
+
end
|
20
|
+
|
21
|
+
it do
|
22
|
+
expect(subject.to_f).to be_a(Float)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when all the variables are numbers' do
|
27
|
+
let(:variables) { [ 2, 4 ] }
|
28
|
+
|
29
|
+
it 'returns the division of the values' do
|
30
|
+
expect(subject.to_f).to eq(1.0 / 2.0)
|
31
|
+
end
|
32
|
+
|
33
|
+
it do
|
34
|
+
expect(subject.to_f).to be_a(Float)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when one the variables are numbers' do
|
39
|
+
before do
|
40
|
+
variables[0] = 2
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'returns the division of the values' do
|
44
|
+
expect(subject.to_f).to eq(1.0 / 2.0)
|
45
|
+
end
|
46
|
+
|
47
|
+
it do
|
48
|
+
expect(subject.to_f).to be_a(Float)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'to_tex' do
|
54
|
+
context 'when variables have no value' do
|
55
|
+
let(:variables) do
|
56
|
+
[ 1,2 ].map do |i|
|
57
|
+
Danica::Variable.new(name: "X#{i}")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns a latex format fraction' do
|
62
|
+
expect(subject.to_tex).to eq('\frac{X1}{X2}')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when one of the variables has value' do
|
67
|
+
before do
|
68
|
+
variables[1].value = nil
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'returns the number instead of the value' do
|
72
|
+
expect(subject.to_tex).to eq('\frac{2}{X2}')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when both variables are numeric' do
|
77
|
+
it 'prints both numbers' do
|
78
|
+
expect(subject.to_tex).to eq('\frac{2}{4}')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when one of the variables is a number' do
|
83
|
+
before do
|
84
|
+
variables[1].value = nil
|
85
|
+
variables[0] = 1
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'prints both numbers' do
|
89
|
+
expect(subject.to_tex).to eq('\frac{1}{X2}')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Danica::Function::Product do
|
4
|
+
it_behaves_like 'a function that joins many variables with same operation', {
|
5
|
+
calculated: 24,
|
6
|
+
tex_expected: %w(X1 X2 X3 X4).join(' \cdot '),
|
7
|
+
tex_integer_expected: %w(3 X3 X4).join(' \cdot '),
|
8
|
+
tex_float_expected: '10.5 \cdot X4',
|
9
|
+
numeric_variables: [ 1.5, 2, 3.5 ]
|
10
|
+
}
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Danica::Function::Sum do
|
4
|
+
it_behaves_like 'a function that joins many variables with same operation', {
|
5
|
+
calculated: 10,
|
6
|
+
tex_expected: 'X1 + X2 + X3 + X4',
|
7
|
+
tex_integer_expected: '4 + X3 + X4',
|
8
|
+
tex_float_expected: '7.5 + X4',
|
9
|
+
numeric_variables: [ 1.5, 2.5, 3.5 ]
|
10
|
+
}
|
11
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Danica::Function do
|
4
|
+
class Danica::Function
|
5
|
+
class Spatial < Danica::Function
|
6
|
+
attr_accessor :time, :acceleration, :initial_space, :initial_velocity
|
7
|
+
delegate :to_tex, to: :sum
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def sum
|
12
|
+
@sum ||= Sum.new(variables: parcels)
|
13
|
+
end
|
14
|
+
|
15
|
+
def parcels
|
16
|
+
[
|
17
|
+
initial_space,
|
18
|
+
spatial_velocity,
|
19
|
+
spatial_acceleration
|
20
|
+
]
|
21
|
+
end
|
22
|
+
|
23
|
+
def spatial_velocity
|
24
|
+
Product.new(variables: [ initial_velocity, time ])
|
25
|
+
end
|
26
|
+
|
27
|
+
def spatial_acceleration
|
28
|
+
Division.new(numerator: Product.new(variables: [ acceleration, time, time ]), denominator: 2)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#to_tex' do
|
34
|
+
context 'when creating the spatial function for constantly accelerated movement' do
|
35
|
+
let(:variables) do
|
36
|
+
{
|
37
|
+
time: Danica::Variable.new(name: :t),
|
38
|
+
acceleration: Danica::Variable.new(name: :a),
|
39
|
+
initial_space: Danica::Variable.new(name: :S0, latex: 'S_0'),
|
40
|
+
initial_velocity: Danica::Variable.new(name: :V0, latex: 'V_0')
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
let(:subject) { described_class::Spatial.new(variables) }
|
45
|
+
let(:expected) { 'S_0 + V_0 \cdot t + \frac{a \cdot t \cdot t}{2}' }
|
46
|
+
|
47
|
+
it 'return the latex format CAM' do
|
48
|
+
expect(subject.to_tex).to eq(expected)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Danica::Variable do
|
4
|
+
describe 'to_f' do
|
5
|
+
context 'when variable has no value' do
|
6
|
+
it { expect { subject.to_f }.to raise_error(Danica::NotDefined) }
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'when variable has value' do
|
10
|
+
let(:value) { 100 }
|
11
|
+
let(:subject) { described_class.new(value: value) }
|
12
|
+
|
13
|
+
it { expect(subject.to_f).to eq(value) }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'to_tex' do
|
18
|
+
let(:name) { :delta }
|
19
|
+
|
20
|
+
context 'when latex is not defined ' do
|
21
|
+
let(:subject) { described_class.new name: name }
|
22
|
+
|
23
|
+
it 'returns name' do
|
24
|
+
expect(subject.to_tex).to eq('delta')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when latex has been defined' do
|
29
|
+
let(:subject) { described_class.new name: name, latex: '\delta' }
|
30
|
+
|
31
|
+
it 'returns latex' do
|
32
|
+
expect(subject.to_tex).to eq('\delta')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
SimpleCov.profiles.define 'gem' do
|
4
|
+
add_filter '/spec/'
|
5
|
+
end
|
6
|
+
|
7
|
+
SimpleCov.start 'gem'
|
8
|
+
require 'pry-nav'
|
9
|
+
require 'danica'
|
10
|
+
|
11
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
12
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
13
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
14
|
+
# loaded once.
|
15
|
+
#
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
|
18
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
19
|
+
# in spec/support/ and its subdirectories.
|
20
|
+
Dir['./spec/support/**/*.rb'].each { |f| require f }
|
21
|
+
|
22
|
+
RSpec.configure do |config|
|
23
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
24
|
+
config.run_all_when_everything_filtered = true
|
25
|
+
config.filter_run :focus
|
26
|
+
|
27
|
+
# Run specs in random order to surface order dependencies. If you find an
|
28
|
+
# order dependency and want to debug it, you can fix the order by providing
|
29
|
+
# the seed, which is printed after each run.
|
30
|
+
# --seed 1234
|
31
|
+
config.order = 'random'
|
32
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
shared_examples 'a function that joins many variables with same operation' do |arguments|
|
2
|
+
it_behaves_like 'a function that knows how to calculate', arguments
|
3
|
+
it_behaves_like 'a function that knows how to write to tex', arguments
|
4
|
+
end
|
5
|
+
|
6
|
+
shared_examples 'a function that knows how to calculate' do |arguments|
|
7
|
+
%w(calculated).each do |key|
|
8
|
+
let(key) { arguments[key.to_sym] }
|
9
|
+
end
|
10
|
+
let(:variables) do
|
11
|
+
(1..4).map do |i|
|
12
|
+
Danica::Variable.new(name: "X#{i}", value: numeric_variables[i-1])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
let(:numeric_variables){ (1..4).to_a }
|
16
|
+
let(:subject) do
|
17
|
+
described_class.new(variables: variables)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'to_f' do
|
21
|
+
it 'returns the sum of variables value' do
|
22
|
+
expect(subject.to_f).to eq(calculated)
|
23
|
+
end
|
24
|
+
|
25
|
+
it do
|
26
|
+
expect(subject.to_f).to be_a(Float)
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when one variable is a number' do
|
30
|
+
let(:variables) { (1..4) }
|
31
|
+
|
32
|
+
it do
|
33
|
+
expect(subject.to_f).to eq(calculated)
|
34
|
+
end
|
35
|
+
|
36
|
+
it do
|
37
|
+
expect(subject.to_f).to be_a(Float)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
shared_examples 'a function that knows how to write to tex' do |arguments|
|
44
|
+
%w(numeric_variables tex_integer_expected tex_expected tex_float_expected).each do |key|
|
45
|
+
let(key) { arguments[key.to_sym] }
|
46
|
+
end
|
47
|
+
let(:subject) do
|
48
|
+
described_class.new(variables: variables)
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'to_tex' do
|
52
|
+
let(:variables) do
|
53
|
+
(1..4).map do |i|
|
54
|
+
Danica::Variable.new(name: "X#{i}")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when variables have no value' do
|
59
|
+
it 'outputs a latex format' do
|
60
|
+
expect(subject.to_tex).to eq(tex_expected)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when some variables have values' do
|
65
|
+
let(:numeric_variables_index) { 1 }
|
66
|
+
before do
|
67
|
+
(0..numeric_variables_index).each do |i|
|
68
|
+
variables[i].value = numeric_variables[i]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'outputs a latex format with colapsed numbers' do
|
73
|
+
expect(subject.to_tex).to eq(tex_integer_expected)
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when numeric variables sum is a float value' do
|
77
|
+
let(:numeric_variables_index) { 2 }
|
78
|
+
|
79
|
+
it 'outputs a latex format with colapsed numbers' do
|
80
|
+
expect(subject.to_tex).to eq(tex_float_expected)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'when some variables are numbers' do
|
86
|
+
let(:numeric_variables_index) { 1 }
|
87
|
+
before do
|
88
|
+
(0..numeric_variables_index).each do |i|
|
89
|
+
variables[i] = numeric_variables[i]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'outputs a latex format with colapsed numbers' do
|
94
|
+
expect(subject.to_tex).to eq(tex_integer_expected)
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'when numeric variables sum is a float value' do
|
98
|
+
let(:numeric_variables_index) { 2 }
|
99
|
+
|
100
|
+
it 'outputs a latex format with colapsed numbers' do
|
101
|
+
expect(subject.to_tex).to eq(tex_float_expected)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
metadata
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: danica
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Darthjee
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activemodel
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.14'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.14'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-mocks
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry-nav
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description:
|
126
|
+
email:
|
127
|
+
- darthjee@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- Gemfile
|
135
|
+
- Gemfile.lock
|
136
|
+
- README.md
|
137
|
+
- Rakefile
|
138
|
+
- danica.gemspec
|
139
|
+
- lib/danica.rb
|
140
|
+
- lib/danica/function.rb
|
141
|
+
- lib/danica/function/chained.rb
|
142
|
+
- lib/danica/function/division.rb
|
143
|
+
- lib/danica/function/product.rb
|
144
|
+
- lib/danica/function/sum.rb
|
145
|
+
- lib/danica/not_defined.rb
|
146
|
+
- lib/danica/number.rb
|
147
|
+
- lib/danica/variable.rb
|
148
|
+
- lib/danica/version.rb
|
149
|
+
- spec/lib/danica/function/division_spec.rb
|
150
|
+
- spec/lib/danica/function/product_spec.rb
|
151
|
+
- spec/lib/danica/function/sum_spec.rb
|
152
|
+
- spec/lib/danica/function_spec.rb
|
153
|
+
- spec/lib/danica/variable_spec.rb
|
154
|
+
- spec/spec_helper.rb
|
155
|
+
- spec/support/shared_examples/function.rb
|
156
|
+
homepage:
|
157
|
+
licenses: []
|
158
|
+
metadata: {}
|
159
|
+
post_install_message:
|
160
|
+
rdoc_options: []
|
161
|
+
require_paths:
|
162
|
+
- lib
|
163
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
requirements: []
|
174
|
+
rubyforge_project:
|
175
|
+
rubygems_version: 2.5.1
|
176
|
+
signing_key:
|
177
|
+
specification_version: 4
|
178
|
+
summary: Danica
|
179
|
+
test_files:
|
180
|
+
- spec/lib/danica/function/division_spec.rb
|
181
|
+
- spec/lib/danica/function/product_spec.rb
|
182
|
+
- spec/lib/danica/function/sum_spec.rb
|
183
|
+
- spec/lib/danica/function_spec.rb
|
184
|
+
- spec/lib/danica/variable_spec.rb
|
185
|
+
- spec/spec_helper.rb
|
186
|
+
- spec/support/shared_examples/function.rb
|