Skip to content

Commit 785c8af

Browse files
#6219: Using Function.identity() instead of an identity lambda.
1 parent 9034842 commit 785c8af

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/test/java/com/thealgorithms/randomized/MonteCarloIntegrationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void testConstantFunction() {
2020
@Test
2121
void testLinearFunction() {
2222
// Integral of f(x) = x from 0 to 1 is 0.5
23-
Function<Double, Double> linear = x -> x;
23+
Function<Double, Double> linear = Function.identity();
2424
double result = MonteCarloIntegration.approximate(linear, 0, 1, 10000);
2525
assertEquals(0.5, result, EPSILON);
2626
}
@@ -43,7 +43,7 @@ void testLargeSampleSize() {
4343

4444
@Test
4545
void testReproducibility() {
46-
Function<Double, Double> linear = x -> x;
46+
Function<Double, Double> linear = Function.identity();
4747
double result1 = MonteCarloIntegration.approximate(linear, 0, 1, 10000, 42L);
4848
double result2 = MonteCarloIntegration.approximate(linear, 0, 1, 10000, 42L);
4949
assertEquals(result1, result2, 0.0); // Exactly equal
@@ -52,7 +52,7 @@ void testReproducibility() {
5252
@Test
5353
void testNegativeInterval() {
5454
// Integral of f(x) = x from -1 to 1 is 0
55-
Function<Double, Double> linear = x -> x;
55+
Function<Double, Double> linear = Function.identity();
5656
double result = MonteCarloIntegration.approximate(linear, -1, 1, 10000);
5757
assertEquals(0.0, result, EPSILON);
5858
}

0 commit comments

Comments
 (0)