Browse Source

Added and chnged tests in order to test Exceptions instead of if the funktion is returning null

featureMatrixCalculator
Lukas Reichwein 6 years ago
parent
commit
e57a53d6d0
  1. 71
      src/test/java/com/ugsbo/matrixcalc/MatrixAdditionAndSubstractionTest.java
  2. 28
      src/test/java/com/ugsbo/matrixcalc/MatrixMultiplicationTest.java
  3. 8
      src/test/java/com/ugsbo/matrixcalc/MatrixTransposeTest.java

71
src/test/java/com/ugsbo/matrixcalc/MatrixAdditionAndSubstractionTest.java

@ -43,7 +43,7 @@ public class MatrixAdditionAndSubstractionTest {
double[][] result = math.matrixAddition(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);
assertArrayEquals("The second row is not correct", matrixC[1], result[1], 0.1);
}
@Test
@ -56,7 +56,37 @@ public class MatrixAdditionAndSubstractionTest {
double[][] result = math.matrixAddition(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);
assertArrayEquals("The second row is not correct", matrixC[1], result[1], 0.1);
}
@Test(expected = IllegalArgumentException.class)
public void tryToAddTowEmptyMatricies() {
MatrixCalcMath math = new MatrixCalcMath();
// A(0,0) B(0,0) => IllegalArgumentException
double[][] matrixA = new double[0][0];
double[][] matrixB = new double[0][0];
math.matrixAddition(matrixA, matrixB);
}
@Test(expected = IllegalArgumentException.class)
public void tryToAddTowNullMatrices() {
MatrixCalcMath math = new MatrixCalcMath();
// A(0,0) B(0,0) => IllegalArgumentException
double[][] matrixA = null;
double[][] matrixB = null;
math.matrixAddition(matrixA, matrixB);
}
@Test(expected = IllegalArgumentException.class)
public void tryToAddTowMatricesWithDifferentDimensions() {
MatrixCalcMath math = new MatrixCalcMath();
// A(0,0) B(0,0) => IllegalArgumentException
double[][] matrixA = {{1.0, 2.0}};
double[][] matrixB = {{1.0}, {2.0}};
math.matrixAddition(matrixA, matrixB);
}
@Test
@ -69,7 +99,7 @@ public class MatrixAdditionAndSubstractionTest {
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);
assertArrayEquals("The second row is not correct", matrixC[1], result[1], 0.1);
}
@Test
@ -82,7 +112,7 @@ public class MatrixAdditionAndSubstractionTest {
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);
assertArrayEquals("The second row is not correct", matrixC[1], result[1], 0.1);
}
@Test
@ -95,6 +125,37 @@ public class MatrixAdditionAndSubstractionTest {
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);
assertArrayEquals("The second row is not correct", matrixC[1], result[1], 0.1);
}
@Test(expected = IllegalArgumentException.class)
public void tryToSubstractTowEmptyMatricies() {
MatrixCalcMath math = new MatrixCalcMath();
// A(0,0) B(0,0) => IllegalArgumentException
double[][] matrixA = new double[0][0];
double[][] matrixB = new double[0][0];
math.matrixSubstraction(matrixA, matrixB);
}
@Test(expected = IllegalArgumentException.class)
public void tryToSubstractTowNullMatrices() {
MatrixCalcMath math = new MatrixCalcMath();
// A(0,0) B(0,0) => IllegalArgumentException
double[][] matrixA = null;
double[][] matrixB = null;
math.matrixSubstraction(matrixA, matrixB);
}
@Test(expected = IllegalArgumentException.class)
public void tryToSubstractTowMatricesWithDifferentDimensions() {
MatrixCalcMath math = new MatrixCalcMath();
// A(0,0) B(0,0) => IllegalArgumentException
double[][] matrixA = {{1.0, 2.0}};
double[][] matrixB = {{1.0}, {2.0}};
math.matrixSubstraction(matrixA, matrixB);
}
}

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

@ -54,7 +54,7 @@ public class MatrixMultiplicationTest {
double[][] result = math.matrixMultiplication(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);
assertArrayEquals("The second row is not correct", matrixC[1], result[1], 0.1);
}
@Test
@ -68,7 +68,7 @@ public class MatrixMultiplicationTest {
double[][] result = math.matrixMultiplication(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);
assertArrayEquals("The second row is not correct", matrixC[1], result[1], 0.1);
}
@Test
@ -82,30 +82,28 @@ public class MatrixMultiplicationTest {
double[][] result = math.matrixMultiplication(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);
assertArrayEquals("The second row is not correct", matrixC[1], result[1], 0.1);
}
@Test
@Test(expected = IllegalArgumentException.class)
public void tryToMultiplyTowEmptyMatricies() {
MatrixCalcMath math = new MatrixCalcMath();
// A(0,0) B(0,0) => null
// A(0,0) B(0,0) => IllegalArgumentException
double[][] matrixA = new double[0][0];
double[][] matrixB = new double[0][0];
double[][] result = math.matrixMultiplication(matrixA, matrixB);
assertArrayEquals(null, result);
math.matrixMultiplication(matrixA, matrixB);
}
@Test
@Test(expected = IllegalArgumentException.class)
public void tryToMultiplyTowNullObjects() {
MatrixCalcMath math = new MatrixCalcMath();
// null null => null
// null null => IllegalArgumentException
double[][] matrixA = null;
double[][] matrixB = null;
double[][] result = math.matrixMultiplication(matrixA, matrixB);
assertArrayEquals(null, result);
math.matrixMultiplication(matrixA, matrixB);
}
}

8
src/test/java/com/ugsbo/matrixcalc/MatrixTransposeTest.java

@ -19,7 +19,7 @@ public class MatrixTransposeTest {
double[][] result = math.matrixTransponation(matrixA);
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);
assertArrayEquals("The second row is not correct", matrixC[1], result[1], 0.1);
}
@Test
@ -32,7 +32,8 @@ public class MatrixTransposeTest {
double[][] result = math.matrixTransponation(matrixA);
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);
assertArrayEquals("The second row is not correct", matrixC[1], result[1], 0.1);
assertArrayEquals("The third row is not correct", matrixC[2], result[2], 0.1);
}
@Test
@ -45,6 +46,7 @@ public class MatrixTransposeTest {
double[][] result = math.matrixTransponation(matrixA);
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);
assertArrayEquals("The second row is not correct", matrixC[1], result[1], 0.1);
assertArrayEquals("The third row is not correct", matrixC[2], result[2], 0.1);
}
}
Loading…
Cancel
Save