Repository: TheAlgorithms/Java
Pull request #5372 (2024-08-23 20:58:24)

refactor: fix typo
Fix few typos in GaussLegendre and Isomorphic classes, and removing redundant generics parameters.

<!--
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.
- [x] All filenames are in PascalCase.
- [x] All functions and variable names follow Java naming conventions.
- [x] All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
- [x] All new code is formatted with `clang-format -i --style=file path/to/your/file.java`

codecov-commenter: ## [Codecov](https://app.codecov.io/gh/TheAlgorithms/Java/pull/5372?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) Report
Attention: Patch coverage is `0%` with `4 lines` in your changes missing coverage. Please review.
> Project coverage is 46.25%. Comparing base [(`ce4eb55`)](https://app.codecov.io/gh/TheAlgorithms/Java/commit/ce4eb55e0e7c5216e2cba53217627f6bbe8b5083?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) to head [(`8a56d50`)](https://app.codecov.io/gh/TheAlgorithms/Java/commit/8a56d50ba40c25aaf4f1ca7bb45fa204368a8ae5?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms).

| [Files](https://app.codecov.io/gh/TheAlgorithms/Java/pull/5372?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) | Patch % | Lines |
|---|---|---|
| [...ain/java/com/thealgorithms/strings/Isomorphic.java](https://app.codecov.io/gh/TheAlgorithms/Java/pull/5372?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Fcom%2Fthealgorithms%2Fstrings%2FIsomorphic.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms#diff-c3JjL21haW4vamF2YS9jb20vdGhlYWxnb3JpdGhtcy9zdHJpbmdzL0lzb21vcnBoaWMuamF2YQ==) | 0.00% | [4 Missing :warning: ](https://app.codecov.io/gh/TheAlgorithms/Java/pull/5372?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) |

<details><summary>Additional details and impacted files</summary>


```diff
@@             Coverage Diff              @@
##             master    #5372      +/-   ##
============================================
- Coverage     46.26%   46.25%   -0.02%     
+ Complexity     2866     2865       -1     
============================================
  Files           525      525              
  Lines         15410    15410              
  Branches       2916     2916              
============================================
- Hits           7130     7128       -2     
- Misses         7981     7982       +1     
- Partials        299      300       +1     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/TheAlgorithms/Java/pull/5372?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms).


Patch:
diff --git a/src/main/java/com/thealgorithms/backtracking/NQueens.java b/src/main/java/com/thealgorithms/backtracking/NQueens.java
index e21a8bb7..1a8e453e 100644
--- a/src/main/java/com/thealgorithms/backtracking/NQueens.java
+++ b/src/main/java/com/thealgorithms/backtracking/NQueens.java
@@ -36,13 +36,10 @@ public final class NQueens {
     private NQueens() {
     }
 
-    public static void main(String[] args) {
-        placeQueens(1);
-        placeQueens(2);
-        placeQueens(3);
-        placeQueens(4);
-        placeQueens(5);
-        placeQueens(6);
+    public static List<List<String>> getNQueensArrangements(int queens) {
+        List<List<String>> arrangements = new ArrayList<>();
+        getSolution(queens, arrangements, new int[queens], 0);
+        return arrangements;
     }
 
     public static void placeQueens(final int queens) {
diff --git a/src/main/java/com/thealgorithms/conversions/HexToOct.java b/src/main/java/com/thealgorithms/conversions/HexToOct.java
index 97a8be16..d3a672d3 100644
--- a/src/main/java/com/thealgorithms/conversions/HexToOct.java
+++ b/src/main/java/com/thealgorithms/conversions/HexToOct.java
@@ -1,7 +1,5 @@
 package com.thealgorithms.conversions;
 
-import java.util.Scanner;
-
 /**
  * Converts any Hexadecimal Number to Octal
  *
@@ -12,64 +10,53 @@ public final class HexToOct {
     }
 
     /**
-     * This method converts a Hexadecimal number to a decimal number
+     * Converts a Hexadecimal number to a Decimal number.
      *
-     * @param s The Hexadecimal Number
-     * @return The Decimal number
+     * @param hex The Hexadecimal number as a String.
+     * @return The Decimal equivalent as an integer.
      */
-    public static int hex2decimal(String s) {
-        String str = "0123456789ABCDEF";
-        s = s.toUpperCase();
-        int val = 0;
-        for (int i = 0; i < s.length(); i++) {
-            char a = s.charAt(i);
-            int n = str.indexOf(a);
-            val = 16 * val + n;
+    public static int hexToDecimal(String hex) {
+        String hexDigits = "0123456789ABCDEF";
+        hex = hex.toUpperCase();
+        int decimalValue = 0;
+
+        for (int i = 0; i < hex.length(); i++) {
+            char hexChar = hex.charAt(i);
+            int digitValue = hexDigits.indexOf(hexChar);
+            decimalValue = 16 * decimalValue + digitValue;
         }
-        return val;
+
+        return decimalValue;
     }
 
     /**
-     * This method converts a Decimal number to a octal number
+     * Converts a Decimal number to an Octal number.
      *
-     * @param q The Decimal Number
-     * @return The Octal number
+     * @param decimal The Decimal number as an integer.
+     * @return The Octal equivalent as an integer.
      */
-    public static int decimal2octal(int q) {
-        int now;
-        int i = 1;
-        int octnum = 0;
-        while (q > 0) {
-            now = q % 8;
-            octnum = (now * (int) (Math.pow(10, i))) + octnum;
-            q /= 8;
-            i++;
+    public static int decimalToOctal(int decimal) {
+        int octalValue = 0;
+        int placeValue = 1;
+
+        while (decimal > 0) {
+            int remainder = decimal % 8;
+            octalValue += remainder * placeValue;
+            decimal /= 8;
+            placeValue *= 10;
         }
-        octnum /= 10;
-        return octnum;
+
+        return octalValue;
     }
 
     /**
-     * Main method that gets the hex input from user and converts it into octal.
+     * Converts a Hexadecimal number to an Octal number.
      *
-     * @param args arguments
+     * @param hex The Hexadecimal number as a String.
+     * @return The Octal equivalent as an integer.
      */
-    public static void main(String[] args) {
-        String hexadecnum;
-        int decnum;
-        int octalnum;
-        Scanner scan = new Scanner(System.in);
-
-        System.out.print("Enter Hexadecimal Number : ");
-        hexadecnum = scan.nextLine();
-
-        // first convert hexadecimal to decimal
-        decnum = hex2decimal(hexadecnum); // Pass the string to the hex2decimal function and get the decimal form in
-        // variable decnum
-
-        // convert decimal to octal
-        octalnum = decimal2octal(decnum);
-        System.out.println("Number in octal: " + octalnum);
-        scan.close();
+    public static int hexToOctal(String hex) {
+        int decimalValue = hexToDecimal(hex);
+        return decimalToOctal(decimalValue);
     }
 }
diff --git a/src/main/java/com/thealgorithms/maths/DeterminantOfMatrix.java b/src/main/java/com/thealgorithms/maths/DeterminantOfMatrix.java
index a2a32711..b652d490 100644
--- a/src/main/java/com/thealgorithms/maths/DeterminantOfMatrix.java
+++ b/src/main/java/com/thealgorithms/maths/DeterminantOfMatrix.java
@@ -1,7 +1,5 @@
 package com.thealgorithms.maths;
 
-import java.util.Scanner;
-
 /*
  * @author Ojasva Jain
  * Determinant of a Matrix Wikipedia link: https://en.wikipedia.org/wiki/Determinant
@@ -10,8 +8,13 @@ public final class DeterminantOfMatrix {
     private DeterminantOfMatrix() {
     }
 
-    // Determinant calculator
-    //@return determinant of the input matrix
+    /**
+     * Calculates the determinant of a given matrix.
+     *
+     * @param a the input matrix
+     * @param n the size of the matrix
+     * @return the determinant of the matrix
+     */
     static int determinant(int[][] a, int n) {
         int det = 0;
         int sign = 1;
@@ -41,21 +44,4 @@ public final class DeterminantOfMatrix {
         }
         return det;
     }
-
-    // Driver Method
-    public static void main(String[] args) {
-        Scanner in = new Scanner(System.in);
-        // Input Matrix
-        System.out.println("Enter matrix size (Square matrix only)");
-        int n = in.nextInt();
-        System.out.println("Enter matrix");
-        int[][] a = new int[n][n];
-        for (int i = 0; i < n; i++) {
-            for (int j = 0; j < n; j++) {
-                a[i][j] = in.nextInt();
-            }
-        }
-        System.out.println(determinant(a, n));
-        in.close();
-    }
 }
diff --git a/src/main/java/com/thealgorithms/maths/FindKthNumber.java b/src/main/java/com/thealgorithms/maths/FindKthNumber.java
index daea3f96..a9b26767 100644
--- a/src/main/java/com/thealgorithms/maths/FindKthNumber.java
+++ b/src/main/java/com/thealgorithms/maths/FindKthNumber.java
@@ -1,10 +1,9 @@
 package com.thealgorithms.maths;
 
-import java.util.Arrays;
 import java.util.Random;
 
 /**
- * use quick sort algorithm to get kth largest or kth smallest element in given array
+ * Use a quicksort-based approach to identify the k-th largest or k-th max element within the provided array.
  */
 public final class FindKthNumber {
     private FindKthNumber() {
@@ -12,66 +11,55 @@ public final class FindKthNumber {
 
     private static final Random RANDOM = new Random();
 
-    public static void main(String[] args) {
-        /* generate an array with random size and random elements */
-        int[] nums = generateArray(100);
-
-        /* get 3th largest element */
-        int kth = 3;
-        int kthMaxIndex = nums.length - kth;
-        int targetMax = findKthMax(nums, kthMaxIndex);
-
-        /* get 3th smallest element */
-        int kthMinIndex = kth - 1;
-        int targetMin = findKthMax(nums, kthMinIndex);
+    public static int findKthMax(int[] array, int k) {
+        if (k <= 0 || k > array.length) {
+            throw new IllegalArgumentException("k must be between 1 and the size of the array");
+        }
 
-        Arrays.sort(nums);
-        assert nums[kthMaxIndex] == targetMax;
-        assert nums[kthMinIndex] == targetMin;
+        // Convert k-th largest to index for QuickSelect
+        return quickSelect(array, 0, array.length - 1, array.length - k);
     }
 
-    private static int[] generateArray(int capacity) {
-        int size = RANDOM.nextInt(capacity) + 1;
-        int[] array = new int[size];
-
-        for (int i = 0; i < size; i++) {
-            array[i] = RANDOM.nextInt() % 100;
+    private static int quickSelect(int[] array, int left, int right, int kSmallest) {
+        if (left == right) {
+            return array[left];
         }
-        return array;
-    }
 
-    private static int findKthMax(int[] nums, int k) {
-        int start = 0;
-        int end = nums.length;
-        while (start < end) {
-            int pivot = partition(nums, start, end);
-            if (k == pivot) {
-                return nums[pivot];
-            } else if (k > pivot) {
-                start = pivot + 1;
-            } else {
-                end = pivot;
-            }
+        // Randomly select a pivot index
+        int pivotIndex = left + RANDOM.nextInt(right - left + 1);
+        pivotIndex = partition(array, left, right, pivotIndex);
+
+        if (kSmallest == pivotIndex) {
+            return array[kSmallest];
+        } else if (kSmallest < pivotIndex) {
+            return quickSelect(array, left, pivotIndex - 1, kSmallest);
+        } else {
+            return quickSelect(array, pivotIndex + 1, right, kSmallest);
         }
-        return -1;
     }
 
-    private static int partition(int[] nums, int start, int end) {
-        int pivot = nums[start];
-        int j = start;
-        for (int i = start + 1; i < end; i++) {
-            if (nums[i] < pivot) {
-                j++;
-                swap(nums, i, j);
+    private static int partition(int[] array, int left, int right, int pivotIndex) {
+        int pivotValue = array[pivotIndex];
+        // Move pivot to end
+        swap(array, pivotIndex, right);
+        int storeIndex = left;
+
+        // Move all smaller elements to the left
+        for (int i = left; i < right; i++) {
+            if (array[i] < pivotValue) {
+                swap(array, storeIndex, i);
+                storeIndex++;
             }
         }
-        swap(nums, start, j);
-        return j;
+
+        // Move pivot to its final place
+        swap(array, storeIndex, right);
+        return storeIndex;
     }
 
-    private static void swap(int[] nums, int a, int b) {
-        int tmp = nums[a];
-        nums[a] = nums[b];
-        nums[b] = tmp;
+    private static void swap(int[] array, int i, int j) {
+        int temp = array[i];
+        array[i] = array[j];
+        array[j] = temp;
     }
 }
diff --git a/src/main/java/com/thealgorithms/others/GuassLegendre.java b/src/main/java/com/thealgorithms/others/GaussLegendre.java
similarity index 94%
rename from src/main/java/com/thealgorithms/others/GuassLegendre.java
rename to src/main/java/com/thealgorithms/others/GaussLegendre.java
index 5ecfdf2b..b56b51f1 100644
--- a/src/main/java/com/thealgorithms/others/GuassLegendre.java
+++ b/src/main/java/com/thealgorithms/others/GaussLegendre.java
@@ -6,8 +6,8 @@ package com.thealgorithms.others;
  *
  * @author AKS1996
  */
-public final class GuassLegendre {
-    private GuassLegendre() {
+public final class GaussLegendre {
+    private GaussLegendre() {
     }
 
     public static void main(String[] args) {
diff --git a/src/main/java/com/thealgorithms/others/PasswordGen.java b/src/main/java/com/thealgorithms/others/PasswordGen.java
index 7d21f112..da9f21bc 100644
--- a/src/main/java/com/thealgorithms/others/PasswordGen.java
+++ b/src/main/java/com/thealgorithms/others/PasswordGen.java
@@ -12,21 +12,32 @@ import java.util.Random;
  * @date 2017.10.25
  */
 final class PasswordGen {
+    private static final String UPPERCASE_LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+    private static final String LOWERCASE_LETTERS = "abcdefghijklmnopqrstuvwxyz";
+    private static final String DIGITS = "0123456789";
+    private static final String SPECIAL_CHARACTERS = "!@#$%^&*(){}?";
+    private static final String ALL_CHARACTERS = UPPERCASE_LETTERS + LOWERCASE_LETTERS + DIGITS + SPECIAL_CHARACTERS;
+
     private PasswordGen() {
     }
 
-    static String generatePassword(int minLength, int maxLength) {
-        Random random = new Random();
-
-        String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-        String lower = "abcdefghijklmnopqrstuvwxyz";
-        String numbers = "0123456789";
-        String specialChars = "!@#$%^&*(){}?";
+    /**
+     * Generates a random password with a length between minLength and maxLength.
+     *
+     * @param minLength The minimum length of the password.
+     * @param maxLength The maximum length of the password.
+     * @return A randomly generated password.
+     * @throws IllegalArgumentException if minLength is greater than maxLength or if either is non-positive.
+     */
+    public static String generatePassword(int minLength, int maxLength) {
+        if (minLength > maxLength || minLength <= 0 || maxLength <= 0) {
+            throw new IllegalArgumentException("Incorrect length parameters: minLength must be <= maxLength and both must be > 0");
+        }
 
-        String allChars = upper + lower + numbers + specialChars;
+        Random random = new Random();
 
-        List<Character> letters = new ArrayList<Character>();
-        for (char c : allChars.toCharArray()) {
+        List<Character> letters = new ArrayList<>();
+        for (char c : ALL_CHARACTERS.toCharArray()) {
             letters.add(c);
         }
 
@@ -36,7 +47,7 @@ final class PasswordGen {
 
         // Note that size of the password is also random
         for (int i = random.nextInt(maxLength - minLength) + minLength; i > 0; --i) {
-            password.append(letters.get(random.nextInt(letters.size())));
+            password.append(ALL_CHARACTERS.charAt(random.nextInt(ALL_CHARACTERS.length())));
         }
 
         return password.toString();
diff --git a/src/main/java/com/thealgorithms/strings/Isomorphic.java b/src/main/java/com/thealgorithms/strings/Isomorphic.java
index 088addc6..ccd68617 100644
--- a/src/main/java/com/thealgorithms/strings/Isomorphic.java
+++ b/src/main/java/com/thealgorithms/strings/Isomorphic.java
@@ -17,8 +17,8 @@ public final class Isomorphic {
         // To mark the characters of string using MAP
         // character of first string as KEY and another as VALUE
         // now check occurence by keeping the track with SET data structure
-        Map<Character, Character> characterMap = new HashMap<Character, Character>();
-        Set<Character> trackUinqueCharacter = new HashSet<Character>();
+        Map<Character, Character> characterMap = new HashMap<>();
+        Set<Character> trackUniqueCharacter = new HashSet<>();
 
         for (int i = 0; i < s.length(); i++) {
             if (characterMap.containsKey(s.charAt(i))) {
@@ -26,13 +26,13 @@ public final class Isomorphic {
                     return false;
                 }
             } else {
-                if (trackUinqueCharacter.contains(t.charAt(i))) {
+                if (trackUniqueCharacter.contains(t.charAt(i))) {
                     return false;
                 }
 
                 characterMap.put(s.charAt(i), t.charAt(i));
             }
-            trackUinqueCharacter.add(t.charAt(i));
+            trackUniqueCharacter.add(t.charAt(i));
         }
         return true;
     }


Test patch:
diff --git a/src/test/java/com/thealgorithms/backtracking/NQueensTest.java b/src/test/java/com/thealgorithms/backtracking/NQueensTest.java
new file mode 100644
index 00000000..977e3dfa
--- /dev/null
+++ b/src/test/java/com/thealgorithms/backtracking/NQueensTest.java
@@ -0,0 +1,48 @@
+package com.thealgorithms.backtracking;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.junit.jupiter.api.Test;
+
+public class NQueensTest {
+
+    @Test
+    public void testNQueens1() {
+        List<List<String>> expected = Arrays.asList(Arrays.asList("Q"));
+        assertEquals(expected, NQueens.getNQueensArrangements(1));
+    }
+
+    @Test
+    public void testNQueens2() {
+        List<List<String>> expected = new ArrayList<>(); // No solution exists
+        assertEquals(expected, NQueens.getNQueensArrangements(2));
+    }
+
+    @Test
+    public void testNQueens3() {
+        List<List<String>> expected = new ArrayList<>(); // No solution exists
+        assertEquals(expected, NQueens.getNQueensArrangements(3));
+    }
+
+    @Test
+    public void testNQueens4() {
+        List<List<String>> expected = Arrays.asList(Arrays.asList(".Q..", "...Q", "Q...", "..Q."), Arrays.asList("..Q.", "Q...", "...Q", ".Q.."));
+        assertEquals(expected, NQueens.getNQueensArrangements(4));
+    }
+
+    @Test
+    public void testNQueens5() {
+        // Only the number of solutions is tested for larger N due to the complexity of checking each board configuration
+        List<List<String>> result = NQueens.getNQueensArrangements(5);
+        assertEquals(10, result.size()); // 5x5 board has 10 solutions
+    }
+
+    @Test
+    public void testNQueens6() {
+        List<List<String>> result = NQueens.getNQueensArrangements(6);
+        assertEquals(4, result.size()); // 6x6 board has 4 solutions
+    }
+}
diff --git a/src/test/java/com/thealgorithms/conversions/HexToOctTest.java b/src/test/java/com/thealgorithms/conversions/HexToOctTest.java
index 5924aa31..b3f94b19 100644
--- a/src/test/java/com/thealgorithms/conversions/HexToOctTest.java
+++ b/src/test/java/com/thealgorithms/conversions/HexToOctTest.java
@@ -5,10 +5,29 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import org.junit.jupiter.api.Test;
 
 public class HexToOctTest {
+    @Test
+    public void testHexToDecimal() {
+        assertEquals(255, HexToOct.hexToDecimal("FF"));
+        assertEquals(16, HexToOct.hexToDecimal("10"));
+        assertEquals(0, HexToOct.hexToDecimal("0"));
+        assertEquals(4095, HexToOct.hexToDecimal("FFF"));
+    }
+
+    @Test
+    public void testDecimalToOctal() {
+        assertEquals(110, HexToOct.decimalToOctal(HexToOct.hexToDecimal("48")));
+        assertEquals(255, HexToOct.decimalToOctal(HexToOct.hexToDecimal("AD")));
+        assertEquals(377, HexToOct.decimalToOctal(255));
+        assertEquals(20, HexToOct.decimalToOctal(16));
+        assertEquals(0, HexToOct.decimalToOctal(0));
+        assertEquals(7777, HexToOct.decimalToOctal(4095));
+    }
 
     @Test
-    public void testHexToOct() {
-        assertEquals(110, HexToOct.decimal2octal(HexToOct.hex2decimal("48")));
-        assertEquals(255, HexToOct.decimal2octal(HexToOct.hex2decimal("AD")));
+    public void testHexToOctal() {
+        assertEquals(377, HexToOct.hexToOctal("FF"));
+        assertEquals(20, HexToOct.hexToOctal("10"));
+        assertEquals(0, HexToOct.hexToOctal("0"));
+        assertEquals(7777, HexToOct.hexToOctal("FFF"));
     }
 }
diff --git a/src/test/java/com/thealgorithms/maths/DeterminantOfMatrixTest.java b/src/test/java/com/thealgorithms/maths/DeterminantOfMatrixTest.java
new file mode 100644
index 00000000..dd1c3ac4
--- /dev/null
+++ b/src/test/java/com/thealgorithms/maths/DeterminantOfMatrixTest.java
@@ -0,0 +1,50 @@
+package com.thealgorithms.maths;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+public class DeterminantOfMatrixTest {
+
+    @Test
+    public void testDeterminant2x2Matrix() {
+        int[][] matrix = {{1, 2}, {3, 4}};
+        int expected = -2;
+        assertEquals(expected, DeterminantOfMatrix.determinant(matrix, 2));
+    }
+
+    @Test
+    public void testDeterminant3x3Matrix() {
+        int[][] matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
+        int expected = 0;
+        assertEquals(expected, DeterminantOfMatrix.determinant(matrix, 3));
+    }
+
+    @Test
+    public void testDeterminant3x3MatrixNonZero() {
+        int[][] matrix = {{1, 2, 3}, {0, 1, 4}, {5, 6, 0}};
+        int expected = 1;
+        assertEquals(expected, DeterminantOfMatrix.determinant(matrix, 3));
+    }
+
+    @Test
+    public void testDeterminant1x1Matrix() {
+        int[][] matrix = {{7}};
+        int expected = 7;
+        assertEquals(expected, DeterminantOfMatrix.determinant(matrix, 1));
+    }
+
+    @Test
+    public void testDeterminant4x4Matrix() {
+        int[][] matrix = {{1, 0, 0, 1}, {0, 1, 0, 0}, {0, 0, 1, 0}, {1, 0, 0, 1}};
+        int expected = 0;
+        assertEquals(expected, DeterminantOfMatrix.determinant(matrix, 4));
+    }
+
+    @Test
+    public void testDeterminant4x4MatrixZero() {
+        int[][] matrix = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}};
+        int expected = 0;
+        assertEquals(expected, DeterminantOfMatrix.determinant(matrix, 4));
+    }
+}
diff --git a/src/test/java/com/thealgorithms/maths/FindKthNumberTest.java b/src/test/java/com/thealgorithms/maths/FindKthNumberTest.java
new file mode 100644
index 00000000..ddf62ff1
--- /dev/null
+++ b/src/test/java/com/thealgorithms/maths/FindKthNumberTest.java
@@ -0,0 +1,59 @@
+package com.thealgorithms.maths;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.util.Arrays;
+import java.util.Random;
+import org.junit.jupiter.api.Test;
+
+public class FindKthNumberTest {
+    @Test
+    public void testFindKthMaxTypicalCases() {
+        int[] array1 = {3, 2, 1, 4, 5};
+        assertEquals(3, FindKthNumber.findKthMax(array1, 3));
+        assertEquals(4, FindKthNumber.findKthMax(array1, 2));
+        assertEquals(5, FindKthNumber.findKthMax(array1, 1));
+
+        int[] array2 = {7, 5, 8, 2, 1, 6};
+        assertEquals(5, FindKthNumber.findKthMax(array2, 4));
+        assertEquals(6, FindKthNumber.findKthMax(array2, 3));
+        assertEquals(8, FindKthNumber.findKthMax(array2, 1));
+    }
+
+    @Test
+    public void testFindKthMaxEdgeCases() {
+        int[] array1 = {1};
+        assertEquals(1, FindKthNumber.findKthMax(array1, 1));
+
+        int[] array2 = {5, 3};
+        assertEquals(5, FindKthNumber.findKthMax(array2, 1));
+        assertEquals(3, FindKthNumber.findKthMax(array2, 2));
+    }
+
+    @Test
+    public void testFindKthMaxInvalidK() {
+        int[] array = {1, 2, 3, 4, 5};
+        assertThrows(IllegalArgumentException.class, () -> FindKthNumber.findKthMax(array, 0));
+        assertThrows(IllegalArgumentException.class, () -> FindKthNumber.findKthMax(array, 6));
+    }
+
+    @Test
+    public void testFindKthMaxLargeArray() {
+        int[] array = generateArray(1000);
+        int k = new Random().nextInt(array.length);
+        int result = FindKthNumber.findKthMax(array, k);
+        Arrays.sort(array);
+        assertEquals(array[array.length - k], result);
+    }
+
+    public static int[] generateArray(int capacity) {
+        int size = new Random().nextInt(capacity) + 1;
+        int[] array = new int[size];
+
+        for (int i = 0; i < size; i++) {
+            array[i] = new Random().nextInt(100); // Ensure positive values for testing
+        }
+        return array;
+    }
+}
diff --git a/src/test/java/com/thealgorithms/others/PasswordGenTest.java b/src/test/java/com/thealgorithms/others/PasswordGenTest.java
index 57de329c..76492556 100644
--- a/src/test/java/com/thealgorithms/others/PasswordGenTest.java
+++ b/src/test/java/com/thealgorithms/others/PasswordGenTest.java
@@ -1,5 +1,6 @@
 package com.thealgorithms.others;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -10,7 +11,7 @@ public class PasswordGenTest {
     @Test
     public void failGenerationWithSameMinMaxLengthTest() {
         int length = 10;
-        assertThrows(IllegalArgumentException.class, () -> { PasswordGen.generatePassword(length, length); });
+        assertThrows(IllegalArgumentException.class, () -> PasswordGen.generatePassword(length, length));
     }
 
     @Test
@@ -23,7 +24,7 @@ public class PasswordGenTest {
     public void failGenerationWithMinLengthSmallerThanMaxLengthTest() {
         int minLength = 10;
         int maxLength = 5;
-        assertThrows(IllegalArgumentException.class, () -> { PasswordGen.generatePassword(minLength, maxLength); });
+        assertThrows(IllegalArgumentException.class, () -> PasswordGen.generatePassword(minLength, maxLength));
     }
 
     @Test
@@ -31,4 +32,22 @@ public class PasswordGenTest {
         String tempPassword = PasswordGen.generatePassword(8, 16);
         assertTrue(tempPassword.length() != 0);
     }
+
+    @Test
+    public void testGeneratePasswordWithMinGreaterThanMax() {
+        Exception exception = assertThrows(IllegalArgumentException.class, () -> PasswordGen.generatePassword(12, 8));
+        assertEquals("Incorrect length parameters: minLength must be <= maxLength and both must be > 0", exception.getMessage());
+    }
+
+    @Test
+    public void testGeneratePasswordWithNegativeLength() {
+        Exception exception = assertThrows(IllegalArgumentException.class, () -> PasswordGen.generatePassword(-5, 10));
+        assertEquals("Incorrect length parameters: minLength must be <= maxLength and both must be > 0", exception.getMessage());
+    }
+
+    @Test
+    public void testGeneratePasswordWithZeroLength() {
+        Exception exception = assertThrows(IllegalArgumentException.class, () -> PasswordGen.generatePassword(0, 0));
+        assertEquals("Incorrect length parameters: minLength must be <= maxLength and both must be > 0", exception.getMessage());
+    }
 }