-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathMatrixExampleTest.java
More file actions
81 lines (73 loc) · 2.21 KB
/
MatrixExampleTest.java
File metadata and controls
81 lines (73 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
public class MatrixExampleTest {
public void testMultiplyMatrices_CorrectMultiplication() {
int[][] matrix1 = {
{1, 2},
{3, 4}
};
int[][] matrix2 = {
{5, 6},
{7, 8}
};
int[][] expected = {
{19, 22},
{43, 50}
};
int[][] result = MatrixExample.multiplyMatrices(matrix1, matrix2);
System.out.println(expected == result);
}
public void testMultiplyMatrices_IdentityMatrix() {
int[][] matrix1 = {
{1, 0},
{0, 1}
};
int[][] matrix2 = {
{9, 8},
{7, 6}
};
int[][] expected = {
{9, 8},
{7, 6}
};
int[][] result = MatrixExample.multiplyMatrices(matrix1, matrix2);
System.out.println(expected == result);
}
public void testMultiplyMatrices_RectangularMatrices() {
int[][] matrix1 = {
{2, 3, 4},
{1, 0, 0}
};
int[][] matrix2 = {
{0, 1000},
{1, 100},
{0, 10}
};
int[][] expected = {
{3, 2340},
{0, 1000}
};
int[][] result = MatrixExample.multiplyMatrices(matrix1, matrix2);
System.out.println(expected == result);
}
public void testGenerateRandomMatrix_SizeAndRange() {
int numRows = 5;
int numCols = 4;
int[][] matrix = MatrixExample.generateRandomMatrix(numRows, numCols);
System.out.println(numRows == matrix.length);
for (int[] row : matrix) {
System.out.println(numCols == row.length);
for (int val : row) {
System.out.println(val >= 0 && val < 100);
}
}
}
public void testGenerateRandomMatrix_DifferentSizes() {
int[][] matrix = MatrixExample.generateRandomMatrix(1, 1);
System.out.println(matrix[0][0]);
matrix = MatrixExample.generateRandomMatrix(3, 2);
System.out.println(matrix.toString());
}
public void testGenerateRandomMatrix_ZeroSize() {
int[][] matrix = MatrixExample.generateRandomMatrix(0, 0);
System.out.println(matrix.length);
}
}