Browse Source

The funktionality Linked Matricies Check

featureMatrixCalculator
Lukas Reichwein 5 years ago
parent
commit
f9891c392a
  1. 8
      src/main/java/com/ugsbo/matrixcalc/MatrixCalcMath.java
  2. 31
      src/test/java/com/ugsbo/matrixcalc/MatrixMultiplicationTest.java

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

@ -27,8 +27,16 @@ public class MatrixCalcMath {
*/
public boolean checkIfMatriciesAreLinked(Double[][] matrixA, Double[][] matrixB) {
// TODO Check if the number of Rows of Matrix A equal to the coulums of Matrix B
if (matrixA != null) {
if (matrixA[0].length == matrixB.length) {
return true;
} else {
return false;
}
} else {
return false;
}
}
/**
* Adds two matroices A and B. Adding matrix A to matrix B is the same as adding

31
src/test/java/com/ugsbo/matrixcalc/MatrixMultiplicationTest.java

@ -1,5 +1,6 @@
package com.ugsbo.matrixcalc;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
@ -8,12 +9,30 @@ import org.junit.Test;
* Testet die Matrix Multiplication funkionalität
*/
public class MatrixMultiplicationTest {
/**
* This Test only tests that the assertTrue funktion works like expected.
*/
@Test
public void MatrixAIsLinkedToMatrixBSouldBeTrue() {
MatrixCalcMath math = new MatrixCalcMath();
Double[][] matrixA = new Double[1][2];
Double[][] matrixB = new Double[2][1];
assertTrue("Matrix A is Linked to B but it is not detected that way",
math.checkIfMatriciesAreLinked(matrixA, matrixB));
}
@Test
public void MatrixAAndMatrixBAreNullSouldReturnFalse() {
MatrixCalcMath math = new MatrixCalcMath();
Double[][] matrixA = null;
Double[][] matrixB = null;
assertFalse("Matrix A and B are null but detected as Linked", math.checkIfMatriciesAreLinked(matrixA, matrixB));
}
@Test
public void shouldAlwaysBeTrue() {
//TODO replace this test through a real one!!
assertTrue("The JUnit setup is not correct, this test only assertTrue.", true);
public void MatrixAAndMatrixBAreNotLinkedSouldReturnFalse() {
MatrixCalcMath math = new MatrixCalcMath();
Double[][] matrixA = new Double[1][1];
Double[][] matrixB = new Double[2][1];
assertFalse("Matrix A and B are not Linked but detected as Linked",
math.checkIfMatriciesAreLinked(matrixA, matrixB));
}
}
Loading…
Cancel
Save