Пример #1
0
 @Test
 public void testAddShouldPass() throws Exception {
   Matrix a = new Matrix(new double[][] {{1, 2, 3}, {3, 2, 1}, {2, 1, 3}});
   Matrix b = new Matrix(new double[][] {{1, 2, 3}, {3, 2, 1}, {2, 1, 3}});
   Matrix c = a.add(b);
   Matrix r = new Matrix(new double[][] {{2, 4, 6}, {6, 4, 2}, {4, 2, 6}});
   for (int i = 0; i < c.getNumRows(); i++) {
     for (int j = 0; j < c.getNumColumns(); j++) {
       assertEquals(r.getElement(i, j), c.getElement(i, j), 0);
     }
   }
 }
Пример #2
0
  @Test
  public void addTwoMatrix() {
    int row = 2, column = 2;
    int[] firstArrayInput = {1, 2, 3, 4};
    int[] secondArrayInput = {2, 3, 4, 5};
    int[] expectedOutput = {3, 5, 7, 9};

    Matrix firstMatrix = new Matrix(row, column);
    Matrix secondMatrix = new Matrix(row, column);
    Matrix expectedMatrix = new Matrix(row, column);

    firstMatrix.populate(firstArrayInput);
    secondMatrix.populate(secondArrayInput);
    expectedMatrix.populate(expectedOutput);
    Matrix destinationMatrix = firstMatrix.add(secondMatrix);

    assertArrayEquals(destinationMatrix.matrix, expectedMatrix.matrix);
  }