|
|
@ -7,9 +7,9 @@ import static org.junit.Assert.assertTrue; |
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
/** |
|
|
|
* Tests the funktionality to add two matricies |
|
|
|
* Tests the funktionality to add and substract two matricies |
|
|
|
*/ |
|
|
|
public class MatrixAdditionTest { |
|
|
|
public class MatrixAdditionAndSubstractionTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
public void twoMatriciesHaveTheSameDimensions() { |
|
|
@ -58,4 +58,43 @@ public class MatrixAdditionTest { |
|
|
|
assertArrayEquals("The first row is not correct", matrixC[0], result[0], 0.1); |
|
|
|
assertArrayEquals("The seound row is not correct", matrixC[1], result[1], 0.1); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void substractTwoMatriciesWithSameContent() { |
|
|
|
MatrixCalcMath math = new MatrixCalcMath(); |
|
|
|
double[][] matrixA = { { 1.0, 1.0 }, { 1.0, 1.0 } }; |
|
|
|
double[][] matrixB = { { 1.0, 1.0 }, { 1.0, 1.0 } }; |
|
|
|
double[][] matrixC = { { 0.0, 0.0 }, { 0.0, 0.0 } }; |
|
|
|
|
|
|
|
double[][] result = math.matrixSubstraction(matrixA, matrixB); |
|
|
|
|
|
|
|
assertArrayEquals("The first row is not correct", matrixC[0], result[0], 0.1); |
|
|
|
assertArrayEquals("The seound row is not correct", matrixC[1], result[1], 0.1); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void substractTwoMatriciesWithDiffrentContent() { |
|
|
|
MatrixCalcMath math = new MatrixCalcMath(); |
|
|
|
double[][] matrixA = { { 1.0, 2.0 }, { 3.0, 4.0 } }; |
|
|
|
double[][] matrixB = { { 5.0, 6.0 }, { 7.0, 8.0 } }; |
|
|
|
double[][] matrixC = { { -4.0, -4.0 }, { -4.0, -4.0 } }; |
|
|
|
|
|
|
|
double[][] result = math.matrixSubstraction(matrixA, matrixB); |
|
|
|
|
|
|
|
assertArrayEquals("The first row is not correct", matrixC[0], result[0], 0.1); |
|
|
|
assertArrayEquals("The seound row is not correct", matrixC[1], result[1], 0.1); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void substractTwoMatriciesWithNegativeContent() { |
|
|
|
MatrixCalcMath math = new MatrixCalcMath(); |
|
|
|
double[][] matrixA = { { -1.0, -2.0 }, { -3.0, -4.0 } }; |
|
|
|
double[][] matrixB = { { 5.0, 6.0 }, { 7.0, 8.0 } }; |
|
|
|
double[][] matrixC = { { -6.0, -8.0 }, { -10.0, -12.0 } }; |
|
|
|
|
|
|
|
double[][] result = math.matrixSubstraction(matrixA, matrixB); |
|
|
|
|
|
|
|
assertArrayEquals("The first row is not correct", matrixC[0], result[0], 0.1); |
|
|
|
assertArrayEquals("The seound row is not correct", matrixC[1], result[1], 0.1); |
|
|
|
} |
|
|
|
} |