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.

57 lines
1.9 KiB

  1. package com.ugsbo.matrixcalc;
  2. import static org.junit.Assert.assertArrayEquals;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. /**
  6. * Tests the funktionality to Transpose a Matix
  7. */
  8. public class MatrixTransposeTest {
  9. private MatrixCalcMath matrixMath;
  10. @Before
  11. public void setup() {
  12. matrixMath = new MatrixCalcMath();
  13. }
  14. @Test
  15. public void TransformQuadraticMatrixA_ResultsInQuadraticMatrixC() {
  16. // A(2,2) => C(2,2)
  17. double[][] matrixA = { { 1.0, 2.0 }, { 3.0, 4.0 } };
  18. double[][] matrixC = { { 1.0, 3.0 }, { 2.0, 4.0 } };
  19. double[][] result = matrixMath.matrixTransponation(matrixA);
  20. assertArrayEquals("The first row is not correct", matrixC[0], result[0], 0.1);
  21. assertArrayEquals("The second row is not correct", matrixC[1], result[1], 0.1);
  22. }
  23. @Test
  24. public void Transform2by3MatrixA_ResultsIn3by2MatrixC() {
  25. // A(2,3) => C(3,2)
  26. double[][] matrixA = { { 1.0, 2.0, 3.0 }, { 4.0, 5.0, 6.0 } };
  27. double[][] matrixC = { { 1.0, 4.0 }, { 2.0, 5.0 }, { 3.0, 6.0 } };
  28. double[][] result = matrixMath.matrixTransponation(matrixA);
  29. assertArrayEquals("The first row is not correct", matrixC[0], result[0], 0.1);
  30. assertArrayEquals("The second row is not correct", matrixC[1], result[1], 0.1);
  31. assertArrayEquals("The third row is not correct", matrixC[2], result[2], 0.1);
  32. }
  33. @Test
  34. public void Transform1by3MatrixA_ResultsIn3by1MatrixC() {
  35. // A(1,3) => C(1,3)
  36. double[][] matrixA = { { 1.0, 2.0, 3.0 } };
  37. double[][] matrixC = { { 1.0 }, { 2.0 }, { 3.0 } };
  38. double[][] result = matrixMath.matrixTransponation(matrixA);
  39. assertArrayEquals("The first row is not correct", matrixC[0], result[0], 0.1);
  40. assertArrayEquals("The second row is not correct", matrixC[1], result[1], 0.1);
  41. assertArrayEquals("The third row is not correct", matrixC[2], result[2], 0.1);
  42. }
  43. }