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.

61 lines
1.8 KiB

  1. package com.ugsbo.matrixcalc;
  2. import static org.junit.Assert.assertEquals;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. /**
  6. * Tests the funktionality to Calculate the Determinant of a Matrix.
  7. */
  8. public class MatrixCalcDeterminatTest {
  9. private MatrixCalcMath matrixMath;
  10. @Before
  11. public void setup() {
  12. matrixMath = new MatrixCalcMath();
  13. }
  14. @Test
  15. public void CalculatesTheDeterminanteOfA2by2Matrix() {
  16. // A(2,2)
  17. double[][] matrixA = { { 1.0, 2.0 }, { 3.0, 4.0 } };
  18. double determinat = -2.0;
  19. double delta = 0.01;
  20. double result = matrixMath.calcDeterminat(matrixA);
  21. assertEquals("The Determinant is not as it should be", determinat, result, delta);
  22. }
  23. @Test
  24. public void CalculatesTheDeterminanteOfA3by3Matrix() {
  25. // A(3,3)
  26. double[][] matrixA = { { 1.0, 2.0, 1.0 }, { 3.0, 4.0, 0.0 }, { 5.0, 6.0, 0.0 } };
  27. double determinat = -2.0;
  28. double delta = 0.01;
  29. double result = matrixMath.calcDeterminat(matrixA);
  30. assertEquals("The Determinant is not as it should be", determinat, result, delta);
  31. }
  32. @Test(expected = IllegalArgumentException.class)
  33. public void tryToCalculateA4by4Matrix_ShouldResulInIllegalArgumentException() {
  34. // A(4,4)
  35. 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 },
  36. { 5.0, 6.0, 0.0, 0.0 } };
  37. matrixMath.calcDeterminat(matrixA);
  38. }
  39. @Test(expected = IllegalArgumentException.class)
  40. public void tryToCalculateANonQuadraticMatrix_SouldResulInIllegalArgumentException() {
  41. // A(2,4)
  42. double[][] matrixA = { { 5.0, 6.0, 0.0, 0.0 }, { 5.0, 6.0, 0.0, 0.0 } };
  43. matrixMath.calcDeterminat(matrixA);
  44. }
  45. }