spec/lib/danica/function_spec.rb in danica-0.1.0 vs spec/lib/danica/function_spec.rb in danica-0.2.0
- old
+ new
@@ -23,27 +23,31 @@
def spatial_velocity
Product.new(variables: [ initial_velocity, time ])
end
def spatial_acceleration
- Division.new(numerator: Product.new(variables: [ acceleration, time, time ]), denominator: 2)
+ Division.new(numerator: Product.new(variables: [ acceleration, time_squared ]), denominator: 2)
end
+
+ def time_squared
+ Power.new(base: time, exponent: 2)
+ end
end
end
describe '#to_tex' do
context 'when creating the spatial function for constantly accelerated movement' do
let(:variables) do
{
- time: Danica::Variable.new(name: :t),
- acceleration: Danica::Variable.new(name: :a),
- initial_space: Danica::Variable.new(name: :S0, latex: 'S_0'),
- initial_velocity: Danica::Variable.new(name: :V0, latex: 'V_0')
+ time: :t,
+ acceleration: 'a',
+ initial_space: { name: :S0, latex: 'S_0' },
+ initial_velocity: { name: :V0, latex: 'V_0' }
}
end
let(:subject) { described_class::Spatial.new(variables) }
- let(:expected) { 'S_0 + V_0 \cdot t + \frac{a \cdot t \cdot t}{2}' }
+ let(:expected) { 'S_0 + V_0 \cdot t + \frac{a \cdot t^2}{2}' }
it 'return the latex format CAM' do
expect(subject.to_tex).to eq(expected)
end
end