danica 0.2.0 → 0.3.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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/danica/function.rb +1 -0
- data/lib/danica/function/division.rb +2 -0
- data/lib/danica/function/power.rb +3 -1
- data/lib/danica/function/square_root.rb +23 -0
- data/lib/danica/number.rb +2 -2
- data/lib/danica/version.rb +1 -1
- data/spec/lib/danica/function/division_spec.rb +2 -2
- data/spec/lib/danica/function/power_spec.rb +10 -10
- data/spec/lib/danica/function/square_root_spec.rb +53 -0
- data/spec/lib/danica/function_spec.rb +1 -1
- data/spec/lib/danica/variable_spec.rb +3 -1
- metadata +4 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 8d8ae393046bb15fcbcd46af8e9430aa50bbbad6
         | 
| 4 | 
            +
              data.tar.gz: 835a4b71b6348e1a3da11a34771d4b4864a37894
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 74eb602d0265187cc3505c25b0870d9564a05bb82e6ae072efdca3cba8be6c9a5b04c243c179a68e8fc94f5f5e73fdfca5c941e547ff1d24e4197f14c78e02ba
         | 
| 7 | 
            +
              data.tar.gz: a389e884fa35861559a76b78ee907b6525a42a3274ddb6ee25d41a896361b5df5003328b2186fdc6d4a1382b9944b80318c022256e22861b27bd551ec7850425
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/lib/danica/function.rb
    CHANGED
    
    
| @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            module Danica
         | 
| 2 | 
            +
              class Function
         | 
| 3 | 
            +
                class SquareRoot < Function
         | 
| 4 | 
            +
                  attr_reader :variable
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  def to_f
         | 
| 7 | 
            +
                    Math.sqrt(variable.to_f)
         | 
| 8 | 
            +
                  end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  def to_tex
         | 
| 11 | 
            +
                    Number.new(to_f).to_tex
         | 
| 12 | 
            +
                  rescue NotDefined
         | 
| 13 | 
            +
                    "\\sqrt{#{variable.to_tex}}"
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  def variable=(value)
         | 
| 17 | 
            +
                    @variable = wrap_value(value)
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
            end
         | 
| 23 | 
            +
             | 
    
        data/lib/danica/number.rb
    CHANGED
    
    
    
        data/lib/danica/version.rb
    CHANGED
    
    
| @@ -72,8 +72,8 @@ describe Danica::Function::Division do | |
| 72 72 | 
             
                end
         | 
| 73 73 |  | 
| 74 74 | 
             
                context 'when both variables are numeric' do
         | 
| 75 | 
            -
                  it 'prints  | 
