66import org .junit .jupiter .api .Test ;
77
88class LUDecompositionTest {
9-
109 private static final double EPSILON = 1e-10 ;
1110
1211 @ Test
1312 void testBasicLUDecomposition () {
1413 double [][] matrix = {{2 , -1 , -2 }, {-4 , 6 , 3 }, {-4 , -2 , 8 }};
15-
1614 LUDecomposition .Result result = LUDecomposition .decompose (matrix );
1715
1816 double [][] expectedL = {{1.0 , 0.0 , 0.0 }, {-2.0 , 1.0 , 0.0 }, {-2.0 , -1.0 , 1.0 }};
19-
2017 double [][] expectedU = {{2.0 , -1.0 , -2.0 }, {0.0 , 4.0 , -1.0 }, {0.0 , 0.0 , 3.0 }};
2118
2219 assertMatrixEquals (expectedL , result .getL ());
@@ -26,7 +23,6 @@ void testBasicLUDecomposition() {
2623 @ Test
2724 void testIdentityMatrix () {
2825 double [][] matrix = {{1 , 0 , 0 }, {0 , 1 , 0 }, {0 , 0 , 1 }};
29-
3026 LUDecomposition .Result result = LUDecomposition .decompose (matrix );
3127
3228 assertMatrixEquals (matrix , result .getL ());
@@ -36,32 +32,27 @@ void testIdentityMatrix() {
3632 @ Test
3733 void testSingularMatrix () {
3834 double [][] matrix = {{1 , 2 , 3 }, {4 , 5 , 6 }, {7 , 8 , 9 }};
39-
4035 assertThrows (IllegalArgumentException .class , () -> LUDecomposition .decompose (matrix ));
4136 }
4237
4338 @ Test
4439 void testEmptyMatrix () {
4540 double [][] matrix = {};
46-
4741 assertThrows (IllegalArgumentException .class , () -> LUDecomposition .decompose (matrix ));
4842 }
4943
5044 @ Test
5145 void testNonSquareMatrix () {
5246 double [][] matrix = {{1 , 2 , 3 }, {4 , 5 , 6 }};
53-
5447 assertThrows (IllegalArgumentException .class , () -> LUDecomposition .decompose (matrix ));
5548 }
5649
5750 @ Test
5851 void testTwoByTwoMatrix () {
5952 double [][] matrix = {{4 , 3 }, {6 , 3 }};
60-
6153 LUDecomposition .Result result = LUDecomposition .decompose (matrix );
6254
6355 double [][] expectedL = {{1.0 , 0.0 }, {1.5 , 1.0 }};
64-
6556 double [][] expectedU = {{4.0 , 3.0 }, {0.0 , -1.5 }};
6657
6758 assertMatrixEquals (expectedL , result .getL ());
0 commit comments