forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKinematicsTest.java
More file actions
48 lines (39 loc) · 1.69 KB
/
KinematicsTest.java
File metadata and controls
48 lines (39 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.thealgorithms.physics;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
/**
* Unit tests for the Kinematics utility class.
*/
public final class KinematicsTest {
// A small tolerance for comparing floating-point numbers
private static final double DELTA = 1e-9;
@Test
@DisplayName("Test final velocity: v = u + at")
void testCalculateFinalVelocity() {
assertEquals(20.0, Kinematics.calculateFinalVelocity(10.0, 2.0, 5.0), DELTA);
}
@Test
@DisplayName("Test displacement: s = ut + 0.5at^2")
void testCalculateDisplacement() {
assertEquals(75.0, Kinematics.calculateDisplacement(10.0, 2.0, 5.0), DELTA);
}
@Test
@DisplayName("Test final velocity squared: v^2 = u^2 + 2as")
void testCalculateFinalVelocitySquared() {
assertEquals(400.0, Kinematics.calculateFinalVelocitySquared(10.0, 2.0, 75.0), DELTA);
}
@Test
@DisplayName("Test displacement from average velocity: s = (u+v)/2 * t")
void testCalculateDisplacementFromVelocities() {
assertEquals(75.0, Kinematics.calculateDisplacementFromVelocities(10.0, 20.0, 5.0), DELTA);
}
@Test
@DisplayName("Test with negative acceleration (deceleration)")
void testDeceleration() {
assertEquals(10.0, Kinematics.calculateFinalVelocity(30.0, -4.0, 5.0), DELTA);
assertEquals(100.0, Kinematics.calculateDisplacement(30.0, -4.0, 5.0), DELTA);
assertEquals(100.0, Kinematics.calculateFinalVelocitySquared(30.0, -4.0, 100.0), DELTA);
assertEquals(100.0, Kinematics.calculateDisplacementFromVelocities(30.0, 10.0, 5.0), DELTA);
}
}