package testMatrix;
public class MatrixAdd {
public int [][] addtionOfArray(int [][] numbers){
int length = numbers.length;
int output[][] = new int[length][length];
for(int i=0; i< length; i++){
for(int j=0; i< length; j++){
output[i][j] = numbers[i][j] + numbers[i][j];
}
}
return output;
}
}
How to write Junit test for array matrix addition? and also Junit test for matrix multiplication
in the test
source set you can use something similar
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class MatrixAddTest {
private MatrixAdd testee = MatrixAdd();
@Test
public void testAdditionOfArray(){
int[][] expected = new int[][]{new int[]{2, 0}, new int[]{0, 2}};
int[][] actual = testee.addtionOfArray(new int[][]{new int[]{1, 0}, new int[]{0, 1}});
Assertions.assertEquals(expected, actual);
}
}
however, since MatrixAdd seems like a Utility class, you could also make the methods static, you don't really need a MatrixAdd instance anywhere.