11package com .thealgorithms .physics ;
22
3- import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
43import static org .junit .jupiter .api .Assertions .assertEquals ;
54import static org .junit .jupiter .api .Assertions .assertThrows ;
65
@@ -15,60 +14,60 @@ final class RelativityTest {
1514 // A small tolerance (delta) for comparing floating-point numbers
1615 private static final double DELTA = 1e-6 ;
1716 private static final double C = Relativity .SPEED_OF_LIGHT ;
18-
17+
1918 @ Test
2019 @ DisplayName ("Test the gamma parameter" )
2120 void testGamma () {
22- double myGamma = Relativity .gamma (0.6 * C );
21+ double myGamma = Relativity .gamma (0.6 * C );
2322 assertEquals (1.25 , myGamma , DELTA );
2423 }
25-
24+
2625 @ Test
2726 @ DisplayName ("Test the length contraction" )
2827 void testLengthContraction () {
29- double myLength = Relativity .lengthContraction (5.0 , 0.8 * C );
28+ double myLength = Relativity .lengthContraction (5.0 , 0.8 * C );
3029 assertEquals (3.0 , myLength , DELTA );
3130 }
32-
31+
3332 @ Test
3433 @ DisplayName ("Test the time dilation" )
3534 void testTimeDilation () {
36- double myTime = Relativity .timeDilation (4.0 , 0.6 * C );
35+ double myTime = Relativity .timeDilation (4.0 , 0.6 * C );
3736 assertEquals (5.0 , myTime , DELTA );
3837 }
39-
38+
4039 @ Test
4140 @ DisplayName ("Test the velocity addition in the same direction" )
4241 void testVelocityAdditionSameDirection () {
43- double myVelocity = Relativity .velocityAddition (0.8 * C , 0.75 * C );
42+ double myVelocity = Relativity .velocityAddition (0.8 * C , 0.75 * C );
4443 assertEquals (0.125 *C , myVelocity , DELTA );
4544 }
46-
45+
4746 @ Test
4847 @ DisplayName ("Test the velocity addition in different directions" )
4948 void testVelocityAdditionDifferentDirections () {
50- double myVelocity = Relativity .velocityAddition (0.8 * C , -0.75 * C );
49+ double myVelocity = Relativity .velocityAddition (0.8 * C , -0.75 * C );
5150 assertEquals (0.96875 *C , myVelocity , DELTA );
5251 }
5352
5453 @ Test
5554 @ DisplayName ("Test the velocity addition with the speed of light" )
5655 void testVelocityAdditionWithSpeedOfLight () {
57- double myVelocity = Relativity .velocityAddition (C , 0.7 * C );
56+ double myVelocity = Relativity .velocityAddition (C , 0.7 * C );
5857 assertEquals (C , myVelocity , DELTA );
5958 }
60-
59+
6160 @ Test
6261 @ DisplayName ("Test invalid inputs throw exception" )
6362 void testInvalidOrbitalVelocityInputs () {
64- assertThrows (IllegalArgumentException .class , () -> Relativity .gamma (1.2 * C ));
63+ assertThrows (IllegalArgumentException .class , () -> Relativity .gamma (1.2 * C ));
6564 assertThrows (IllegalArgumentException .class , () -> Relativity .gamma (-C ));
66- assertThrows (IllegalArgumentException .class , () -> Relativity .lengthContraction (-1.0 , 0.6 * C ));
67- assertThrows (IllegalArgumentException .class , () -> Relativity .lengthContraction (1.0 , 1.5 * C ));
68- assertThrows (IllegalArgumentException .class , () -> Relativity .timeDilation (-5.0 , -0.8 * C ));
65+ assertThrows (IllegalArgumentException .class , () -> Relativity .lengthContraction (-1.0 , 0.6 * C ));
66+ assertThrows (IllegalArgumentException .class , () -> Relativity .lengthContraction (1.0 , 1.5 * C ));
67+ assertThrows (IllegalArgumentException .class , () -> Relativity .timeDilation (-5.0 , -0.8 * C ));
6968 assertThrows (IllegalArgumentException .class , () -> Relativity .timeDilation (5.0 , C ));
70- assertThrows (IllegalArgumentException .class , () -> Relativity .velocityAddition (0.3 * C , -C ));
71- assertThrows (IllegalArgumentException .class , () -> Relativity .velocityAddition (1.4 * C , 0.2 * C ));
72- assertThrows (IllegalArgumentException .class , () -> Relativity .velocityAddition (-0.4 * C , 1.2 * C ));
69+ assertThrows (IllegalArgumentException .class , () -> Relativity .velocityAddition (0.3 * C , -C ));
70+ assertThrows (IllegalArgumentException .class , () -> Relativity .velocityAddition (1.4 * C , 0.2 * C ));
71+ assertThrows (IllegalArgumentException .class , () -> Relativity .velocityAddition (-0.4 * C , 1.2 * C ));
7372 }
7473}
0 commit comments