Skip to content

Commit fadf7af

Browse files
Added clang formatting
1 parent 657bd0f commit fadf7af

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed

src/main/java/com/thealgorithms/maths/PiApproximation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public Point(double x, double y) {
3838
* @return An estimate of the number π
3939
*/
4040
public static double approximatePi(List<Point> pts) {
41-
double count = 0; // Points in circle
41+
double count = 0; // Points in circle
4242

4343
for (Point p : pts) {
4444
if ((p.x * p.x) + (p.y * p.y) <= 1) {
@@ -60,8 +60,8 @@ public static List<Point> generateRandomPoints(int numPoints) {
6060
Random rand = new Random();
6161

6262
for (int i = 0; i < numPoints; i++) {
63-
double x = rand.nextDouble(); // Random value between 0 and 1
64-
double y = rand.nextDouble(); // Random value between 0 and 1
63+
double x = rand.nextDouble(); // Random value between 0 and 1
64+
double y = rand.nextDouble(); // Random value between 0 and 1
6565
points.add(new Point(x, y));
6666
}
6767

src/test/java/com/thealgorithms/maths/PiApproximationTest.java

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
package 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

66
import java.util.ArrayList;
77
import 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

1210
class 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

Comments
 (0)