Lukas Reichwein
6 years ago
2 changed files with 117 additions and 13 deletions
-
85src/main/java/com/ugsbo/matrixcalc/MatrixCalcMath.java
-
45src/test/java/com/ugsbo/matrixcalc/MatrixCalcDeterminatTest.java
@ -0,0 +1,45 @@ |
|||
package com.ugsbo.matrixcalc; |
|||
|
|||
import static org.junit.Assert.assertEquals; |
|||
|
|||
import org.junit.Test; |
|||
|
|||
/** |
|||
* Tests the funktionality to Calculate the Determinant of a Matrix. |
|||
*/ |
|||
public class MatrixCalcDeterminatTest { |
|||
|
|||
@Test |
|||
public void CalculatesTheDeterminanteOfA2by2Matrix() { |
|||
MatrixCalcMath math = new MatrixCalcMath(); |
|||
// A(2,2) |
|||
double[][] matrixA = { { 1.0, 2.0 }, { 3.0, 4.0 } }; |
|||
double determinat = -2.0; |
|||
|
|||
double result = math.calcDeterminat(matrixA); |
|||
|
|||
assertEquals("The Determinant is not as it should be", determinat, result, 0.01); |
|||
} |
|||
|
|||
@Test |
|||
public void CalculatesTheDeterminanteOfA3by3Matrix() { |
|||
MatrixCalcMath math = new MatrixCalcMath(); |
|||
// A(3,3) |
|||
double[][] matrixA = { { 1.0, 2.0, 1.0 }, { 3.0, 4.0, 0.0 }, {5.0, 6.0, 0.0} }; |
|||
double determinat = -2.0; |
|||
double result = math.calcDeterminat(matrixA); |
|||
|
|||
assertEquals("The Determinant is not as it should be", determinat, result, 0.01); |
|||
|
|||
|
|||
} |
|||
|
|||
@Test(expected = IllegalArgumentException.class) |
|||
public void tryToCalculateA4by4MatrixSouldResulInIllegalArgumentException() { |
|||
MatrixCalcMath math = new MatrixCalcMath(); |
|||
// A(4,4) |
|||
double[][] matrixA = { { 1.0, 2.0, 1.0, 0.0 }, { 3.0, 4.0, 0.0, 0.0 }, {5.0, 6.0, 0.0, 0.0}, {5.0, 6.0, 0.0, 0.0} }; |
|||
|
|||
math.calcDeterminat(matrixA); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue