-
Notifications
You must be signed in to change notification settings - Fork 20.1k
Closed
Description
The matrix class and the tests written for it only support shallow comparison. In other words, comparisons only verify whether two matrices have the same reference rather than actually comparing each element in the matrix.
int[][] data = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 } };
int[][] zeroData = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
Matrix matrix = new Matrix(data);
Matrix zeroMatrix = new Matrix(zeroData);
System.out.println(matrix);
System.out.println(matrix.plus(zeroMatrix));
System.out.println(matrix.equals(matrix.plus(zeroMatrix)));
The above equality should equate to true
, since a matrix plus the zero matrix is itself (identity property of matrix addition), but instead, it equates to false
. Deep comparison is necessary, in the same way a deep copy of the data is made in the matrix constructor.
Metadata
Metadata
Assignees
Labels
No labels