Browse Source

Added and changed some Documentaion

featureMatrixCalculator
Lukas Reichwein 5 years ago
parent
commit
05c259c0d1
  1. 7
      src/main/java/com/ugsbo/matrixcalc/MatrixCalcController.java
  2. 31
      src/main/java/com/ugsbo/matrixcalc/MatrixCalcMath.java
  3. 9
      src/test/java/com/ugsbo/matrixcalc/MatrixCalcDeterminatTest.java

7
src/main/java/com/ugsbo/matrixcalc/MatrixCalcController.java

@ -42,6 +42,13 @@ public class MatrixCalcController {
});
}
/**
* Chcks if the Input is Valid, with Regex. Returns true if the Matrix can be
* matched by the regular Expression.
*
* @param matrix It is the InputMatrix
* @return true if the Matrix is valid Input.
*/
public boolean checkInput(String matrix) {
boolean isMatched = false;
if (matrix.length() == 0) {

31
src/main/java/com/ugsbo/matrixcalc/MatrixCalcMath.java

@ -1,7 +1,5 @@
package com.ugsbo.matrixcalc;
//import java.io.IOException;
/**
* Contains all basic matrix math calculations.
*/
@ -132,10 +130,10 @@ public class MatrixCalcMath {
if (matrixA == null) {
throw new IllegalArgumentException("Matricies need to have the same Dimensions");
}
if (matrixA.length == 0){
if (matrixA.length == 0) {
throw new IllegalArgumentException("Matricies need to have the same Dimensions");
}
if(matrixA[0] == null){
if (matrixA[0] == null) {
throw new IllegalArgumentException("Matricies need to have the same Dimensions");
}
int columCountResult = matrixA.length;
@ -174,6 +172,12 @@ public class MatrixCalcMath {
return result;
}
/**
* Calculates the Determinat of an three by three Matrix.
*
* @param matrixA The Inputmatrix form wich the Determinat will be calculated
* @return the Determinant of the Matrix
*/
private double calc3by3Determinant(double[][] matrixA) {
double result = matrixA[0][0] * matrixA[1][1] * matrixA[2][2] + matrixA[0][1] * matrixA[1][2] * matrixA[2][0]
+ matrixA[0][2] * matrixA[1][0] * matrixA[2][1] - matrixA[0][0] * matrixA[1][2] * matrixA[2][1]
@ -181,15 +185,34 @@ public class MatrixCalcMath {
return result;
}
/**
* Calculates the Determinat of an two by two Matrix.
*
* @param matrixA The Inputmatrix form wich the Determinat will be calculated
* @return the Determinant of the Matrix
*/
private double calc2by2Determinant(double[][] matrixA) {
double result = matrixA[0][0] * matrixA[1][1] - matrixA[0][1] * matrixA[1][0];
return result;
}
/**
* Returns the Number of rows of a Matrix.
*
* @param matrixA the Inputmatrix form wich the rows will be counted
* @return Number of rows
*/
private int getMatrixRowCount(double[][] matrixA) {
return matrixA.length;
}
/**
* Checks if the rows and colums of an Matrix are equal. If they are equal the
* Matrix is Quadratic and the function will return true.
*
* @param matrixA the Inputmatrix for wich the rows and colums will be compared
* @return isQuadratic
*/
private boolean checkIfMatrixIsQuadradtic(double[][] matrixA) {
if (matrixA == null) {
return false;

9
src/test/java/com/ugsbo/matrixcalc/MatrixCalcDeterminatTest.java

@ -42,4 +42,13 @@ public class MatrixCalcDeterminatTest {
math.calcDeterminat(matrixA);
}
@Test(expected = IllegalArgumentException.class)
public void tryToCalculateANonQuadraticMatrixSouldResulInIllegalArgumentException() {
MatrixCalcMath math = new MatrixCalcMath();
// A(2,4)
double[][] matrixA = {{5.0, 6.0, 0.0, 0.0}, {5.0, 6.0, 0.0, 0.0} };
math.calcDeterminat(matrixA);
}
}
Loading…
Cancel
Save