| 76 | 
            -
                    expect(subject.to_tex).to eq(' | 
| 75 | 
            +
                  it 'prints the result of the division' do
         | 
| 76 | 
            +
                    expect(subject.to_tex).to eq('0.5')
         | 
| 77 77 | 
             
                  end
         | 
| 78 78 | 
             
                end
         | 
| 79 79 |  | 
| @@ -14,7 +14,7 @@ describe Danica::Function::Power do | |
| 14 14 |  | 
| 15 15 | 
             
              describe 'to_f' do
         | 
| 16 16 | 
             
                context 'when variables are not numbers but have value' do
         | 
| 17 | 
            -
                  it 'returns the  | 
| 17 | 
            +
                  it 'returns the power of the values' do
         | 
| 18 18 | 
             
                    expect(subject.to_f).to eq(9.0)
         | 
| 19 19 | 
             
                  end
         | 
| 20 20 |  | 
| @@ -26,7 +26,7 @@ describe Danica::Function::Power do | |
| 26 26 | 
             
                context 'when all the variables are numbers' do
         | 
| 27 27 | 
             
                  let(:variables) { [ 3, 2 ] }
         | 
| 28 28 |  | 
| 29 | 
            -
                  it 'returns the  | 
| 29 | 
            +
                  it 'returns the power of the values' do
         | 
| 30 30 | 
             
                    expect(subject.to_f).to eq(9.0)
         | 
| 31 31 | 
             
                  end
         | 
| 32 32 |  | 
| @@ -40,7 +40,7 @@ describe Danica::Function::Power do | |
| 40 40 | 
             
                    variables[0] = 3
         | 
| 41 41 | 
             
                  end
         | 
| 42 42 |  | 
| 43 | 
            -
                  it 'returns the  | 
| 43 | 
            +
                  it 'returns the power of the values' do
         | 
| 44 44 | 
             
                    expect(subject.to_f).to eq(9.0)
         | 
| 45 45 | 
             
                  end
         | 
| 46 46 |  | 
| @@ -57,7 +57,7 @@ describe Danica::Function::Power do | |
| 57 57 | 
             
                  end
         | 
| 58 58 |  | 
| 59 59 | 
             
                  it 'returns a latex format fraction' do
         | 
| 60 | 
            -
                    expect(subject.to_tex).to eq('X1^X2')
         | 
| 60 | 
            +
                    expect(subject.to_tex).to eq('X1^{X2}')
         | 
| 61 61 | 
             
                  end
         | 
| 62 62 | 
             
                end
         | 
| 63 63 |  | 
| @@ -66,14 +66,14 @@ describe Danica::Function::Power do | |
| 66 66 | 
             
                    subject.exponent.value = nil
         | 
| 67 67 | 
             
                  end
         | 
| 68 68 |  | 
| 69 | 
            -
                  it 'returns  | 
| 70 | 
            -
                    expect(subject.to_tex).to eq('3^X2')
         | 
| 69 | 
            +
                  it 'returns both variables' do
         | 
| 70 | 
            +
                    expect(subject.to_tex).to eq('3^{X2}')
         | 
| 71 71 | 
             
                  end
         | 
| 72 72 | 
             
                end
         | 
| 73 73 |  | 
| 74 74 | 
             
                context 'when both variables are numeric' do
         | 
| 75 | 
            -
                  it 'prints  | 
| 76 | 
            -
                    expect(subject.to_tex).to eq(' | 
| 75 | 
            +
                  it 'prints the final calculation' do
         | 
| 76 | 
            +
                    expect(subject.to_tex).to eq('9')
         | 
| 77 77 | 
             
                  end
         | 
| 78 78 | 
             
                end
         | 
| 79 79 |  | 
| @@ -83,8 +83,8 @@ describe Danica::Function::Power do | |
| 83 83 | 
             
                    subject.exponent.value = nil
         | 
| 84 84 | 
             
                  end
         | 
| 85 85 |  | 
| 86 | 
            -
                  it 'prints both  | 
| 87 | 
            -
                    expect(subject.to_tex).to eq('1^X2')
         | 
| 86 | 
            +
                  it 'prints both variables' do
         | 
| 87 | 
            +
                    expect(subject.to_tex).to eq('1^{X2}')
         | 
| 88 88 | 
             
                  end
         | 
| 89 89 | 
             
                end
         | 
| 90 90 | 
             
              end
         | 
| @@ -0,0 +1,53 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Danica::Function::SquareRoot do
         | 
| 4 | 
            +
              let(:variables_number) { 4 }
         | 
| 5 | 
            +
              let(:variable) { { name: "X", value: 9 } }
         | 
| 6 | 
            +
              let(:subject) do
         | 
| 7 | 
            +
                described_class.new(variable: variable)
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              describe 'to_f' do
         | 
| 11 | 
            +
                context 'when variables are not numbers but have value' do
         | 
| 12 | 
            +
                  it 'returns the division of the values' do
         | 
| 13 | 
            +
                    expect(subject.to_f).to eq(3.0)
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  it do
         | 
| 17 | 
            +
                    expect(subject.to_f).to be_a(Float)
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                context 'when the variable is a number' do
         | 
| 22 | 
            +
                  let(:variable) { 9 }
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  it 'returns the squared root of the value' do
         | 
| 25 | 
            +
                    expect(subject.to_f).to eq(3.0)
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  it do
         | 
| 29 | 
            +
                    expect(subject.to_f).to be_a(Float)
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
              describe 'to_tex' do
         | 
| 35 | 
            +
                context 'when variables have no value' do
         | 
| 36 | 
            +
                  let(:variable) { :X }
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                  it 'returns a latex format fraction' do
         | 
| 39 | 
            +
                    expect(subject.to_tex).to eq('\sqrt{X}')
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                context 'when the variable is numeric' do
         | 
| 44 | 
            +
                  before do
         | 
| 45 | 
            +
                    subject.variable.value = 9
         | 
| 46 | 
            +
                  end
         | 
| 47 | 
            +
                  it 'prints both numbers' do
         | 
| 48 | 
            +
                    expect(subject.to_tex).to eq('3')
         | 
| 49 | 
            +
                  end
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
              end
         | 
| 52 | 
            +
            end
         | 
| 53 | 
            +
             | 
| @@ -46,7 +46,7 @@ describe Danica::Function do | |
| 46 46 | 
             
                  end
         | 
| 47 47 |  | 
| 48 48 | 
             
                  let(:subject) { described_class::Spatial.new(variables) }
         | 
| 49 | 
            -
                  let(:expected) { 'S_0 + V_0 \cdot t + \frac{a \cdot t^2}{2}'  }
         | 
| 49 | 
            +
                  let(:expected) { 'S_0 + V_0 \cdot t + \frac{a \cdot t^{2}}{2}'  }
         | 
| 50 50 |  | 
| 51 51 | 
             
                  it 'return the latex format CAM' do
         | 
| 52 52 | 
             
                    expect(subject.to_tex).to eq(expected)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: danica
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.3.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Darthjee
         | 
| @@ -142,6 +142,7 @@ files: | |
| 142 142 | 
             
            - lib/danica/function/division.rb
         | 
| 143 143 | 
             
            - lib/danica/function/power.rb
         | 
| 144 144 | 
             
            - lib/danica/function/product.rb
         | 
| 145 | 
            +
            - lib/danica/function/square_root.rb
         | 
| 145 146 | 
             
            - lib/danica/function/sum.rb
         | 
| 146 147 | 
             
            - lib/danica/not_defined.rb
         | 
| 147 148 | 
             
            - lib/danica/number.rb
         | 
| @@ -150,6 +151,7 @@ files: | |
| 150 151 | 
             
            - spec/lib/danica/function/division_spec.rb
         | 
| 151 152 | 
             
            - spec/lib/danica/function/power_spec.rb
         | 
| 152 153 | 
             
            - spec/lib/danica/function/product_spec.rb
         | 
| 154 | 
            +
            - spec/lib/danica/function/square_root_spec.rb
         | 
| 153 155 | 
             
            - spec/lib/danica/function/sum_spec.rb
         | 
| 154 156 | 
             
            - spec/lib/danica/function_spec.rb
         | 
| 155 157 | 
             
            - spec/lib/danica/variable_spec.rb
         | 
| @@ -182,6 +184,7 @@ test_files: | |
| 182 184 | 
             
            - spec/lib/danica/function/division_spec.rb
         | 
| 183 185 | 
             
            - spec/lib/danica/function/power_spec.rb
         | 
| 184 186 | 
             
            - spec/lib/danica/function/product_spec.rb
         | 
| 187 | 
            +
            - spec/lib/danica/function/square_root_spec.rb
         | 
| 185 188 | 
             
            - spec/lib/danica/function/sum_spec.rb
         | 
| 186 189 | 
             
            - spec/lib/danica/function_spec.rb
         | 
| 187 190 | 
             
            - spec/lib/danica/variable_spec.rb
         |