From 05c259c0d18e62cd5923e2686d04475ce7a9e35a Mon Sep 17 00:00:00 2001 From: Lukas Reichwein Date: Tue, 9 Jul 2019 16:39:02 +0200 Subject: [PATCH] Added and changed some Documentaion --- .../matrixcalc/MatrixCalcController.java | 7 +++++ .../com/ugsbo/matrixcalc/MatrixCalcMath.java | 31 ++++++++++++++++--- .../matrixcalc/MatrixCalcDeterminatTest.java | 9 ++++++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ugsbo/matrixcalc/MatrixCalcController.java b/src/main/java/com/ugsbo/matrixcalc/MatrixCalcController.java index 3dd8596..3b93482 100644 --- a/src/main/java/com/ugsbo/matrixcalc/MatrixCalcController.java +++ b/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) { diff --git a/src/main/java/com/ugsbo/matrixcalc/MatrixCalcMath.java b/src/main/java/com/ugsbo/matrixcalc/MatrixCalcMath.java index 5c1728d..78ef29e 100644 --- a/src/main/java/com/ugsbo/matrixcalc/MatrixCalcMath.java +++ b/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; diff --git a/src/test/java/com/ugsbo/matrixcalc/MatrixCalcDeterminatTest.java b/src/test/java/com/ugsbo/matrixcalc/MatrixCalcDeterminatTest.java index 5a12760..a40ff64 100644 --- a/src/test/java/com/ugsbo/matrixcalc/MatrixCalcDeterminatTest.java +++ b/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); + } } \ No newline at end of file