Sha256: 6c4290b8dd53e7dbf7c0b8472bedc7307bc10493683b293ae2a322d1cc241927

Contents?: true

Size: 1.96 KB

Versions: 4

Compression:

Stored size: 1.96 KB

Contents

require 'spec_helper'

describe Danica::Function::Spatial do
  subject do
    described_class.new(
      time: :t,
      acceleration: 'a',
      initial_space: { name: :S0, latex: 'S_0', gnu: 'S0' },
      initial_velocity: { name: :V0, latex: 'V_0', gnu: 'V0' }
    )
  end

  let(:name) { :f }

  context 'when using it as default' do
    let(:left) { "#{name}(time, acceleration, initial_space, initial_velocity)" }
    let(:right) { 'initial_space + initial_velocity * time + (acceleration * time**(2))/(2)' }

    subject { described_class.new }

    it 'knows how to return to gnu format' do
      expect(subject.to_gnu).to eq("#{left} = #{right}")
    end

    context 'when changing the name' do
      let(:name) { :g }
      subject { described_class.new(name: name) }

      it 'knows how to return to gnu format' do
        expect(subject.to_gnu).to eq("#{left} = #{right}")
      end
    end
  end

  context 'when setting the variables' do
    let(:variables) do
      { time: :t, acceleration: :a, initial_space: :s0, initial_velocity: :v0 }
    end
    let(:left) { "#{name}(t, a, s0, v0)" }
    let(:right) { 's0 + v0 * t + (a * t**(2))/(2)' }

    subject { described_class.new(variables) }

    it 'knows how to return to gnu format' do
      expect(subject.to_gnu).to eq("#{left} = #{right}")
    end
  end

  describe '#to_tex' do
    let(:left) { "#{name}(t, a, S_0, V_0)" }
    let(:right) { 'S_0 + V_0 \cdot t + \frac{a \cdot t^{2}}{2}' }

    it 'builds tex format with its variables' do
      expect(subject.to_tex).to eq("#{left} = #{right}")
    end
  end

  describe '#to_gnu' do
    let(:left) { "#{name}(t, a, S0, V0)" }
    let(:right) { 'S0 + V0 * t + (a * t**(2))/(2)' }

    it 'builds gnu format with its variables' do
      expect(subject.to_gnu).to eq("#{left} = #{right}")
    end
  end
end

describe Danica::Function::MyFunction do
  describe '#to_gnu' do
    it 'returns the function' do
      expect(subject.to_gnu).to eq('f(x, y) = x**(2) + y')
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
danica-2.6.2 spec/integration/readme/function_spec.rb
danica-2.6.1 spec/integration/readme/function_spec.rb
danica-2.6.0 spec/integration/readme/function_spec.rb
danica-2.5.1 spec/integration/readme/function_spec.rb