Ultra Geile Studenten Benutzer Oberfläche (UGSBO)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.4 KiB

  1. package com.ugsbo.matrixcalc;
  2. import static org.junit.Assert.assertEquals;
  3. import org.junit.Test;
  4. /**
  5. * Tests the funktionality to Calculate the Determinant of a Matrix.
  6. */
  7. public class MatrixCalcDeterminatTest {
  8. @Test
  9. public void CalculatesTheDeterminanteOfA2by2Matrix() {
  10. MatrixCalcMath math = new MatrixCalcMath();
  11. // A(2,2)
  12. double[][] matrixA = { { 1.0, 2.0 }, { 3.0, 4.0 } };
  13. double determinat = -2.0;
  14. double result = math.calcDeterminat(matrixA);
  15. assertEquals("The Determinant is not as it should be", determinat, result, 0.01);
  16. }
  17. @Test
  18. public void CalculatesTheDeterminanteOfA3by3Matrix() {
  19. MatrixCalcMath math = new MatrixCalcMath();
  20. // A(3,3)
  21. double[][] matrixA = { { 1.0, 2.0, 1.0 }, { 3.0, 4.0, 0.0 }, {5.0, 6.0, 0.0} };
  22. double determinat = -2.0;
  23. double result = math.calcDeterminat(matrixA);
  24. assertEquals("The Determinant is not as it should be", determinat, result, 0.01);
  25. }
  26. @Test(expected = IllegalArgumentException.class)
  27. public void tryToCalculateA4by4MatrixSouldResulInIllegalArgumentException() {
  28. MatrixCalcMath math = new MatrixCalcMath();
  29. // A(4,4)
  30. double[][] matrixA = { { 1.0, 2.0, 1.0, 0.0 }, { 3.0, 4.0, 0.0, 0.0 }, {5.0, 6.0, 0.0, 0.0}, {5.0, 6.0, 0.0, 0.0} };
  31. math.calcDeterminat(matrixA);
  32. }
  33. }