Add RandomizedMatrixVerifier and test class #6305
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New Feature: Randomized Matrix Equality Verifier
This pull request introduces a new utility class called RandomizedMatrixVerifier in the matrix package.
It provides an efficient method areMatricesEqual(int[][] a, int[][] b) that determines whether two matrices are equal using randomized hashing with prime coefficients.
This approach ensures performance and robustness, especially for large matrices.
Tests Added:-
A corresponding test class RandomizedMatrixVerifierTest is added under src/test/java/com/thealgorithms/matrix/.
It includes two unit tests using JUnit 5:
✅ Verifies equality for identical matrices
❌ Verifies inequality for different matrices
Both test cases pass successfully using the Maven test runner.
Build & Code Coverage:-
The project builds cleanly with Java 21 and Maven 3.9.10
Tests executed via mvn -Dtest=RandomizedMatrixVerifierTest test
Code coverage verified using JaCoCo, confirming the new code is tested
Code Quality & Structure:-
Follows the existing file structure and naming conventions of the repository
Code is clean, well-commented, and adheres to contribution guidelines
No breaking changes introduced to existing functionality
About This Contribution:-
This is my first contribution to the TheAlgorithms/Java repository
I’m currently learning open-source contribution and Java best practices.
Feedback and suggestions are warmly welcome!!!