mirror of
https://bitbucket.org/Mattrixwv/matrix.git
synced 2025-12-06 23:13:57 -05:00
Fixed bugs found during unit testing
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
//Matrix/src/main/java/com/mattrixwv/IntegerMatrix.java
|
//Matrix/src/main/java/com/mattrixwv/IntegerMatrix.java
|
||||||
//Mattrixwv
|
//Mattrixwv
|
||||||
// Created: 02-01-22
|
// Created: 02-01-22
|
||||||
//Modified: 02-07-22
|
//Modified: 02-08-22
|
||||||
package com.mattrixwv.matrix;
|
package com.mattrixwv.matrix;
|
||||||
|
|
||||||
|
|
||||||
@@ -167,7 +167,12 @@ public class IntegerMatrix{
|
|||||||
return new IntegerMatrix(newRow);
|
return new IntegerMatrix(newRow);
|
||||||
}
|
}
|
||||||
public int getNumRows(){
|
public int getNumRows(){
|
||||||
return grid.length;
|
if(grid == null){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return grid.length;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public IntegerMatrix getCol(int col){
|
public IntegerMatrix getCol(int col){
|
||||||
//Make sure the column number is valid
|
//Make sure the column number is valid
|
||||||
@@ -693,7 +698,7 @@ public class IntegerMatrix{
|
|||||||
int[][] newGrid = new int[getNumRows()][getNumCols()];
|
int[][] newGrid = new int[getNumRows()][getNumCols()];
|
||||||
//If the grid is 1x1 return the grid
|
//If the grid is 1x1 return the grid
|
||||||
if(getNumRows() == 1){
|
if(getNumRows() == 1){
|
||||||
newGrid[0][0] = grid[0][0];
|
newGrid[0][0] = 1;
|
||||||
}
|
}
|
||||||
//Use the formula to find the cofactor matrix
|
//Use the formula to find the cofactor matrix
|
||||||
else{
|
else{
|
||||||
@@ -738,7 +743,7 @@ public class IntegerMatrix{
|
|||||||
IntegerMatrix rightMatrix = (IntegerMatrix)rightSide;
|
IntegerMatrix rightMatrix = (IntegerMatrix)rightSide;
|
||||||
|
|
||||||
//Make sure they have the same number of elements
|
//Make sure they have the same number of elements
|
||||||
if(grid.length != rightMatrix.grid.length){
|
if(getNumRows() != rightMatrix.getNumRows()){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if(getNumCols() != rightMatrix.getNumCols()){
|
else if(getNumCols() != rightMatrix.getNumCols()){
|
||||||
@@ -746,8 +751,8 @@ public class IntegerMatrix{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Check every element
|
//Check every element
|
||||||
for(int row = 0;row < grid.length;++row){
|
for(int row = 0;row < getNumRows();++row){
|
||||||
for(int col = 0;col < grid[0].length;++col){
|
for(int col = 0;col < getNumCols();++col){
|
||||||
if(grid[row][col] != rightMatrix.grid[row][col]){
|
if(grid[row][col] != rightMatrix.grid[row][col]){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -773,10 +778,10 @@ public class IntegerMatrix{
|
|||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
StringJoiner matrix = new StringJoiner("\n");
|
StringJoiner matrix = new StringJoiner("\n");
|
||||||
for(int rowCnt = 0;rowCnt < grid.length;++rowCnt){
|
for(int rowCnt = 0;rowCnt < getNumRows();++rowCnt){
|
||||||
StringJoiner row = new StringJoiner(",", "[", "]");
|
StringJoiner row = new StringJoiner(",", "[", "]");
|
||||||
|
|
||||||
for(int colCnt = 0;colCnt < grid[0].length;++colCnt){
|
for(int colCnt = 0;colCnt < getNumCols();++colCnt){
|
||||||
row.add(Integer.toString(grid[rowCnt][colCnt]));
|
row.add(Integer.toString(grid[rowCnt][colCnt]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user