Create SetMatrixToZeroUnitTest.java

This commit is contained in:
anujgaud 2024-03-16 23:32:11 +05:30 committed by GitHub
parent 2922f0619f
commit f88022796a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,53 @@
package com.baeldung.matrixtozero;
import org.junit.Test;
public class SetMatrixToZeroUnitTest{
@Test
void givenMatrix_whenUsingBruteForce_thenSetZeroes() {
int[][] matrix = {
{1, 2, 3},
{4, 0, 6},
{7, 8, 9}
};
int[][] expected = {
{1, 0, 3},
{0, 0, 0},
{7, 0, 9}
};
SetMatrixToZero.setZeroesBruteForce(matrix);
assertArrayEquals(expected, matrix);
}
@Test
void givenMatrix_whenUsingExtraSpace_thenSetZeroes() {
int[][] matrix = {
{1, 2, 3},
{4, 0, 6},
{7, 8, 9}
};
int[][] expected = {
{1, 0, 3},
{0, 0, 0},
{7, 0, 9}
};
SetMatrixToZero.setZeroesExtraSpace(matrix);
assertArrayEquals(expected, matrix);
}
@Test
void givenMatrix_whenUsingOptimized_thenSetZeroes() {
int[][] matrix = {
{1, 2, 3},
{4, 0, 6},
{7, 8, 9}
};
int[][] expected = {
{1, 0, 3},
{0, 0, 0},
{7, 0, 9}
};
SetMatrixToZero.setZeroesOptimized(matrix);
assertArrayEquals(expected, matrix);
}
}