Skip to content

Commit c3904bc

Browse files
committed
feat: add delta x motion equation implementation
Fixes: #191
1 parent bda11bd commit c3904bc

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

maths/delta_x.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
# Computes displacement from uniformly accelerated motion:
4+
# delta_x = v0 * t + 0.5 * a * t^2
5+
class DeltaX
6+
class << self
7+
def call(initial_velocity:, time:, acceleration:)
8+
(initial_velocity * time) + (0.5 * acceleration * time * time)
9+
end
10+
end
11+
end

maths/delta_x_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
require 'minitest/autorun'
4+
require_relative './delta_x'
5+
6+
class DeltaXTest < Minitest::Test
7+
def test_zero_acceleration
8+
assert_in_delta 15.0, DeltaX.call(initial_velocity: 3.0, time: 5.0, acceleration: 0.0), 1E-12
9+
end
10+
11+
def test_positive_acceleration
12+
assert_in_delta 20.0, DeltaX.call(initial_velocity: 2.0, time: 4.0, acceleration: 1.5), 1E-12
13+
end
14+
15+
def test_negative_acceleration
16+
assert_in_delta 2.0, DeltaX.call(initial_velocity: 5.0, time: 2.0, acceleration: -4.0), 1E-12
17+
end
18+
end

0 commit comments

Comments
 (0)