Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions MatrixExampleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}
}