Skip to content

Commit 9348239

Browse files
Adding one more test case
1 parent 4527bcb commit 9348239

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/test/java/com/thealgorithms/physics/DampedOscillatorTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,21 @@ void gettersReturnConfiguration() {
121121

122122
assertAll("getters", () -> assertEquals(omega0, d.getOmega0(), 0.0, "getOmega0 should return configured omega0"), () -> assertEquals(gamma, d.getGamma(), 0.0, "getGamma should return configured gamma"));
123123
}
124+
125+
@Test
126+
@DisplayName("Analytical displacement at t=0 returns initial amplitude * cos(phase)")
127+
void analyticalAtZeroTime() {
128+
double omega0 = 5.0;
129+
double gamma = 0.2;
130+
DampedOscillator d = new DampedOscillator(omega0, gamma);
131+
132+
double A = 2.0;
133+
double phi = Math.PI / 3.0;
134+
double t = 0.0;
135+
136+
double expected = A * Math.cos(phi);
137+
double actual = d.displacementAnalytical(A, phi, t);
138+
139+
assertEquals(expected, actual, 1e-12, "Displacement at t=0 should be A * cos(phase)");
140+
}
124141
}

0 commit comments

Comments
 (0)