Skip to content

Commit e00efa5

Browse files
authored
Update ChebyshevIterationTest.java
1 parent b4e47fc commit e00efa5

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

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

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,55 @@
55

66
import org.junit.jupiter.api.Test;
77

8+
/**
9+
* Unit tests for ChebyshevIteration class
10+
*/
811
class ChebyshevIterationTest {
912

10-
private static final double[][] M1_A = { { 4.0, 1.0 }, { 1.0, 3.0 } };
11-
private static final double[] M1_B = { 1.0, 2.0 };
12-
private static final double[] M1_X0 = { 0.0, 0.0 };
13+
private static final double[][] M1_A = {{4.0, 1.0}, {1.0, 3.0}};
14+
private static final double[] M1_B = {1.0, 2.0};
15+
private static final double[] M1_X0 = {0.0, 0.0};
1316
private static final double M1_LAMBDA_MIN = (7.0 - Math.sqrt(5.0)) / 2.0;
1417
private static final double M1_LAMBDA_MAX = (7.0 + Math.sqrt(5.0)) / 2.0;
15-
private static final double[] M1_EXPECTED = { 1.0 / 11.0, 7.0 / 11.0 };
18+
private static final double[] M1_EXPECTED = {1.0 / 11.0, 7.0 / 11.0};
1619

17-
private static final double[][] M2_A = { { 5.0, 0.0, 0.0 }, { 0.0, 2.0, 0.0 }, { 0.0, 0.0, 8.0 } };
18-
private static final double[] M2_B = { 10.0, -4.0, 24.0 };
19-
private static final double[] M2_X0 = { 0.0, 0.0, 0.0 };
20-
private static final double[] M2_EXPECTED = { 2.0, -2.0, 3.0 };
20+
private static final double[][] M2_A = {{5.0, 0.0, 0.0}, {0.0, 2.0, 0.0}, {0.0, 0.0, 8.0}};
21+
private static final double[] M2_B = {10.0, -4.0, 24.0};
22+
private static final double[] M2_X0 = {0.0, 0.0, 0.0};
23+
private static final double[] M2_EXPECTED = {2.0, -2.0, 3.0};
2124
private static final double M2_LAMBDA_MIN = 2.0;
2225
private static final double M2_LAMBDA_MAX = 8.0;
2326

24-
private static final double MAX_ITERATIONS = 100;
27+
private static final int MAX_ITERATIONS = 1000;
2528
private static final double TOLERANCE = 1e-10;
2629
private static final double ASSERT_TOLERANCE = 1e-9;
2730

2831
@Test
29-
void testSolveSimple2x2System() {
30-
double[] solution = ChebyshevIteration.solve(M1_A, M1_B, M1_X0, M1_LAMBDA_MIN, M1_LAMBDA_MAX, 100, TOLERANCE);
32+
void testSolve2x2System() {
33+
double[] solution = ChebyshevIteration.solve(
34+
M1_A, M1_B, M1_X0, M1_LAMBDA_MIN, M1_LAMBDA_MAX, MAX_ITERATIONS, TOLERANCE);
3135
assertArrayEquals(M1_EXPECTED, solution, ASSERT_TOLERANCE);
3236
}
3337

3438
@Test
3539
void testSolve3x3System() {
36-
double[] solution = ChebyshevIteration.solve(M2_A, M2_B, M2_X0, M2_LAMBDA_MIN, M2_LAMBDA_MAX, 100, TOLERANCE);
40+
double[] solution = ChebyshevIteration.solve(
41+
M2_A, M2_B, M2_X0, M2_LAMBDA_MIN, M2_LAMBDA_MAX, MAX_ITERATIONS, TOLERANCE);
3742
assertArrayEquals(M2_EXPECTED, solution, ASSERT_TOLERANCE);
3843
}
3944

4045
@Test
4146
void testAlreadyConverged() {
42-
double[] solution = ChebyshevIteration.solve(M1_A, M1_B, M1_EXPECTED, M1_LAMBDA_MIN, M1_LAMBDA_MAX, 100, TOLERANCE);
47+
double[] solution = ChebyshevIteration.solve(
48+
M1_A, M1_B, M1_EXPECTED, M1_LAMBDA_MIN, M1_LAMBDA_MAX, MAX_ITERATIONS, TOLERANCE);
4349
assertArrayEquals(M1_EXPECTED, solution, ASSERT_TOLERANCE);
4450
}
4551

4652
@Test
4753
void testInvalidEigenvalues() {
48-
assertThrows(IllegalArgumentException.class,
49-
() -> ChebyshevIteration.solve(M1_A, M1_B, M1_X0, 2.0, 1.0, 10, 1e-5));
50-
assertThrows(IllegalArgumentException.class,
51-
() -> ChebyshevIteration.solve(M1_A, M1_B, M1_X0, 0.0, 2.0, 10, 1e-5));
54+
assertThrows(IllegalArgumentException.class, () ->
55+
ChebyshevIteration.solve(M1_A, M1_B, M1_X0, 2.0, 1.0, 10, 1e-5));
56+
assertThrows(IllegalArgumentException.class, () ->
57+
ChebyshevIteration.solve(M1_A, M1_B, M1_X0, 0.0, 2.0, 10, 1e-5));
5258
}
5359
}

0 commit comments

Comments
 (0)