Repository: TheAlgorithms/Java
Pull request #6139 (2025-01-15 07:47:03)

Create package prime, matrix and games
<!--
Thank you for your contribution!
In order to reduce the number of notifications sent to the maintainers, please:
- create your PR as draft, cf. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests#draft-pull-requests,
- make sure that all of the CI checks pass,
- mark your PR as ready for review, cf. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-stage-of-a-pull-request#marking-a-pull-request-as-ready-for-review
-->

<!-- For completed items, change [ ] to [x] -->

- [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Java/blob/master/CONTRIBUTING.md).
- [x] This pull request is all my own work -- I have not plagiarized it.
- [ ] All filenames are in PascalCase.
- [ ] All functions and variable names follow Java naming conventions.
- [ ] All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
- [ ] All new code is formatted with `clang-format -i --style=file path/to/your/file.java`

siriak: And please see why build and linter checks failed
![image](https://github.com/user-attachments/assets/30242af0-6244-4b9a-adbb-d8fd9c8eebba)


Patch:
diff --git a/src/main/java/com/thealgorithms/maths/GoldbachConjecture.java b/src/main/java/com/thealgorithms/maths/GoldbachConjecture.java
index 52391bc1..4e962722 100644
--- a/src/main/java/com/thealgorithms/maths/GoldbachConjecture.java
+++ b/src/main/java/com/thealgorithms/maths/GoldbachConjecture.java
@@ -1,6 +1,6 @@
 package com.thealgorithms.maths;
 
-import static com.thealgorithms.maths.PrimeCheck.isPrime;
+import static com.thealgorithms.maths.Prime.PrimeCheck.isPrime;
 
 /**
  * This is a representation of the unsolved problem of Goldbach's Projection, according to which every
diff --git a/src/main/java/com/thealgorithms/maths/LiouvilleLambdaFunction.java b/src/main/java/com/thealgorithms/maths/Prime/LiouvilleLambdaFunction.java
similarity index 93%
rename from src/main/java/com/thealgorithms/maths/LiouvilleLambdaFunction.java
rename to src/main/java/com/thealgorithms/maths/Prime/LiouvilleLambdaFunction.java
index c0f55f5e..73535b3a 100644
--- a/src/main/java/com/thealgorithms/maths/LiouvilleLambdaFunction.java
+++ b/src/main/java/com/thealgorithms/maths/Prime/LiouvilleLambdaFunction.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.maths;
+package com.thealgorithms.maths.Prime;
 
 /*
  * Java program for liouville lambda function
@@ -24,7 +24,7 @@ public final class LiouvilleLambdaFunction {
      *         -1 when number has odd number of prime factors
      * @throws IllegalArgumentException when number is negative
      */
-    static int liouvilleLambda(int number) {
+    public static int liouvilleLambda(int number) {
         if (number <= 0) {
             // throw exception when number is less than or is zero
             throw new IllegalArgumentException("Number must be greater than zero.");
diff --git a/src/main/java/com/thealgorithms/maths/MillerRabinPrimalityCheck.java b/src/main/java/com/thealgorithms/maths/Prime/MillerRabinPrimalityCheck.java
similarity index 98%
rename from src/main/java/com/thealgorithms/maths/MillerRabinPrimalityCheck.java
rename to src/main/java/com/thealgorithms/maths/Prime/MillerRabinPrimalityCheck.java
index f889213a..debe3a21 100644
--- a/src/main/java/com/thealgorithms/maths/MillerRabinPrimalityCheck.java
+++ b/src/main/java/com/thealgorithms/maths/Prime/MillerRabinPrimalityCheck.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.maths;
+package com.thealgorithms.maths.Prime;
 
 import java.util.Random;
 
diff --git a/src/main/java/com/thealgorithms/maths/MobiusFunction.java b/src/main/java/com/thealgorithms/maths/Prime/MobiusFunction.java
similarity index 96%
rename from src/main/java/com/thealgorithms/maths/MobiusFunction.java
rename to src/main/java/com/thealgorithms/maths/Prime/MobiusFunction.java
index 915d0d9a..3d4e4eff 100644
--- a/src/main/java/com/thealgorithms/maths/MobiusFunction.java
+++ b/src/main/java/com/thealgorithms/maths/Prime/MobiusFunction.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.maths;
+package com.thealgorithms.maths.Prime;
 
 /*
  * Java program for mobius function
@@ -25,7 +25,7 @@ public final class MobiusFunction {
      *          0 when number has repeated prime factor
      *         -1 when number has odd number of prime factors
      */
-    static int mobius(int number) {
+    public static int mobius(int number) {
         if (number <= 0) {
             // throw exception when number is less than or is zero
             throw new IllegalArgumentException("Number must be greater than zero.");
diff --git a/src/main/java/com/thealgorithms/maths/PrimeCheck.java b/src/main/java/com/thealgorithms/maths/Prime/PrimeCheck.java
similarity index 98%
rename from src/main/java/com/thealgorithms/maths/PrimeCheck.java
rename to src/main/java/com/thealgorithms/maths/Prime/PrimeCheck.java
index 628a819a..91c490f7 100644
--- a/src/main/java/com/thealgorithms/maths/PrimeCheck.java
+++ b/src/main/java/com/thealgorithms/maths/Prime/PrimeCheck.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.maths;
+package com.thealgorithms.maths.Prime;
 
 import java.util.Scanner;
 
diff --git a/src/main/java/com/thealgorithms/maths/PrimeFactorization.java b/src/main/java/com/thealgorithms/maths/Prime/PrimeFactorization.java
similarity index 95%
rename from src/main/java/com/thealgorithms/maths/PrimeFactorization.java
rename to src/main/java/com/thealgorithms/maths/Prime/PrimeFactorization.java
index 9ac50fd9..e12002b3 100644
--- a/src/main/java/com/thealgorithms/maths/PrimeFactorization.java
+++ b/src/main/java/com/thealgorithms/maths/Prime/PrimeFactorization.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.maths;
+package com.thealgorithms.maths.Prime;
 
 /*
  * Authors:
diff --git a/src/main/java/com/thealgorithms/maths/SquareFreeInteger.java b/src/main/java/com/thealgorithms/maths/Prime/SquareFreeInteger.java
similarity index 97%
rename from src/main/java/com/thealgorithms/maths/SquareFreeInteger.java
rename to src/main/java/com/thealgorithms/maths/Prime/SquareFreeInteger.java
index 22e9fee0..15c0a8a6 100644
--- a/src/main/java/com/thealgorithms/maths/SquareFreeInteger.java
+++ b/src/main/java/com/thealgorithms/maths/Prime/SquareFreeInteger.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.maths;
+package com.thealgorithms.maths.Prime;
 /*
  * Java program for Square free integer
  * This class has a function which checks
diff --git a/src/main/java/com/thealgorithms/maths/TwinPrime.java b/src/main/java/com/thealgorithms/maths/TwinPrime.java
index ef8de0d1..f4e546a2 100644
--- a/src/main/java/com/thealgorithms/maths/TwinPrime.java
+++ b/src/main/java/com/thealgorithms/maths/TwinPrime.java
@@ -9,6 +9,8 @@ package com.thealgorithms.maths;
  *
  * */
 
+import com.thealgorithms.maths.Prime.PrimeCheck;
+
 public final class TwinPrime {
     private TwinPrime() {
     }
diff --git a/src/main/java/com/thealgorithms/maths/MatrixRank.java b/src/main/java/com/thealgorithms/matrix/MatrixRank.java
similarity index 77%
rename from src/main/java/com/thealgorithms/maths/MatrixRank.java
rename to src/main/java/com/thealgorithms/matrix/MatrixRank.java
index 7a628b92..6692b6c3 100644
--- a/src/main/java/com/thealgorithms/maths/MatrixRank.java
+++ b/src/main/java/com/thealgorithms/matrix/MatrixRank.java
@@ -1,4 +1,6 @@
-package com.thealgorithms.maths;
+package com.thealgorithms.matrix;
+
+import static com.thealgorithms.matrix.utils.MatrixUtil.validateInputMatrix;
 
 /**
  * This class provides a method to compute the rank of a matrix.
@@ -63,47 +65,6 @@ public final class MatrixRank {
         return matrixCopy;
     }
 
-    private static void validateInputMatrix(double[][] matrix) {
-        if (matrix == null) {
-            throw new IllegalArgumentException("The input matrix cannot be null");
-        }
-        if (matrix.length == 0) {
-            throw new IllegalArgumentException("The input matrix cannot be empty");
-        }
-        if (!hasValidRows(matrix)) {
-            throw new IllegalArgumentException("The input matrix cannot have null or empty rows");
-        }
-        if (isJaggedMatrix(matrix)) {
-            throw new IllegalArgumentException("The input matrix cannot be jagged");
-        }
-    }
-
-    private static boolean hasValidRows(double[][] matrix) {
-        for (double[] row : matrix) {
-            if (row == null || row.length == 0) {
-                return false;
-            }
-        }
-        return true;
-    }
-
-    /**
-     * @brief Checks if the input matrix is a jagged matrix.
-     * Jagged matrix is a matrix where the number of columns in each row is not the same.
-     *
-     * @param matrix The input matrix
-     * @return True if the input matrix is a jagged matrix, false otherwise
-     */
-    private static boolean isJaggedMatrix(double[][] matrix) {
-        int numColumns = matrix[0].length;
-        for (double[] row : matrix) {
-            if (row.length != numColumns) {
-                return true;
-            }
-        }
-        return false;
-    }
-
     /**
      * @brief The pivot row is the row in the matrix that is used to eliminate other rows and reduce the matrix to its row echelon form.
      * The pivot row is selected as the first row (from top to bottom) where the value in the current column (the pivot column) is not zero.
diff --git a/src/main/java/com/thealgorithms/matrix/MirrorOfMatrix.java b/src/main/java/com/thealgorithms/matrix/MirrorOfMatrix.java
index b24fcba7..3a3055f3 100644
--- a/src/main/java/com/thealgorithms/matrix/MirrorOfMatrix.java
+++ b/src/main/java/com/thealgorithms/matrix/MirrorOfMatrix.java
@@ -1,6 +1,9 @@
 package com.thealgorithms.matrix;
 
 // Problem Statement
+
+import com.thealgorithms.matrix.utils.MatrixUtil;
+
 /*
 We have given an array of m x n (where m is the number of rows and n is the number of columns).
 Print the new matrix in such a way that the new matrix is the mirror image of the original matrix.
@@ -17,41 +20,17 @@ public final class MirrorOfMatrix {
     private MirrorOfMatrix() {
     }
 
-    public static int[][] mirrorMatrix(final int[][] originalMatrix) {
-        if (originalMatrix == null) {
-            // Handle invalid input
-            return null;
-        }
-        if (originalMatrix.length == 0) {
-            return new int[0][0];
-        }
-
-        checkInput(originalMatrix);
+    public static double[][] mirrorMatrix(final double[][] originalMatrix) {
+        MatrixUtil.validateInputMatrix(originalMatrix);
 
         int numRows = originalMatrix.length;
         int numCols = originalMatrix[0].length;
 
-        int[][] mirroredMatrix = new int[numRows][numCols];
+        double[][] mirroredMatrix = new double[numRows][numCols];
 
         for (int i = 0; i < numRows; i++) {
-            mirroredMatrix[i] = reverseRow(originalMatrix[i]);
+            mirroredMatrix[i] = MatrixUtil.reverseRow(originalMatrix[i]);
         }
         return mirroredMatrix;
     }
-    private static int[] reverseRow(final int[] inRow) {
-        int[] res = new int[inRow.length];
-        for (int i = 0; i < inRow.length; ++i) {
-            res[i] = inRow[inRow.length - 1 - i];
-        }
-        return res;
-    }
-
-    private static void checkInput(final int[][] matrix) {
-        // Check if all rows have the same number of columns
-        for (int i = 1; i < matrix.length; i++) {
-            if (matrix[i].length != matrix[0].length) {
-                throw new IllegalArgumentException("The input is not a matrix.");
-            }
-        }
-    }
 }
diff --git a/src/main/java/com/thealgorithms/matrix/matrixexponentiation/Fibonacci.java b/src/main/java/com/thealgorithms/matrix/matrixexponentiation/Fibonacci.java
index 9c9f97b9..85852713 100644
--- a/src/main/java/com/thealgorithms/matrix/matrixexponentiation/Fibonacci.java
+++ b/src/main/java/com/thealgorithms/matrix/matrixexponentiation/Fibonacci.java
@@ -1,6 +1,7 @@
 package com.thealgorithms.matrix.matrixexponentiation;
 
-import java.util.Scanner;
+import com.thealgorithms.matrix.utils.MatrixUtil;
+import java.math.BigDecimal;
 
 /**
  * @author Anirudh Buvanesh (https://github.com/anirudhb11) For more information
@@ -12,39 +13,11 @@ public final class Fibonacci {
     }
 
     // Exponentiation matrix for Fibonacci sequence
-    private static final int[][] FIB_MATRIX = {{1, 1}, {1, 0}};
-    private static final int[][] IDENTITY_MATRIX = {{1, 0}, {0, 1}};
-    // First 2 fibonacci numbers
-    private static final int[][] BASE_FIB_NUMBERS = {{1}, {0}};
+    private static final BigDecimal ONE = BigDecimal.valueOf(1);
+    private static final BigDecimal ZERO = BigDecimal.valueOf(0);
 
-    /**
-     * Performs multiplication of 2 matrices
-     *
-     * @param matrix1
-     * @param matrix2
-     * @return The product of matrix1 and matrix2
-     */
-    private static int[][] matrixMultiplication(int[][] matrix1, int[][] matrix2) {
-        // Check if matrices passed can be multiplied
-        int rowsInMatrix1 = matrix1.length;
-        int columnsInMatrix1 = matrix1[0].length;
-
-        int rowsInMatrix2 = matrix2.length;
-        int columnsInMatrix2 = matrix2[0].length;
-
-        assert columnsInMatrix1 == rowsInMatrix2;
-        int[][] product = new int[rowsInMatrix1][columnsInMatrix2];
-        for (int rowIndex = 0; rowIndex < rowsInMatrix1; rowIndex++) {
-            for (int colIndex = 0; colIndex < columnsInMatrix2; colIndex++) {
-                int matrixEntry = 0;
-                for (int intermediateIndex = 0; intermediateIndex < columnsInMatrix1; intermediateIndex++) {
-                    matrixEntry += matrix1[rowIndex][intermediateIndex] * matrix2[intermediateIndex][colIndex];
-                }
-                product[rowIndex][colIndex] = matrixEntry;
-            }
-        }
-        return product;
-    }
+    private static final BigDecimal[][] FIB_MATRIX = {{ONE, ONE}, {ONE, ZERO}};
+    private static final BigDecimal[][] IDENTITY_MATRIX = {{ONE, ZERO}, {ZERO, ONE}};
 
     /**
      * Calculates the fibonacci number using matrix exponentiaition technique
@@ -53,26 +26,17 @@ public final class Fibonacci {
      * Outputs the nth * fibonacci number
      * @return a 2 X 1 array as { {F_n+1}, {F_n} }
      */
-    public static int[][] fib(int n) {
+    public static BigDecimal[][] fib(int n) {
         if (n == 0) {
             return IDENTITY_MATRIX;
         } else {
-            int[][] cachedResult = fib(n / 2);
-            int[][] matrixExpResult = matrixMultiplication(cachedResult, cachedResult);
+            BigDecimal[][] cachedResult = fib(n / 2);
+            BigDecimal[][] matrixExpResult = MatrixUtil.multiply(cachedResult, cachedResult).get();
             if (n % 2 == 0) {
                 return matrixExpResult;
             } else {
-                return matrixMultiplication(FIB_MATRIX, matrixExpResult);
+                return MatrixUtil.multiply(FIB_MATRIX, matrixExpResult).get();
             }
         }
     }
-
-    public static void main(String[] args) {
-        // Returns [0, 1, 1, 2, 3, 5 ..] for n = [0, 1, 2, 3, 4, 5.. ]
-        Scanner sc = new Scanner(System.in);
-        int n = sc.nextInt();
-        int[][] result = matrixMultiplication(fib(n), BASE_FIB_NUMBERS);
-        System.out.println("Fib(" + n + ") = " + result[1][0]);
-        sc.close();
-    }
 }
diff --git a/src/main/java/com/thealgorithms/maths/MatrixUtil.java b/src/main/java/com/thealgorithms/matrix/utils/MatrixUtil.java
similarity index 62%
rename from src/main/java/com/thealgorithms/maths/MatrixUtil.java
rename to src/main/java/com/thealgorithms/matrix/utils/MatrixUtil.java
index 7e462f92..5ff9e37f 100644
--- a/src/main/java/com/thealgorithms/maths/MatrixUtil.java
+++ b/src/main/java/com/thealgorithms/matrix/utils/MatrixUtil.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.maths;
+package com.thealgorithms.matrix.utils;
 
 import java.math.BigDecimal;
 import java.util.Optional;
@@ -10,6 +10,7 @@ import java.util.stream.IntStream;
  * @date: 31 October 2021 (Sunday)
  */
 public final class MatrixUtil {
+
     private MatrixUtil() {
     }
 
@@ -18,11 +19,52 @@ public final class MatrixUtil {
     }
 
     private static boolean hasEqualSizes(final BigDecimal[][] matrix1, final BigDecimal[][] matrix2) {
-        return (isValid(matrix1) && isValid(matrix2) && matrix1.length == matrix2.length && matrix1[0].length == matrix2[0].length);
+        return isValid(matrix1) && isValid(matrix2) && matrix1.length == matrix2.length && matrix1[0].length == matrix2[0].length;
     }
 
     private static boolean canMultiply(final BigDecimal[][] matrix1, final BigDecimal[][] matrix2) {
-        return (isValid(matrix1) && isValid(matrix2) && matrix1[0].length == matrix2.length);
+        return isValid(matrix1) && isValid(matrix2) && matrix1[0].length == matrix2.length;
+    }
+
+    public static void validateInputMatrix(double[][] matrix) {
+        if (matrix == null) {
+            throw new IllegalArgumentException("The input matrix cannot be null");
+        }
+        if (matrix.length == 0) {
+            throw new IllegalArgumentException("The input matrix cannot be empty");
+        }
+        if (!hasValidRows(matrix)) {
+            throw new IllegalArgumentException("The input matrix cannot have null or empty rows");
+        }
+        if (isJaggedMatrix(matrix)) {
+            throw new IllegalArgumentException("The input matrix cannot be jagged");
+        }
+    }
+
+    private static boolean hasValidRows(double[][] matrix) {
+        for (double[] row : matrix) {
+            if (row == null || row.length == 0) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    /**
+     * @brief Checks if the input matrix is a jagged matrix.
+     * Jagged matrix is a matrix where the number of columns in each row is not the same.
+     *
+     * @param matrix The input matrix
+     * @return True if the input matrix is a jagged matrix, false otherwise
+     */
+    private static boolean isJaggedMatrix(double[][] matrix) {
+        int numColumns = matrix[0].length;
+        for (double[] row : matrix) {
+            if (row.length != numColumns) {
+                return true;
+            }
+        }
+        return false;
     }
 
     private static Optional<BigDecimal[][]> operate(final BigDecimal[][] matrix1, final BigDecimal[][] matrix2, final BiFunction<BigDecimal, BigDecimal, BigDecimal> operation) {
@@ -80,4 +122,12 @@ public final class MatrixUtil {
 
         return Optional.of(result);
     }
+
+    public static double[] reverseRow(final double[] inRow) {
+        double[] res = new double[inRow.length];
+        for (int i = 0; i < inRow.length; ++i) {
+            res[i] = inRow[inRow.length - 1 - i];
+        }
+        return res;
+    }
 }
diff --git a/src/main/java/com/thealgorithms/others/Sudoku.java b/src/main/java/com/thealgorithms/puzzlesandgames/Sudoku.java
similarity index 99%
rename from src/main/java/com/thealgorithms/others/Sudoku.java
rename to src/main/java/com/thealgorithms/puzzlesandgames/Sudoku.java
index 0e88aee4..fce665c4 100644
--- a/src/main/java/com/thealgorithms/others/Sudoku.java
+++ b/src/main/java/com/thealgorithms/puzzlesandgames/Sudoku.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.others;
+package com.thealgorithms.puzzlesandgames;
 
 /**
  * A class that provides methods to solve Sudoku puzzles of any n x n size
diff --git a/src/main/java/com/thealgorithms/others/TowerOfHanoi.java b/src/main/java/com/thealgorithms/puzzlesandgames/TowerOfHanoi.java
similarity index 98%
rename from src/main/java/com/thealgorithms/others/TowerOfHanoi.java
rename to src/main/java/com/thealgorithms/puzzlesandgames/TowerOfHanoi.java
index 7017ed03..72e9a14a 100644
--- a/src/main/java/com/thealgorithms/others/TowerOfHanoi.java
+++ b/src/main/java/com/thealgorithms/puzzlesandgames/TowerOfHanoi.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.others;
+package com.thealgorithms.puzzlesandgames;
 
 import java.util.List;
 
diff --git a/src/main/java/com/thealgorithms/misc/WordBoggle.java b/src/main/java/com/thealgorithms/puzzlesandgames/WordBoggle.java
similarity index 98%
rename from src/main/java/com/thealgorithms/misc/WordBoggle.java
rename to src/main/java/com/thealgorithms/puzzlesandgames/WordBoggle.java
index 8b629d68..ca1430f7 100644
--- a/src/main/java/com/thealgorithms/misc/WordBoggle.java
+++ b/src/main/java/com/thealgorithms/puzzlesandgames/WordBoggle.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.misc;
+package com.thealgorithms.puzzlesandgames;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -8,9 +8,9 @@ import java.util.Map;
 import java.util.Set;
 
 public final class WordBoggle {
+
     private WordBoggle() {
     }
-
     /**
      * O(nm * 8^s + ws) time where n = width of boggle board, m = height of
      * boggle board, s = length of longest word in string array, w = length of


Test patch:
diff --git a/src/test/java/com/thealgorithms/maths/SquareFreeIntegerTest.java b/src/test/java/com/thealgorithms/maths/SquareFreeIntegerTest.java
index d7e16e02..5b35ee7b 100644
--- a/src/test/java/com/thealgorithms/maths/SquareFreeIntegerTest.java
+++ b/src/test/java/com/thealgorithms/maths/SquareFreeIntegerTest.java
@@ -3,6 +3,7 @@ package com.thealgorithms.maths;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
+import com.thealgorithms.maths.Prime.SquareFreeInteger;
 import java.util.List;
 import org.junit.jupiter.api.Test;
 
diff --git a/src/test/java/com/thealgorithms/maths/LiouvilleLambdaFunctionTest.java b/src/test/java/com/thealgorithms/maths/prime/LiouvilleLambdaFunctionTest.java
similarity index 94%
rename from src/test/java/com/thealgorithms/maths/LiouvilleLambdaFunctionTest.java
rename to src/test/java/com/thealgorithms/maths/prime/LiouvilleLambdaFunctionTest.java
index a2763047..d32815c0 100644
--- a/src/test/java/com/thealgorithms/maths/LiouvilleLambdaFunctionTest.java
+++ b/src/test/java/com/thealgorithms/maths/prime/LiouvilleLambdaFunctionTest.java
@@ -1,8 +1,9 @@
-package com.thealgorithms.maths;
+package com.thealgorithms.maths.prime;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
+import com.thealgorithms.maths.Prime.LiouvilleLambdaFunction;
 import org.junit.jupiter.api.Test;
 
 class LiouvilleLambdaFunctionTest {
diff --git a/src/test/java/com/thealgorithms/maths/MillerRabinPrimalityCheckTest.java b/src/test/java/com/thealgorithms/maths/prime/MillerRabinPrimalityCheckTest.java
similarity index 92%
rename from src/test/java/com/thealgorithms/maths/MillerRabinPrimalityCheckTest.java
rename to src/test/java/com/thealgorithms/maths/prime/MillerRabinPrimalityCheckTest.java
index d547cecf..4defcd58 100644
--- a/src/test/java/com/thealgorithms/maths/MillerRabinPrimalityCheckTest.java
+++ b/src/test/java/com/thealgorithms/maths/prime/MillerRabinPrimalityCheckTest.java
@@ -1,8 +1,9 @@
-package com.thealgorithms.maths;
+package com.thealgorithms.maths.prime;
 
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
+import com.thealgorithms.maths.Prime.MillerRabinPrimalityCheck;
 import org.junit.jupiter.api.Test;
 
 class MillerRabinPrimalityCheckTest {
diff --git a/src/test/java/com/thealgorithms/maths/MobiusFunctionTest.java b/src/test/java/com/thealgorithms/maths/prime/MobiusFunctionTest.java
similarity index 96%
rename from src/test/java/com/thealgorithms/maths/MobiusFunctionTest.java
rename to src/test/java/com/thealgorithms/maths/prime/MobiusFunctionTest.java
index f3a6514c..734d0247 100644
--- a/src/test/java/com/thealgorithms/maths/MobiusFunctionTest.java
+++ b/src/test/java/com/thealgorithms/maths/prime/MobiusFunctionTest.java
@@ -1,8 +1,9 @@
-package com.thealgorithms.maths;
+package com.thealgorithms.maths.prime;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
+import com.thealgorithms.maths.Prime.MobiusFunction;
 import org.junit.jupiter.api.Test;
 
 class MobiusFunctionTest {
diff --git a/src/test/java/com/thealgorithms/maths/PrimeCheckTest.java b/src/test/java/com/thealgorithms/maths/prime/PrimeCheckTest.java
similarity index 89%
rename from src/test/java/com/thealgorithms/maths/PrimeCheckTest.java
rename to src/test/java/com/thealgorithms/maths/prime/PrimeCheckTest.java
index c3e1634c..2182bcd9 100644
--- a/src/test/java/com/thealgorithms/maths/PrimeCheckTest.java
+++ b/src/test/java/com/thealgorithms/maths/prime/PrimeCheckTest.java
@@ -1,5 +1,6 @@
-package com.thealgorithms.maths;
+package com.thealgorithms.maths.prime;
 
+import com.thealgorithms.maths.Prime.PrimeCheck;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
diff --git a/src/test/java/com/thealgorithms/maths/PrimeFactorizationTest.java b/src/test/java/com/thealgorithms/maths/prime/PrimeFactorizationTest.java
similarity index 93%
rename from src/test/java/com/thealgorithms/maths/PrimeFactorizationTest.java
rename to src/test/java/com/thealgorithms/maths/prime/PrimeFactorizationTest.java
index 6994379d..79d68572 100644
--- a/src/test/java/com/thealgorithms/maths/PrimeFactorizationTest.java
+++ b/src/test/java/com/thealgorithms/maths/prime/PrimeFactorizationTest.java
@@ -1,7 +1,8 @@
-package com.thealgorithms.maths;
+package com.thealgorithms.maths.prime;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
+import com.thealgorithms.maths.Prime.PrimeFactorization;
 import java.util.List;
 import java.util.stream.Stream;
 import org.junit.jupiter.params.ParameterizedTest;
diff --git a/src/test/java/com/thealgorithms/maths/MatrixRankTest.java b/src/test/java/com/thealgorithms/matrix/MatrixRankTest.java
similarity index 98%
rename from src/test/java/com/thealgorithms/maths/MatrixRankTest.java
rename to src/test/java/com/thealgorithms/matrix/MatrixRankTest.java
index 415b84ec..33a0196b 100644
--- a/src/test/java/com/thealgorithms/maths/MatrixRankTest.java
+++ b/src/test/java/com/thealgorithms/matrix/MatrixRankTest.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.maths;
+package com.thealgorithms.matrix;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
diff --git a/src/test/java/com/thealgorithms/maths/MatrixUtilTest.java b/src/test/java/com/thealgorithms/matrix/MatrixUtilTest.java
similarity index 96%
rename from src/test/java/com/thealgorithms/maths/MatrixUtilTest.java
rename to src/test/java/com/thealgorithms/matrix/MatrixUtilTest.java
index b954e6ff..78947b1e 100644
--- a/src/test/java/com/thealgorithms/maths/MatrixUtilTest.java
+++ b/src/test/java/com/thealgorithms/matrix/MatrixUtilTest.java
@@ -1,7 +1,8 @@
-package com.thealgorithms.maths;
+package com.thealgorithms.matrix;
 
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
+import com.thealgorithms.matrix.utils.MatrixUtil;
 import java.math.BigDecimal;
 import java.util.Objects;
 import org.junit.jupiter.api.Test;
diff --git a/src/test/java/com/thealgorithms/matrix/MirrorOfMatrixTest.java b/src/test/java/com/thealgorithms/matrix/MirrorOfMatrixTest.java
index 2d68e1fa..2e437092 100644
--- a/src/test/java/com/thealgorithms/matrix/MirrorOfMatrixTest.java
+++ b/src/test/java/com/thealgorithms/matrix/MirrorOfMatrixTest.java
@@ -1,7 +1,7 @@
 package com.thealgorithms.matrix;
 
 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import org.junit.jupiter.api.Test;
@@ -10,44 +10,44 @@ class MirrorOfMatrixTest {
 
     @Test
     void testMirrorMatrixRegularMatrix() {
-        int[][] originalMatrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
-        int[][] expectedMirrorMatrix = {{3, 2, 1}, {6, 5, 4}, {9, 8, 7}};
-        int[][] mirroredMatrix = MirrorOfMatrix.mirrorMatrix(originalMatrix);
+        double[][] originalMatrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
+        double[][] expectedMirrorMatrix = {{3, 2, 1}, {6, 5, 4}, {9, 8, 7}};
+        double[][] mirroredMatrix = MirrorOfMatrix.mirrorMatrix(originalMatrix);
         assertArrayEquals(expectedMirrorMatrix, mirroredMatrix);
     }
 
     @Test
     void testMirrorMatrixEmptyMatrix() {
-        int[][] originalMatrix = {};
-        int[][] expectedMirrorMatrix = {};
-        int[][] mirroredMatrix = MirrorOfMatrix.mirrorMatrix(originalMatrix);
-        assertArrayEquals(expectedMirrorMatrix, mirroredMatrix);
+        double[][] originalMatrix = {};
+        Exception e = assertThrows(IllegalArgumentException.class, () -> MirrorOfMatrix.mirrorMatrix(originalMatrix));
+        assertEquals("The input matrix cannot be empty", e.getMessage());
     }
 
     @Test
     void testMirrorMatrixSingleElementMatrix() {
-        int[][] originalMatrix = {{42}};
-        int[][] expectedMirrorMatrix = {{42}};
-        int[][] mirroredMatrix = MirrorOfMatrix.mirrorMatrix(originalMatrix);
+        double[][] originalMatrix = {{42}};
+        double[][] expectedMirrorMatrix = {{42}};
+        double[][] mirroredMatrix = MirrorOfMatrix.mirrorMatrix(originalMatrix);
         assertArrayEquals(expectedMirrorMatrix, mirroredMatrix);
     }
 
     @Test
     void testMirrorMatrixMultipleRowsOneColumnMatrix() {
-        int[][] originalMatrix = {{1}, {2}, {3}, {4}};
-        int[][] expectedMirrorMatrix = {{1}, {2}, {3}, {4}};
-        int[][] mirroredMatrix = MirrorOfMatrix.mirrorMatrix(originalMatrix);
+        double[][] originalMatrix = {{1}, {2}, {3}, {4}};
+        double[][] expectedMirrorMatrix = {{1}, {2}, {3}, {4}};
+        double[][] mirroredMatrix = MirrorOfMatrix.mirrorMatrix(originalMatrix);
         assertArrayEquals(expectedMirrorMatrix, mirroredMatrix);
     }
 
     @Test
     void testMirrorMatrixNullInput() {
-        int[][] originalMatrix = null;
-        assertNull(MirrorOfMatrix.mirrorMatrix(originalMatrix));
+        double[][] originalMatrix = null;
+        Exception e = assertThrows(IllegalArgumentException.class, () -> MirrorOfMatrix.mirrorMatrix(originalMatrix));
+        assertEquals("The input matrix cannot be null", e.getMessage());
     }
 
     @Test
-    void testMirrotMarixThrows() {
-        assertThrows(IllegalArgumentException.class, () -> MirrorOfMatrix.mirrorMatrix(new int[][] {{1}, {2, 3}}));
+    void testMirrorMatrixThrows() {
+        assertThrows(IllegalArgumentException.class, () -> MirrorOfMatrix.mirrorMatrix(new double[][] {{1}, {2, 3}}));
     }
 }
diff --git a/src/test/java/com/thealgorithms/others/SudokuTest.java b/src/test/java/com/thealgorithms/puzzlesandgames/SudokuTest.java
similarity index 97%
rename from src/test/java/com/thealgorithms/others/SudokuTest.java
rename to src/test/java/com/thealgorithms/puzzlesandgames/SudokuTest.java
index 5018b276..7fb96dcf 100644
--- a/src/test/java/com/thealgorithms/others/SudokuTest.java
+++ b/src/test/java/com/thealgorithms/puzzlesandgames/SudokuTest.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.others;
+package com.thealgorithms.puzzlesandgames;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
diff --git a/src/test/java/com/thealgorithms/others/TowerOfHanoiTest.java b/src/test/java/com/thealgorithms/puzzlesandgames/TowerOfHanoiTest.java
similarity index 97%
rename from src/test/java/com/thealgorithms/others/TowerOfHanoiTest.java
rename to src/test/java/com/thealgorithms/puzzlesandgames/TowerOfHanoiTest.java
index ca9376dd..42669eb0 100644
--- a/src/test/java/com/thealgorithms/others/TowerOfHanoiTest.java
+++ b/src/test/java/com/thealgorithms/puzzlesandgames/TowerOfHanoiTest.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.others;
+package com.thealgorithms.puzzlesandgames;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
diff --git a/src/test/java/com/thealgorithms/misc/WordBoggleTest.java b/src/test/java/com/thealgorithms/puzzlesandgames/WordBoggleTest.java
similarity index 98%
rename from src/test/java/com/thealgorithms/misc/WordBoggleTest.java
rename to src/test/java/com/thealgorithms/puzzlesandgames/WordBoggleTest.java
index 1d4ed7c5..ef5d3c92 100644
--- a/src/test/java/com/thealgorithms/misc/WordBoggleTest.java
+++ b/src/test/java/com/thealgorithms/puzzlesandgames/WordBoggleTest.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.misc;
+package com.thealgorithms.puzzlesandgames;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;