import static org.junit.jupiter.api.Assertions.assertArrayEquals; import org.junit.jupiter.api.Test; public class Es4 { static int[][] copiaMatrice(int[][] m) { int[][] r = new int[m.length][]; for (int i = 0; i < m.length; i++) { r[i] = new int[m[i].length]; for (int j = 0; j < m[i].length; j++) { r[i][j] = m[i][j]; } } return r; } @Test void test1() { int[] l = {1, 2, 0}; int[][] m = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; Es3.raddoppia(l, m); assertArrayEquals(new int[][] {{1, 4, 3}, {4, 5, 12}, {14, 8, 9}},m); } @Test void test2() { int[][] m = new int[3][3]; for (int i = 0; i < m.length; i++) { for (int j = 0; j < m[i].length; j++) { m[i][j] = (int)(Math.random() * 10); } } int[][] expected = copiaMatrice(m); Es3.raddoppia(new int[]{0,0,0}, m); for (int i = 0; i < expected.length; i++) { expected[i][0] *= 2; } assertArrayEquals(expected, m); } }