11package com .thealgorithms .maths ;
22
3-
4- import org .junit .jupiter .api .Test ;
3+ import static org . junit . jupiter . api . Assertions . assertEquals ;
4+ import static org .junit .jupiter .api .Assertions . assertTrue ;
55
66import java .util .ArrayList ;
77import java .util .List ;
8-
9- import static org .junit .jupiter .api .Assertions .assertEquals ;
10- import static org .junit .jupiter .api .Assertions .assertTrue ;
8+ import org .junit .jupiter .api .Test ;
119
1210class PiApproximationTest {
1311
14- private static final double DELTA = 0.5 ; // Tolerance for Pi approximation
15- private static final double TIGHT_DELTA = 0.1 ; // Tighter tolerance for large samples
12+ private static final double DELTA = 0.5 ; // Tolerance for Pi approximation
13+ private static final double TIGHT_DELTA = 0.1 ; // Tighter tolerance for large samples
1614
1715 /**
1816 * Test with known points that are all inside the quarter circle.
1917 */
2018 @ Test
2119 public void testAllPointsInside () {
2220 List <PiApproximation .Point > points = new ArrayList <>();
23- points .add (new PiApproximation .Point (0.0 , 0.0 )); // Origin
24- points .add (new PiApproximation .Point (0.5 , 0.5 )); // Inside
25- points .add (new PiApproximation .Point (0.3 , 0.3 )); // Inside
21+ points .add (new PiApproximation .Point (0.0 , 0.0 )); // Origin
22+ points .add (new PiApproximation .Point (0.5 , 0.5 )); // Inside
23+ points .add (new PiApproximation .Point (0.3 , 0.3 )); // Inside
2624
2725 double result = PiApproximation .approximatePi (points );
2826 // All points inside, so result should be 4.0
@@ -35,8 +33,8 @@ public void testAllPointsInside() {
3533 @ Test
3634 public void testAllPointsOutside () {
3735 List <PiApproximation .Point > points = new ArrayList <>();
38- points .add (new PiApproximation .Point (1.0 , 1.0 )); // Corner - outside
39- points .add (new PiApproximation .Point (0.9 , 0.9 )); // Outside
36+ points .add (new PiApproximation .Point (1.0 , 1.0 )); // Corner - outside
37+ points .add (new PiApproximation .Point (0.9 , 0.9 )); // Outside
4038
4139 double result = PiApproximation .approximatePi (points );
4240 // No points inside, so result should be 0.0
@@ -67,8 +65,8 @@ public void testMixedPoints() {
6765 @ Test
6866 public void testBoundaryPoint () {
6967 List <PiApproximation .Point > points = new ArrayList <>();
70- points .add (new PiApproximation .Point (1.0 , 0.0 )); // On circle: x² + y² = 1
71- points .add (new PiApproximation .Point (0.0 , 1.0 )); // On circle
68+ points .add (new PiApproximation .Point (1.0 , 0.0 )); // On circle: x² + y² = 1
69+ points .add (new PiApproximation .Point (0.0 , 1.0 )); // On circle
7270
7371 double result = PiApproximation .approximatePi (points );
7472 // Boundary points should be counted as inside (≤ 1)
@@ -118,8 +116,7 @@ public void testResultIsBounded() {
118116 List <PiApproximation .Point > points = PiApproximation .generateRandomPoints (1000 );
119117 double result = PiApproximation .approximatePi (points );
120118
121- assertTrue (result >= 0 && result <= 4 ,
122- "Pi approximation should be between 0 and 4" );
119+ assertTrue (result >= 0 && result <= 4 , "Pi approximation should be between 0 and 4" );
123120 }
124121
125122 /**
@@ -154,10 +151,8 @@ public void testGeneratedPointsInRange() {
154151 List <PiApproximation .Point > points = PiApproximation .generateRandomPoints (100 );
155152
156153 for (PiApproximation .Point p : points ) {
157- assertTrue (p .x >= 0 && p .x <= 1 ,
158- "X coordinate should be between 0 and 1" );
159- assertTrue (p .y >= 0 && p .y <= 1 ,
160- "Y coordinate should be between 0 and 1" );
154+ assertTrue (p .x >= 0 && p .x <= 1 , "X coordinate should be between 0 and 1" );
155+ assertTrue (p .y >= 0 && p .y <= 1 , "Y coordinate should be between 0 and 1" );
161156 }
162157 }
163158
@@ -167,9 +162,8 @@ public void testGeneratedPointsInRange() {
167162 @ Test
168163 public void testCorrectNumberOfPointsGenerated () {
169164 int expectedSize = 500 ;
170- List <PiApproximation .Point > points =
171- PiApproximation .generateRandomPoints (expectedSize );
165+ List <PiApproximation .Point > points = PiApproximation .generateRandomPoints (expectedSize );
172166
173167 assertEquals (expectedSize , points .size ());
174168 }
175- }
169+ }
0 commit comments