style: enable MethodName in CheckStyle (#5182)

enabled: MethodName in CheckStyle
This commit is contained in:
Godwill Christopher
2024-05-27 01:06:06 -06:00
committed by GitHub
parent ea4dc15a24
commit 295e7436b1
53 changed files with 225 additions and 225 deletions

View File

@ -12,12 +12,12 @@ public class PowerSum {
private int sum = 0;
public int powSum(int N, int X) {
Sum(N, X, 1);
sum(N, X, 1);
return count;
}
// here i is the natural number which will be raised by X and added in sum.
public void Sum(int N, int X, int i) {
public void sum(int N, int X, int i) {
// if sum is equal to N that is one of our answer and count is increased.
if (sum == N) {
count++;
@ -26,7 +26,7 @@ public class PowerSum {
// result is less than N.
else if (sum + power(i, X) <= N) {
sum += power(i, X);
Sum(N, X, i + 1);
sum(N, X, i + 1);
// backtracking and removing the number added last since no possible combination is
// there with it.
sum -= power(i, X);
@ -34,7 +34,7 @@ public class PowerSum {
if (power(i, X) < N) {
// calling the sum function with next natural number after backtracking if when it is
// raised to X is still less than X.
Sum(N, X, i + 1);
sum(N, X, i + 1);
}
}

View File

@ -106,7 +106,7 @@ public class DES {
return subKeys;
}
private String XOR(String a, String b) {
private String xOR(String a, String b) {
int i;
int l = a.length();
StringBuilder xor = new StringBuilder();
@ -143,7 +143,7 @@ public class DES {
for (i = 0; i < 48; i++) {
expandedKey.append(messageBlock.charAt(EXPANSION[i] - 1));
}
String mixedKey = XOR(expandedKey.toString(), key);
String mixedKey = xOR(expandedKey.toString(), key);
StringBuilder substitutedString = new StringBuilder();
// Let us now use the s-boxes to transform each 6 bit (length here) block to 4 bits
@ -175,7 +175,7 @@ public class DES {
// Iterate 16 times
for (i = 0; i < 16; i++) {
String Ln = R0; // Previous Right block
String Rn = XOR(L0, feistel(R0, keys[i]));
String Rn = xOR(L0, feistel(R0, keys[i]));
L0 = Ln;
R0 = Rn;
}

View File

@ -91,7 +91,7 @@ public class LeftistHeap {
}
// Returns and removes the minimum element in the heap
public int extract_min() {
public int extractMin() {
// If is empty return -1
if (isEmpty()) return -1;
@ -101,17 +101,17 @@ public class LeftistHeap {
}
// Function returning a list of an in order traversal of the data structure
public ArrayList<Integer> in_order() {
public ArrayList<Integer> inOrder() {
ArrayList<Integer> lst = new ArrayList<>();
in_order_aux(root, lst);
inOrderAux(root, lst);
return new ArrayList<>(lst);
}
// Auxiliary function for in_order
private void in_order_aux(Node n, ArrayList<Integer> lst) {
private void inOrderAux(Node n, ArrayList<Integer> lst) {
if (n == null) return;
in_order_aux(n.left, lst);
inOrderAux(n.left, lst);
lst.add(n.element);
in_order_aux(n.right, lst);
inOrderAux(n.right, lst);
}
}

View File

@ -25,10 +25,10 @@ public class GenericTree {
private final Node root;
public GenericTree() { // Constructor
Scanner scn = new Scanner(System.in);
root = create_treeG(null, 0, scn);
root = createTreeG(null, 0, scn);
}
private Node create_treeG(Node node, int childIndex, Scanner scanner) {
private Node createTreeG(Node node, int childIndex, Scanner scanner) {
// display
if (node == null) {
System.out.println("Enter root's data");
@ -41,7 +41,7 @@ public class GenericTree {
System.out.println("number of children");
int number = scanner.nextInt();
for (int i = 0; i < number; i++) {
Node child = create_treeG(node, i, scanner);
Node child = createTreeG(node, i, scanner);
node.child.add(child);
}
return node;
@ -51,17 +51,17 @@ public class GenericTree {
* Function to display the generic tree
*/
public void display() { // Helper function
display_1(root);
display1(root);
}
private void display_1(Node parent) {
private void display1(Node parent) {
System.out.print(parent.data + "=>");
for (int i = 0; i < parent.child.size(); i++) {
System.out.print(parent.child.get(i).data + " ");
}
System.out.println(".");
for (int i = 0; i < parent.child.size(); i++) {
display_1(parent.child.get(i));
display1(parent.child.get(i));
}
}

View File

@ -8,7 +8,7 @@ final class NearestRightKey {
}
public static void main(String[] args) {
NRKTree root = BuildTree();
NRKTree root = buildTree();
Scanner sc = new Scanner(System.in);
System.out.print("Enter first number: ");
int inputX0 = sc.nextInt();
@ -17,7 +17,7 @@ final class NearestRightKey {
sc.close();
}
public static NRKTree BuildTree() {
public static NRKTree buildTree() {
int randomX = ThreadLocalRandom.current().nextInt(0, 100 + 1);
NRKTree root = new NRKTree(null, null, randomX);

View File

@ -10,7 +10,7 @@ public final class KadaneAlgorithm {
private KadaneAlgorithm() {
}
public static boolean max_Sum(int[] a, int predicted_answer) {
public static boolean maxSum(int[] a, int predicted_answer) {
int sum = a[0];
int running_sum = 0;
for (int k : a) {

View File

@ -16,7 +16,7 @@ public final class LongestAlternatingSubsequence {
}
/* Function to return longest alternating subsequence length*/
static int AlternatingLength(int[] arr, int n) {
static int alternatingLength(int[] arr, int n) {
/*
las[i][0] = Length of the longest
@ -68,6 +68,6 @@ public final class LongestAlternatingSubsequence {
int[] arr = {10, 22, 9, 33, 49, 50, 31, 60};
int n = arr.length;
System.out.println("Length of Longest "
+ "alternating subsequence is " + AlternatingLength(arr, n));
+ "alternating subsequence is " + alternatingLength(arr, n));
}
}

View File

@ -20,7 +20,7 @@ public final class LongestIncreasingSubsequence {
return r;
}
public static int LIS(int[] array) {
public static int lis(int[] array) {
int N = array.length;
if (N == 0) {
return 0;

View File

@ -12,14 +12,14 @@ public final class LongestPalindromicSubsequence {
String a = "BBABCBCAB";
String b = "BABCBAB";
String aLPS = LPS(a);
String bLPS = LPS(b);
String aLPS = lps(a);
String bLPS = lps(b);
System.out.println(a + " => " + aLPS);
System.out.println(b + " => " + bLPS);
}
public static String LPS(String original) throws IllegalArgumentException {
public static String lps(String original) throws IllegalArgumentException {
StringBuilder reverse = new StringBuilder(original);
reverse = reverse.reverse();
return recursiveLPS(original, reverse.toString());

View File

@ -11,14 +11,14 @@ public final class LongestPalindromicSubstring {
String a = "babad";
String b = "cbbd";
String aLPS = LPS(a);
String bLPS = LPS(b);
String aLPS = lps(a);
String bLPS = lps(b);
System.out.println(a + " => " + aLPS);
System.out.println(b + " => " + bLPS);
}
private static String LPS(String input) {
private static String lps(String input) {
if (input == null || input.length() == 0) {
return input;
}

View File

@ -10,7 +10,7 @@ public final class MatrixChainRecursiveTopDownMemoisation {
private MatrixChainRecursiveTopDownMemoisation() {
}
static int Memoized_Matrix_Chain(int[] p) {
static int memoizedMatrixChain(int[] p) {
int n = p.length;
int[][] m = new int[n][n];
for (int i = 0; i < n; i++) {
@ -18,10 +18,10 @@ public final class MatrixChainRecursiveTopDownMemoisation {
m[i][j] = Integer.MAX_VALUE;
}
}
return Lookup_Chain(m, p, 1, n - 1);
return lookupChain(m, p, 1, n - 1);
}
static int Lookup_Chain(int[][] m, int[] p, int i, int j) {
static int lookupChain(int[][] m, int[] p, int i, int j) {
if (i == j) {
m[i][j] = 0;
return m[i][j];
@ -30,7 +30,7 @@ public final class MatrixChainRecursiveTopDownMemoisation {
return m[i][j];
} else {
for (int k = i; k < j; k++) {
int q = Lookup_Chain(m, p, i, k) + Lookup_Chain(m, p, k + 1, j) + (p[i - 1] * p[k] * p[j]);
int q = lookupChain(m, p, i, k) + lookupChain(m, p, k + 1, j) + (p[i - 1] * p[k] * p[j]);
if (q < m[i][j]) {
m[i][j] = q;
}
@ -43,6 +43,6 @@ public final class MatrixChainRecursiveTopDownMemoisation {
// respectively output should be Minimum number of multiplications is 38
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5};
System.out.println("Minimum number of multiplications is " + Memoized_Matrix_Chain(arr));
System.out.println("Minimum number of multiplications is " + memoizedMatrixChain(arr));
}
}

View File

@ -16,22 +16,22 @@ public final class WineProblem {
// Method 1: Using Recursion
// Time Complexity=0(2^N) Space Complexity=Recursion extra space
public static int WPRecursion(int[] arr, int si, int ei) {
public static int wpRecursion(int[] arr, int si, int ei) {
int n = arr.length;
int year = (n - (ei - si + 1)) + 1;
if (si == ei) {
return arr[si] * year;
}
int start = WPRecursion(arr, si + 1, ei) + arr[si] * year;
int end = WPRecursion(arr, si, ei - 1) + arr[ei] * year;
int start = wpRecursion(arr, si + 1, ei) + arr[si] * year;
int end = wpRecursion(arr, si, ei - 1) + arr[ei] * year;
return Math.max(start, end);
}
// Method 2: Top-Down DP(Memoization)
// Time Complexity=0(N*N) Space Complexity=0(N*N)+Recursion extra space
public static int WPTD(int[] arr, int si, int ei, int[][] strg) {
public static int wptd(int[] arr, int si, int ei, int[][] strg) {
int n = arr.length;
int year = (n - (ei - si + 1)) + 1;
if (si == ei) {
@ -41,8 +41,8 @@ public final class WineProblem {
if (strg[si][ei] != 0) {
return strg[si][ei];
}
int start = WPTD(arr, si + 1, ei, strg) + arr[si] * year;
int end = WPTD(arr, si, ei - 1, strg) + arr[ei] * year;
int start = wptd(arr, si + 1, ei, strg) + arr[si] * year;
int end = wptd(arr, si, ei - 1, strg) + arr[ei] * year;
int ans = Math.max(start, end);
@ -53,7 +53,7 @@ public final class WineProblem {
// Method 3: Bottom-Up DP(Tabulation)
// Time Complexity=0(N*N/2)->0(N*N) Space Complexity=0(N*N)
public static int WPBU(int[] arr) {
public static int wpbu(int[] arr) {
int n = arr.length;
int[][] strg = new int[n][n];
@ -76,9 +76,9 @@ public final class WineProblem {
public static void main(String[] args) {
int[] arr = {2, 3, 5, 1, 4};
System.out.println("Method 1: " + WPRecursion(arr, 0, arr.length - 1));
System.out.println("Method 2: " + WPTD(arr, 0, arr.length - 1, new int[arr.length][arr.length]));
System.out.println("Method 3: " + WPBU(arr));
System.out.println("Method 1: " + wpRecursion(arr, 0, arr.length - 1));
System.out.println("Method 2: " + wptd(arr, 0, arr.length - 1, new int[arr.length][arr.length]));
System.out.println("Method 3: " + wpbu(arr));
}
}
// Memoization vs Tabulation : https://www.geeksforgeeks.org/tabulation-vs-memoization/

View File

@ -10,7 +10,7 @@ public final class SquareRootWithBabylonianMethod {
* @param num contains elements
* @return the square root of num
*/
public static float square_Root(float num) {
public static float squareRoot(float num) {
float a = num;
float b = 1;
double e = 0.000001;

View File

@ -11,7 +11,7 @@ public final class TrinomialTriangle {
private TrinomialTriangle() {
}
public static int TrinomialValue(int n, int k) {
public static int trinomialValue(int n, int k) {
if (n == 0 && k == 0) {
return 1;
}
@ -20,17 +20,17 @@ public final class TrinomialTriangle {
return 0;
}
return (TrinomialValue(n - 1, k - 1) + TrinomialValue(n - 1, k) + TrinomialValue(n - 1, k + 1));
return (trinomialValue(n - 1, k - 1) + trinomialValue(n - 1, k) + trinomialValue(n - 1, k + 1));
}
public static void printTrinomial(int n) {
for (int i = 0; i < n; i++) {
for (int j = -i; j <= 0; j++) {
System.out.print(TrinomialValue(i, j) + " ");
System.out.print(trinomialValue(i, j) + " ");
}
for (int j = 1; j <= i; j++) {
System.out.print(TrinomialValue(i, j) + " ");
System.out.print(trinomialValue(i, j) + " ");
}
System.out.println();

View File

@ -24,13 +24,13 @@ public class ThreeSumProblem {
arr[i] = scan.nextInt();
}
ThreeSumProblem th = new ThreeSumProblem();
System.out.println("Brute Force Approach\n" + (th.BruteForce(arr, ts)) + "\n");
System.out.println("Two Pointer Approach\n" + (th.TwoPointer(arr, ts)) + "\n");
System.out.println("Hashmap Approach\n" + (th.Hashmap(arr, ts)));
System.out.println("Brute Force Approach\n" + (th.bruteForce(arr, ts)) + "\n");
System.out.println("Two Pointer Approach\n" + (th.twoPointer(arr, ts)) + "\n");
System.out.println("Hashmap Approach\n" + (th.hashMap(arr, ts)));
scan.close();
}
public List<List<Integer>> BruteForce(int[] nums, int target) {
public List<List<Integer>> bruteForce(int[] nums, int target) {
List<List<Integer>> arr = new ArrayList<List<Integer>>();
for (int i = 0; i < nums.length; i++) {
@ -51,7 +51,7 @@ public class ThreeSumProblem {
return arr;
}
public List<List<Integer>> TwoPointer(int[] nums, int target) {
public List<List<Integer>> twoPointer(int[] nums, int target) {
Arrays.sort(nums);
List<List<Integer>> arr = new ArrayList<List<Integer>>();
int start = 0;
@ -81,7 +81,7 @@ public class ThreeSumProblem {
return new ArrayList<List<Integer>>(set);
}
public List<List<Integer>> Hashmap(int[] nums, int target) {
public List<List<Integer>> hashMap(int[] nums, int target) {
Arrays.sort(nums);
Set<List<Integer>> ts = new HashSet<>();
HashMap<Integer, Integer> hm = new HashMap<>();

View File

@ -11,7 +11,7 @@ public final class CountChar {
* @return number of character in the specified string
*/
public static int CountCharacters(String str) {
public static int countCharacters(String str) {
return str.replaceAll("\\s", "").length();
}
}

View File

@ -13,11 +13,11 @@ public final class KMP {
public static void main(String[] args) {
final String haystack = "AAAAABAAABA"; // This is the full string
final String needle = "AAAA"; // This is the substring that we want to find
KMPmatcher(haystack, needle);
kmpMatcher(haystack, needle);
}
// find the starting index in string haystack[] that matches the search word P[]
public static void KMPmatcher(final String haystack, final String needle) {
public static void kmpMatcher(final String haystack, final String needle) {
final int m = haystack.length();
final int n = needle.length();
final int[] pi = computePrefixFunction(needle);

View File

@ -33,7 +33,7 @@ public final class KochSnowflake {
ArrayList<Vector2> vectors = new ArrayList<Vector2>();
vectors.add(new Vector2(0, 0));
vectors.add(new Vector2(1, 0));
ArrayList<Vector2> result = Iterate(vectors, 1);
ArrayList<Vector2> result = iterate(vectors, 1);
assert result.get(0).x == 0;
assert result.get(0).y == 0;
@ -54,7 +54,7 @@ public final class KochSnowflake {
int imageWidth = 600;
double offsetX = imageWidth / 10.;
double offsetY = imageWidth / 3.7;
BufferedImage image = GetKochSnowflake(imageWidth, 5);
BufferedImage image = getKochSnowflake(imageWidth, 5);
// The background should be white
assert image.getRGB(0, 0) == new Color(255, 255, 255).getRGB();
@ -80,10 +80,10 @@ public final class KochSnowflake {
* @param steps The number of iterations.
* @return The transformed vectors after the iteration-steps.
*/
public static ArrayList<Vector2> Iterate(ArrayList<Vector2> initialVectors, int steps) {
public static ArrayList<Vector2> iterate(ArrayList<Vector2> initialVectors, int steps) {
ArrayList<Vector2> vectors = initialVectors;
for (int i = 0; i < steps; i++) {
vectors = IterationStep(vectors);
vectors = iterationStep(vectors);
}
return vectors;
@ -96,7 +96,7 @@ public final class KochSnowflake {
* @param steps The number of iterations.
* @return The image of the rendered Koch snowflake.
*/
public static BufferedImage GetKochSnowflake(int imageWidth, int steps) {
public static BufferedImage getKochSnowflake(int imageWidth, int steps) {
if (imageWidth <= 0) {
throw new IllegalArgumentException("imageWidth should be greater than zero");
}
@ -111,8 +111,8 @@ public final class KochSnowflake {
initialVectors.add(vector2);
initialVectors.add(vector3);
initialVectors.add(vector1);
ArrayList<Vector2> vectors = Iterate(initialVectors, steps);
return GetImage(vectors, imageWidth, imageWidth);
ArrayList<Vector2> vectors = iterate(initialVectors, steps);
return getImage(vectors, imageWidth, imageWidth);
}
/**
@ -125,7 +125,7 @@ public final class KochSnowflake {
* applied.
* @return The transformed vectors after the iteration-step.
*/
private static ArrayList<Vector2> IterationStep(ArrayList<Vector2> vectors) {
private static ArrayList<Vector2> iterationStep(ArrayList<Vector2> vectors) {
ArrayList<Vector2> newVectors = new ArrayList<Vector2>();
for (int i = 0; i < vectors.size() - 1; i++) {
Vector2 startVector = vectors.get(i);
@ -149,7 +149,7 @@ public final class KochSnowflake {
* @param imageHeight The height of the rendered image.
* @return The image of the rendered edges.
*/
private static BufferedImage GetImage(ArrayList<Vector2> vectors, int imageWidth, int imageHeight) {
private static BufferedImage getImage(ArrayList<Vector2> vectors, int imageWidth, int imageHeight) {
BufferedImage image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = image.createGraphics();

View File

@ -20,7 +20,7 @@ public final class LineSweep {
* param = ranges : Array of range[start,end]
* return Maximum Endpoint
*/
public static int FindMaximumEndPoint(int[][] ranges) {
public static int findMaximumEndPoint(int[][] ranges) {
Arrays.sort(ranges, Comparator.comparingInt(a -> a[1]));
return ranges[ranges.length - 1][1];
}
@ -32,7 +32,7 @@ public final class LineSweep {
*/
public static boolean isOverlap(int[][] ranges) {
int maximumEndPoint = FindMaximumEndPoint(ranges);
int maximumEndPoint = findMaximumEndPoint(ranges);
Arrays.sort(ranges, Comparator.comparingInt(a -> a[0]));
int[] numberLine = new int[maximumEndPoint + 2];
for (int[] range : ranges) {

View File

@ -12,7 +12,7 @@ public final class BinarySearch2dArray {
private BinarySearch2dArray() {
}
static int[] BinarySearch(int[][] arr, int target) {
static int[] binarySearch(int[][] arr, int target) {
int rowCount = arr.length;
int colCount = arr[0].length;

View File

@ -2,7 +2,7 @@ package com.thealgorithms.searches;
class KMPSearch {
int KMPSearch(String pat, String txt) {
int kmpSearch(String pat, String txt) {
int M = pat.length();
int N = txt.length();

View File

@ -15,7 +15,7 @@ public final class OrderAgnosticBinarySearch {
private OrderAgnosticBinarySearch() {
}
static int BinSearchAlgo(int[] arr, int start, int end, int target) {
static int binSearchAlgo(int[] arr, int start, int end, int target) {
// Checking whether the given array is ascending order
boolean AscOrd = arr[start] < arr[end];

View File

@ -13,14 +13,14 @@ public class DutchNationalFlagSort implements SortAlgorithm {
@Override
public <T extends Comparable<T>> T[] sort(T[] unsorted) {
return dutch_national_flag_sort(unsorted, unsorted[(int) Math.ceil((unsorted.length) / 2.0) - 1]);
return dutchNationalFlagSort(unsorted, unsorted[(int) Math.ceil((unsorted.length) / 2.0) - 1]);
}
public <T extends Comparable<T>> T[] sort(T[] unsorted, T intendedMiddle) {
return dutch_national_flag_sort(unsorted, intendedMiddle);
return dutchNationalFlagSort(unsorted, intendedMiddle);
}
private <T extends Comparable<T>> T[] dutch_national_flag_sort(T[] arr, T intendedMiddle) {
private <T extends Comparable<T>> T[] dutchNationalFlagSort(T[] arr, T intendedMiddle) {
int i = 0;
int j = 0;
int k = arr.length - 1;

View File

@ -10,21 +10,21 @@ public final class MergeSortNoExtraSpace {
private MergeSortNoExtraSpace() {
}
public static void call_merge_sort(int[] a, int n) {
public static void callMergeSort(int[] a, int n) {
int maxele = Arrays.stream(a).max().getAsInt() + 1;
merge_sort(a, 0, n - 1, maxele);
mergeSort(a, 0, n - 1, maxele);
}
public static void merge_sort(int[] a, int start, int end, int maxele) { // this function divides the array into 2 halves
public static void mergeSort(int[] a, int start, int end, int maxele) { // this function divides the array into 2 halves
if (start < end) {
int mid = (start + end) / 2;
merge_sort(a, start, mid, maxele);
merge_sort(a, mid + 1, end, maxele);
implement_merge_sort(a, start, mid, end, maxele);
mergeSort(a, start, mid, maxele);
mergeSort(a, mid + 1, end, maxele);
implementMergeSort(a, start, mid, end, maxele);
}
}
public static void implement_merge_sort(int[] a, int start, int mid, int end,
public static void implementMergeSort(int[] a, int start, int mid, int end,
int maxele) { // implementation of mergesort
int i = start;
int j = mid + 1;
@ -64,7 +64,7 @@ public final class MergeSortNoExtraSpace {
for (int i = 0; i < n; i++) {
a[i] = inp.nextInt();
}
call_merge_sort(a, n);
callMergeSort(a, n);
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}

View File

@ -14,14 +14,14 @@ public class LeftistHeapTest {
heap.insert(2);
heap.insert(3);
heap.insert(1);
heap.in_order();
Assertions.assertTrue(heap.in_order().toString().equals("[6, 2, 3, 1]"));
Assertions.assertTrue(heap.extract_min() == 1);
Assertions.assertTrue(heap.in_order().toString().equals("[6, 2, 3]"));
heap.inOrder();
Assertions.assertTrue(heap.inOrder().toString().equals("[6, 2, 3, 1]"));
Assertions.assertTrue(heap.extractMin() == 1);
Assertions.assertTrue(heap.inOrder().toString().equals("[6, 2, 3]"));
heap.insert(8);
heap.insert(12);
heap.insert(4);
Assertions.assertTrue(heap.in_order().toString().equals("[8, 3, 12, 2, 6, 4]"));
Assertions.assertTrue(heap.inOrder().toString().equals("[8, 3, 12, 2, 6, 4]"));
heap.clear();
Assertions.assertTrue(heap.isEmpty());
}

View File

@ -166,7 +166,7 @@ public class SinglyLinkedListTest {
}
// This is Recursive Reverse List Test
// Test to check whether the method reverseListRec() works fine
void RecursiveReverseList() {
void recursiveReverseList() {
// Create a linked list: 1 -> 2 -> 3 -> 4 -> 5
SinglyLinkedList list = createSampleList(5);
@ -182,7 +182,7 @@ public class SinglyLinkedListTest {
}
@Test
void RecursiveReverseListNullPointer() {
void recursiveReverseListNullPointer() {
// Create an empty linked list
SinglyLinkedList list = new SinglyLinkedList();
Node first = list.getHead();
@ -195,7 +195,7 @@ public class SinglyLinkedListTest {
}
@Test
void RecursiveReverseListTest() {
void recursiveReverseListTest() {
// Create a linked list with values from 1 to 20
SinglyLinkedList list = createSampleList(20);

View File

@ -12,7 +12,7 @@ class StrassenMatrixMultiplicationTest {
// and has to be a Square Matrix
@Test
public void StrassenMatrixMultiplicationTest2x2() {
public void strassenMatrixMultiplicationTest2x2() {
int[][] A = {{1, 2}, {3, 4}};
int[][] B = {{5, 6}, {7, 8}};
int[][] expResult = {{19, 22}, {43, 50}};
@ -21,7 +21,7 @@ class StrassenMatrixMultiplicationTest {
}
@Test
void StrassenMatrixMultiplicationTest4x4() {
void strassenMatrixMultiplicationTest4x4() {
int[][] A = {{1, 2, 5, 4}, {9, 3, 0, 6}, {4, 6, 3, 1}, {0, 2, 0, 6}};
int[][] B = {{1, 0, 4, 1}, {1, 2, 0, 2}, {0, 3, 1, 3}, {1, 8, 1, 2}};
int[][] expResult = {{7, 51, 13, 28}, {18, 54, 42, 27}, {11, 29, 20, 27}, {8, 52, 6, 16}};
@ -30,7 +30,7 @@ class StrassenMatrixMultiplicationTest {
}
@Test
void StrassenMatrixMultiplicationTestNegetiveNumber4x4() {
void strassenMatrixMultiplicationTestNegativeNumber4x4() {
int[][] A = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}};
int[][] B = {{1, -2, -3, 4}, {4, -3, -2, 1}, {5, -6, -7, 8}, {8, -7, -6, -5}};
int[][] expResult = {{56, -54, -52, 10}, {128, -126, -124, 42}, {200, -198, -196, 74}, {272, -270, -268, 106}};

View File

@ -9,7 +9,7 @@ public class KnapsackMemoizationTest {
KnapsackMemoization knapsackMemoization = new KnapsackMemoization();
@Test
void Test1() {
void test1() {
int[] weight = {1, 3, 4, 5};
int[] value = {1, 4, 5, 7};
int capacity = 10;
@ -17,7 +17,7 @@ public class KnapsackMemoizationTest {
}
@Test
void Test2() {
void test2() {
int[] weight = {95, 4, 60, 32, 23, 72, 80, 62, 65, 46};
int[] value = {55, 10, 47, 5, 4, 50, 8, 61, 85, 87};
int capacity = 269;
@ -25,7 +25,7 @@ public class KnapsackMemoizationTest {
}
@Test
void Test3() {
void test3() {
int[] weight = {10, 20, 30};
int[] value = {60, 100, 120};
int capacity = 50;

View File

@ -42,7 +42,7 @@ public class LongestIncreasingSubsequenceTests {
{3, new int[] {1, 1, 2, 2, 2, 3, 3, 3, 3}},
};
final List<IntArrayToInt> methods = Arrays.asList(LongestIncreasingSubsequence::LIS, LongestIncreasingSubsequence::findLISLen);
final List<IntArrayToInt> methods = Arrays.asList(LongestIncreasingSubsequence::lis, LongestIncreasingSubsequence::findLISLen);
return Stream.of(testData).flatMap(input -> methods.stream().map(method -> Arguments.of(input[0], input[1], method)));
}

View File

@ -8,52 +8,52 @@ import org.junit.jupiter.api.Test;
public class UniquePathsTests {
@Test
public void testUniquePaths_3x3() {
public void testUniquePaths3x3() {
assertEquals(6, UniquePaths.uniquePaths(3, 3));
}
@Test
public void testUniquePaths_1x1() {
public void testUniquePaths1x1() {
assertEquals(1, UniquePaths.uniquePaths(1, 1));
}
@Test
public void testUniquePaths_3x7() {
public void testUniquePaths3x7() {
assertEquals(28, UniquePaths.uniquePaths(3, 7));
}
@Test
public void testUniquePaths_7x3() {
public void testUniquePaths7x3() {
assertEquals(28, UniquePaths.uniquePaths(7, 3));
}
@Test
public void testUniquePaths_100x100() {
public void testUniquePaths100x100() {
assertThrows(ArithmeticException.class, () -> UniquePaths.uniquePaths(100, 100));
}
@Test
public void testUniquePaths2_3x3() {
public void testUniquePathsII3x3() {
assertEquals(6, UniquePaths.uniquePaths2(3, 3));
}
@Test
public void testUniquePaths2_1x1() {
public void testUniquePathsII1x1() {
assertEquals(1, UniquePaths.uniquePaths2(1, 1));
}
@Test
public void testUniquePaths2_3x7() {
public void testUniquePathsII3x7() {
assertEquals(28, UniquePaths.uniquePaths2(3, 7));
}
@Test
public void testUniquePaths2_7x3() {
public void testUniquePathsII7x3() {
assertEquals(28, UniquePaths.uniquePaths2(7, 3));
}
@Test
public void testUniquePaths2_100x100() {
public void testUniquePathsII100x100() {
assertThrows(ArithmeticException.class, () -> UniquePaths.uniquePaths2(100, 100));
}
}

View File

@ -8,25 +8,25 @@ public class AverageTest {
private static final double SMALL_VALUE = 0.00001d;
@Test
public void testAverage_double_12() {
public void testAverageDouble12() {
double[] numbers = {3d, 6d, 9d, 12d, 15d, 18d, 21d};
Assertions.assertEquals(12d, Average.average(numbers), SMALL_VALUE);
}
@Test
public void testAverage_double_20() {
public void testAverageDouble20() {
double[] numbers = {5d, 10d, 15d, 20d, 25d, 30d, 35d};
Assertions.assertEquals(20d, Average.average(numbers), SMALL_VALUE);
}
@Test
public void testAverage_double_4_5() {
public void testAverageDouble() {
double[] numbers = {1d, 2d, 3d, 4d, 5d, 6d, 7d, 8d};
Assertions.assertEquals(4.5d, Average.average(numbers), SMALL_VALUE);
}
@Test
public void testAverage_int_5() {
public void testAverageInt() {
int[] numbers = {2, 4, 10};
Assertions.assertEquals(5, Average.average(numbers));
}

View File

@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test;
public class PythagoreanTripleTest {
@Test
public void Testpythagoreantriple() {
public void testPythagoreanTriple() {
assertTrue(PythagoreanTriple.isPythagTriple(3, 4, 5));
assertTrue(PythagoreanTriple.isPythagTriple(6, 8, 10));
assertTrue(PythagoreanTriple.isPythagTriple(9, 12, 15));

View File

@ -7,21 +7,21 @@ public class SquareRootwithBabylonianMethodTest {
@Test
void testfor4() {
Assertions.assertEquals(2, SquareRootWithBabylonianMethod.square_Root(4));
Assertions.assertEquals(2, SquareRootWithBabylonianMethod.squareRoot(4));
}
@Test
void testfor1() {
Assertions.assertEquals(1, SquareRootWithBabylonianMethod.square_Root(1));
Assertions.assertEquals(1, SquareRootWithBabylonianMethod.squareRoot(1));
}
@Test
void testfor2() {
Assertions.assertEquals(1.4142135381698608, SquareRootWithBabylonianMethod.square_Root(2));
Assertions.assertEquals(1.4142135381698608, SquareRootWithBabylonianMethod.squareRoot(2));
}
@Test
void testfor625() {
Assertions.assertEquals(25, SquareRootWithBabylonianMethod.square_Root(625));
Assertions.assertEquals(25, SquareRootWithBabylonianMethod.squareRoot(625));
}
}

View File

@ -11,6 +11,6 @@ class CountCharTest {
String input = "12345";
int expectedValue = 5;
assertEquals(expectedValue, CountChar.CountCharacters(input));
assertEquals(expectedValue, CountChar.countCharacters(input));
}
}

View File

@ -10,48 +10,48 @@ public class KadaneAlogrithmTest {
@Test
void testForOneElement() {
int[] a = {-1};
assertTrue(KadaneAlgorithm.max_Sum(a, -1));
assertTrue(KadaneAlgorithm.maxSum(a, -1));
}
@Test
void testForTwoElements() {
int[] a = {-2, 1};
assertTrue(KadaneAlgorithm.max_Sum(a, 1));
assertTrue(KadaneAlgorithm.maxSum(a, 1));
}
@Test
void testForThreeElements() {
int[] a = {5, 3, 12};
assertTrue(KadaneAlgorithm.max_Sum(a, 20));
assertTrue(KadaneAlgorithm.maxSum(a, 20));
}
@Test
void testForFourElements() {
int[] a = {-1, -3, -7, -4};
assertTrue(KadaneAlgorithm.max_Sum(a, -1));
assertTrue(KadaneAlgorithm.maxSum(a, -1));
}
@Test
void testForFiveElements() {
int[] a = {4, 5, 3, 0, 2};
assertTrue(KadaneAlgorithm.max_Sum(a, 14));
assertTrue(KadaneAlgorithm.maxSum(a, 14));
}
@Test
void testForSixElements() {
int[] a = {-43, -45, 47, 12, 87, -13};
assertTrue(KadaneAlgorithm.max_Sum(a, 146));
assertTrue(KadaneAlgorithm.maxSum(a, 146));
}
@Test
void testForSevenElements() {
int[] a = {9, 8, 2, 23, 13, 6, 7};
assertTrue(KadaneAlgorithm.max_Sum(a, 68));
assertTrue(KadaneAlgorithm.maxSum(a, 68));
}
@Test
void testForEightElements() {
int[] a = {9, -5, -5, -2, 4, 5, 0, 1};
assertTrue(KadaneAlgorithm.max_Sum(a, 10));
assertTrue(KadaneAlgorithm.maxSum(a, 10));
}
}

View File

@ -25,6 +25,6 @@ public class LineSweepTest {
@Test
void testForMaximumEndPoint() {
int[][] arr = {{10, 20}, {1, 100}, {14, 16}, {1, 8}};
assertEquals(100, LineSweep.FindMaximumEndPoint(arr));
assertEquals(100, LineSweep.findMaximumEndPoint(arr));
}
}

View File

@ -6,27 +6,27 @@ import org.junit.jupiter.api.Test;
public class MaximumSumOfDistinctSubarraysWithLengthKTest {
@Test
public void SampleTestCase1() {
public void sampleTestCase1() {
assertEquals(15, MaximumSumOfDistinctSubarraysWithLengthK.maximumSubarraySum(3, 1, 5, 4, 2, 9, 9, 9));
}
@Test
public void SampleTestCase2() {
public void sampleTestCase2() {
assertEquals(0, MaximumSumOfDistinctSubarraysWithLengthK.maximumSubarraySum(3, 4, 4, 4));
}
@Test
public void SampleTestCase3() {
public void sampleTestCase3() {
assertEquals(12, MaximumSumOfDistinctSubarraysWithLengthK.maximumSubarraySum(3, 9, 9, 9, 1, 2, 3));
}
@Test
public void EdgeCase1() {
public void edgeCase1() {
assertEquals(0, MaximumSumOfDistinctSubarraysWithLengthK.maximumSubarraySum(0, 9, 9, 9));
}
@Test
public void EdgeCase2() {
public void edgeCase2() {
assertEquals(0, MaximumSumOfDistinctSubarraysWithLengthK.maximumSubarraySum(5, 9, 9, 9));
}
}

View File

@ -74,7 +74,7 @@ class SJFSchedulingTest {
}
@Test
void schedulingOf_TwoProcesses() {
void schedulingOfTwoProcesses() {
initialisation0();
SJFScheduling a = new SJFScheduling(process);
a.scheduleProcesses();
@ -83,7 +83,7 @@ class SJFSchedulingTest {
}
@Test
void schedulingOfA_ShortestJobArrivingLast() {
void schedulingOfAShortestJobArrivingLast() {
initialisation2();
SJFScheduling a = new SJFScheduling(process);
a.scheduleProcesses();
@ -92,7 +92,7 @@ class SJFSchedulingTest {
assertEquals("2", a.schedule.get(2));
}
@Test
void scheduling_WithProcessesNotComingBackToBack() {
void schedulingWithProcessesNotComingBackToBack() {
initialisation3();
SJFScheduling a = new SJFScheduling(process);
a.scheduleProcesses();
@ -101,7 +101,7 @@ class SJFSchedulingTest {
assertEquals("3", a.schedule.get(2));
}
@Test
void schedulingOf_nothing() {
void schedulingOfNothing() {
process = new ArrayList<>();
SJFScheduling a = new SJFScheduling(process);
a.scheduleProcesses();

View File

@ -19,7 +19,7 @@ class SRTFSchedulingTest {
}
@Test
public void Constructor() {
public void constructor() {
initialization();
SRTFScheduling s = new SRTFScheduling(processes);
assertEquals(3, s.processes.get(0).getBurstTime());

View File

@ -10,11 +10,11 @@ public class BinarySearch2dArrayTest {
@Test
// valid test case
public void BinarySearch2dArrayTestMiddle() {
public void binarySearch2dArrayTestMiddle() {
int[][] arr = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
int target = 6;
int[] ans = BinarySearch2dArray.BinarySearch(arr, target);
int[] ans = BinarySearch2dArray.binarySearch(arr, target);
System.out.println(Arrays.toString(ans));
assertEquals(1, ans[0]);
assertEquals(1, ans[1]);
@ -22,11 +22,11 @@ public class BinarySearch2dArrayTest {
@Test
// valid test case
public void BinarySearch2dArrayTestMiddleSide() {
public void binarySearch2dArrayTestMiddleSide() {
int[][] arr = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
int target = 8;
int[] ans = BinarySearch2dArray.BinarySearch(arr, target);
int[] ans = BinarySearch2dArray.binarySearch(arr, target);
System.out.println(Arrays.toString(ans));
assertEquals(1, ans[0]);
assertEquals(3, ans[1]);
@ -34,11 +34,11 @@ public class BinarySearch2dArrayTest {
@Test
// valid test case
public void BinarySearch2dArrayTestUpper() {
public void binarySearch2dArrayTestUpper() {
int[][] arr = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
int target = 2;
int[] ans = BinarySearch2dArray.BinarySearch(arr, target);
int[] ans = BinarySearch2dArray.binarySearch(arr, target);
System.out.println(Arrays.toString(ans));
assertEquals(0, ans[0]);
assertEquals(1, ans[1]);
@ -46,11 +46,11 @@ public class BinarySearch2dArrayTest {
@Test
// valid test case
public void BinarySearch2dArrayTestUpperSide() {
public void binarySearch2dArrayTestUpperSide() {
int[][] arr = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
int target = 1;
int[] ans = BinarySearch2dArray.BinarySearch(arr, target);
int[] ans = BinarySearch2dArray.binarySearch(arr, target);
System.out.println(Arrays.toString(ans));
assertEquals(0, ans[0]);
assertEquals(0, ans[1]);
@ -58,11 +58,11 @@ public class BinarySearch2dArrayTest {
@Test
// valid test case
public void BinarySearch2dArrayTestLower() {
public void binarySearch2dArrayTestLower() {
int[][] arr = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
int target = 10;
int[] ans = BinarySearch2dArray.BinarySearch(arr, target);
int[] ans = BinarySearch2dArray.binarySearch(arr, target);
System.out.println(Arrays.toString(ans));
assertEquals(2, ans[0]);
assertEquals(1, ans[1]);
@ -70,11 +70,11 @@ public class BinarySearch2dArrayTest {
@Test
// valid test case
public void BinarySearch2dArrayTestLowerSide() {
public void binarySearch2dArrayTestLowerSide() {
int[][] arr = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
int target = 11;
int[] ans = BinarySearch2dArray.BinarySearch(arr, target);
int[] ans = BinarySearch2dArray.binarySearch(arr, target);
System.out.println(Arrays.toString(ans));
assertEquals(2, ans[0]);
assertEquals(2, ans[1]);
@ -82,11 +82,11 @@ public class BinarySearch2dArrayTest {
@Test
// valid test case
public void BinarySearch2dArrayTestNotFound() {
public void binarySearch2dArrayTestNotFound() {
int[][] arr = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
int target = 101;
int[] ans = BinarySearch2dArray.BinarySearch(arr, target);
int[] ans = BinarySearch2dArray.binarySearch(arr, target);
System.out.println(Arrays.toString(ans));
assertEquals(-1, ans[0]);
assertEquals(-1, ans[1]);
@ -96,13 +96,13 @@ public class BinarySearch2dArrayTest {
* Test if the method works with input arrays consisting only of one row.
*/
@Test
public void BinarySearch2dArrayTestOneRow() {
public void binarySearch2dArrayTestOneRow() {
int[][] arr = {{1, 2, 3, 4}};
int target = 2;
// Assert that the requirement, that the array only has one row, is fulfilled.
assertEquals(arr.length, 1);
int[] ans = BinarySearch2dArray.BinarySearch(arr, target);
int[] ans = BinarySearch2dArray.binarySearch(arr, target);
System.out.println(Arrays.toString(ans));
assertEquals(0, ans[0]);
assertEquals(1, ans[1]);
@ -112,13 +112,13 @@ public class BinarySearch2dArrayTest {
* Test if the method works with the target in the middle of the input.
*/
@Test
public void BinarySearch2dArrayTestTargetInMiddle() {
public void binarySearch2dArrayTestTargetInMiddle() {
int[][] arr = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}};
int target = 8;
// Assert that the requirement, that the target is in the middle row and middle column, is
// fulfilled.
assertEquals(arr[arr.length / 2][arr[0].length / 2], target);
int[] ans = BinarySearch2dArray.BinarySearch(arr, target);
int[] ans = BinarySearch2dArray.binarySearch(arr, target);
System.out.println(Arrays.toString(ans));
assertEquals(1, ans[0]);
assertEquals(2, ans[1]);
@ -129,7 +129,7 @@ public class BinarySearch2dArrayTest {
* in the row above the middle row.
*/
@Test
public void BinarySearch2dArrayTestTargetAboveMiddleRowInMiddleColumn() {
public void binarySearch2dArrayTestTargetAboveMiddleRowInMiddleColumn() {
int[][] arr = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
int target = 3;
@ -137,7 +137,7 @@ public class BinarySearch2dArrayTest {
// in an array with an even number of columns, and on the row "above" the middle row.
assertEquals(arr[0].length % 2, 0);
assertEquals(arr[arr.length / 2 - 1][arr[0].length / 2], target);
int[] ans = BinarySearch2dArray.BinarySearch(arr, target);
int[] ans = BinarySearch2dArray.binarySearch(arr, target);
System.out.println(Arrays.toString(ans));
assertEquals(0, ans[0]);
assertEquals(2, ans[1]);
@ -147,11 +147,11 @@ public class BinarySearch2dArrayTest {
* Test if the method works with an empty array.
*/
@Test
public void BinarySearch2dArrayTestEmptyArray() {
public void binarySearch2dArrayTestEmptyArray() {
int[][] arr = {};
int target = 5;
// Assert that an empty array is not valid input for the method.
assertThrows(ArrayIndexOutOfBoundsException.class, () -> BinarySearch2dArray.BinarySearch(arr, target));
assertThrows(ArrayIndexOutOfBoundsException.class, () -> BinarySearch2dArray.binarySearch(arr, target));
}
}

View File

@ -8,55 +8,55 @@ class KMPSearchTest {
@Test
// valid test case
public void KMPSearchTestLast() {
public void kmpSearchTestLast() {
String txt = "ABABDABACDABABCABAB";
String pat = "ABABCABAB";
KMPSearch kmpSearch = new KMPSearch();
int value = kmpSearch.KMPSearch(pat, txt);
int value = kmpSearch.kmpSearch(pat, txt);
System.out.println(value);
assertEquals(value, 10);
}
@Test
// valid test case
public void KMPSearchTestFront() {
public void kmpSearchTestFront() {
String txt = "AAAAABAAABA";
String pat = "AAAA";
KMPSearch kmpSearch = new KMPSearch();
int value = kmpSearch.KMPSearch(pat, txt);
int value = kmpSearch.kmpSearch(pat, txt);
System.out.println(value);
assertEquals(value, 0);
}
@Test
// valid test case
public void KMPSearchTestMiddle() {
public void kmpSearchTestMiddle() {
String txt = "AAACAAAAAC";
String pat = "AAAA";
KMPSearch kmpSearch = new KMPSearch();
int value = kmpSearch.KMPSearch(pat, txt);
int value = kmpSearch.kmpSearch(pat, txt);
System.out.println(value);
assertEquals(value, 4);
}
@Test
// valid test case
public void KMPSearchTestNotFound() {
public void kmpSearchTestNotFound() {
String txt = "AAABAAAA";
String pat = "AAAA";
KMPSearch kmpSearch = new KMPSearch();
int value = kmpSearch.KMPSearch(pat, txt);
int value = kmpSearch.kmpSearch(pat, txt);
System.out.println(value);
assertEquals(value, 4);
}
@Test
// not valid test case
public void KMPSearchTest4() {
public void kmpSearchTest4() {
String txt = "AABAAA";
String pat = "AAAA";
KMPSearch kmpSearch = new KMPSearch();
int value = kmpSearch.KMPSearch(pat, txt);
int value = kmpSearch.kmpSearch(pat, txt);
System.out.println(value);
assertEquals(value, -1);
}

View File

@ -7,9 +7,9 @@ import org.junit.jupiter.api.Test;
public class OrderAgnosticBinarySearchTest {
@Test
// valid Test Case
public void ElementInMiddle() {
public void elementInMiddle() {
int[] arr = {10, 20, 30, 40, 50};
int answer = OrderAgnosticBinarySearch.BinSearchAlgo(arr, 0, arr.length - 1, 30);
int answer = OrderAgnosticBinarySearch.binSearchAlgo(arr, 0, arr.length - 1, 30);
System.out.println(answer);
int expected = 2;
assertEquals(expected, answer);
@ -17,9 +17,9 @@ public class OrderAgnosticBinarySearchTest {
@Test
// valid Test Case
public void RightHalfDescOrder() {
public void rightHalfDescOrder() {
int[] arr = {50, 40, 30, 20, 10};
int answer = OrderAgnosticBinarySearch.BinSearchAlgo(arr, 0, arr.length - 1, 10);
int answer = OrderAgnosticBinarySearch.binSearchAlgo(arr, 0, arr.length - 1, 10);
System.out.println(answer);
int expected = 4;
assertEquals(expected, answer);
@ -27,9 +27,9 @@ public class OrderAgnosticBinarySearchTest {
@Test
// valid test case
public void LeftHalfDescOrder() {
public void leftHalfDescOrder() {
int[] arr = {50, 40, 30, 20, 10};
int answer = OrderAgnosticBinarySearch.BinSearchAlgo(arr, 0, arr.length - 1, 50);
int answer = OrderAgnosticBinarySearch.binSearchAlgo(arr, 0, arr.length - 1, 50);
System.out.println(answer);
int expected = 0;
assertEquals(expected, answer);
@ -37,9 +37,9 @@ public class OrderAgnosticBinarySearchTest {
@Test
// valid test case
public void RightHalfAscOrder() {
public void rightHalfAscOrder() {
int[] arr = {10, 20, 30, 40, 50};
int answer = OrderAgnosticBinarySearch.BinSearchAlgo(arr, 0, arr.length - 1, 50);
int answer = OrderAgnosticBinarySearch.binSearchAlgo(arr, 0, arr.length - 1, 50);
System.out.println(answer);
int expected = 4;
assertEquals(expected, answer);
@ -47,9 +47,9 @@ public class OrderAgnosticBinarySearchTest {
@Test
// valid test case
public void LeftHalfAscOrder() {
public void leftHalfAscOrder() {
int[] arr = {10, 20, 30, 40, 50};
int answer = OrderAgnosticBinarySearch.BinSearchAlgo(arr, 0, arr.length - 1, 10);
int answer = OrderAgnosticBinarySearch.binSearchAlgo(arr, 0, arr.length - 1, 10);
System.out.println(answer);
int expected = 0;
assertEquals(expected, answer);
@ -57,9 +57,9 @@ public class OrderAgnosticBinarySearchTest {
@Test
// valid test case
public void ElementNotFound() {
public void elementNotFound() {
int[] arr = {10, 20, 30, 40, 50};
int answer = OrderAgnosticBinarySearch.BinSearchAlgo(arr, 0, arr.length - 1, 100);
int answer = OrderAgnosticBinarySearch.binSearchAlgo(arr, 0, arr.length - 1, 100);
System.out.println(answer);
int expected = -1;
assertEquals(expected, answer);

View File

@ -9,7 +9,7 @@ class RabinKarpAlgorithmTest {
@ParameterizedTest
@CsvSource({"This is an example for rabin karp algorithmn, algorithmn, 101", "AAABBDDG, AAA, 137", "AAABBCCBB, BBCC, 101", "AAABBCCBB, BBCC, 131", "AAAABBBBCCC, CCC, 41", "ABCBCBCAAB, AADB, 293", "Algorithm The Algorithm, Algorithm, 101"})
void RabinKarpAlgorithmTestExample(String txt, String pat, int q) {
void rabinKarpAlgorithmTestExample(String txt, String pat, int q) {
int indexFromOurAlgorithm = RabinKarpAlgorithm.search(pat, txt, q);
int indexFromLinearSearch = txt.indexOf(pat);
assertEquals(indexFromOurAlgorithm, indexFromLinearSearch);

View File

@ -37,7 +37,7 @@ public class RowColumnWiseSorted2dArrayBinarySearchTest {
}
@Test
public void rowColumnSorted2dArray_BinarySearchTestUpper() {
public void rowColumnSorted2dArrayBinarySearchTestUpper() {
Integer[][] arr = {
{10, 20, 30, 40},
{15, 25, 35, 45},
@ -52,7 +52,7 @@ public class RowColumnWiseSorted2dArrayBinarySearchTest {
}
@Test
public void rowColumnSorted2dArray_BinarySearchTestUpperSide() {
public void rowColumnSorted2dArrayBinarySearchTestUpperSide() {
Integer[][] arr = {
{10, 20, 30, 40},
{15, 25, 35, 45},
@ -67,7 +67,7 @@ public class RowColumnWiseSorted2dArrayBinarySearchTest {
}
@Test
public void rowColumnSorted2dArray_BinarySearchTestLower() {
public void rowColumnSorted2dArrayBinarySearchTestLower() {
Integer[][] arr = {
{10, 20, 30, 40},
{15, 25, 35, 45},
@ -82,7 +82,7 @@ public class RowColumnWiseSorted2dArrayBinarySearchTest {
}
@Test
public void rowColumnSorted2dArray_BinarySearchTestLowerSide() {
public void rowColumnSorted2dArrayBinarySearchTestLowerSide() {
Integer[][] arr = {
{10, 20, 30, 40},
{15, 25, 35, 45},
@ -97,7 +97,7 @@ public class RowColumnWiseSorted2dArrayBinarySearchTest {
}
@Test
public void rowColumnSorted2dArray_BinarySearchTestNotFound() {
public void rowColumnSorted2dArrayBinarySearchTestNotFound() {
Integer[][] arr = {
{10, 20, 30, 40},
{15, 25, 35, 45},

View File

@ -10,7 +10,7 @@ class BinaryInsertionSortTest {
@Test
// valid test case
public void BinaryInsertionSortTestNonDuplicate() {
public void binaryInsertionSortTestNonDuplicate() {
int[] array = {1, 0, 2, 5, 3, 4, 9, 8, 10, 6, 7};
int[] expResult = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int[] actResult = BIS.binaryInsertSort(array);
@ -18,7 +18,7 @@ class BinaryInsertionSortTest {
}
@Test
public void BinaryInsertionSortTestDuplicate() {
public void binaryInsertionSortTestDuplicate() {
int[] array = {1, 1, 1, 5, 9, 8, 7, 2, 6};
int[] expResult = {1, 1, 1, 2, 5, 6, 7, 8, 9};
int[] actResult = BIS.binaryInsertSort(array);

View File

@ -11,7 +11,7 @@ public class DutchNationalFlagSortTest {
1 will be used as intended middle.
Partitions on the result array: [ smaller than 1 , equal 1, greater than 1]
*/
void DNFSTestOdd() {
void testOddDnfs() {
Integer[] integers = {1, 3, 1, 4, 0};
Integer[] integersResult = {0, 1, 1, 4, 3};
DutchNationalFlagSort dutchNationalFlagSort = new DutchNationalFlagSort();
@ -24,7 +24,7 @@ public class DutchNationalFlagSortTest {
3 will be used as intended middle.
Partitions on the result array: [ smaller than 3 , equal 3, greater than 3]
*/
void DNFSTestEven() {
void testEvenDnfs() {
Integer[] integers = {8, 1, 3, 1, 4, 0};
Integer[] integersResult = {0, 1, 1, 3, 4, 8};
DutchNationalFlagSort dutchNationalFlagSort = new DutchNationalFlagSort();
@ -37,7 +37,7 @@ public class DutchNationalFlagSortTest {
"b" will be used as intended middle.
Partitions on the result array: [ smaller than b , equal b, greater than b]
*/
void DNFSTestEvenStrings() {
void testEvenStringsDnfs() {
String[] strings = {"a", "d", "b", "s", "e", "e"};
String[] stringsResult = {"a", "b", "s", "e", "e", "d"};
DutchNationalFlagSort dutchNationalFlagSort = new DutchNationalFlagSort();
@ -50,7 +50,7 @@ public class DutchNationalFlagSortTest {
"b" will be used as intended middle.
Partitions on the result array: [ smaller than b , equal b, greater than b]
*/
void DNFSTestOddStrings() {
void testOddStringsDnfs() {
String[] strings = {"a", "d", "b", "s", "e"};
String[] stringsResult = {"a", "b", "s", "e", "d"};
DutchNationalFlagSort dutchNationalFlagSort = new DutchNationalFlagSort();
@ -63,7 +63,7 @@ public class DutchNationalFlagSortTest {
0 will be used as intended middle.
Partitions on the result array: [ smaller than 0 , equal 0, greater than 0]
*/
void DNFSTestOddMidGiven() {
void testOddMidGivenDnfs() {
Integer[] integers = {1, 3, 1, 4, 0};
Integer[] integersResult = {0, 1, 4, 3, 1};
DutchNationalFlagSort dutchNationalFlagSort = new DutchNationalFlagSort();
@ -76,7 +76,7 @@ public class DutchNationalFlagSortTest {
4 will be used as intended middle.
Partitions on the result array: [ smaller than 4 , equal 4, greater than 4]
*/
void DNFSTestEvenMidGiven() {
void testEvenMidGivenDnfs() {
Integer[] integers = {8, 1, 3, 1, 4, 0};
Integer[] integersResult = {0, 1, 3, 1, 4, 8};
DutchNationalFlagSort dutchNationalFlagSort = new DutchNationalFlagSort();
@ -89,7 +89,7 @@ public class DutchNationalFlagSortTest {
"s" will be used as intended middle.
Partitions on the result array: [ smaller than s , equal s, greater than s]
*/
void DNFSTestEvenStringsMidGiven() {
void testEvenStringsMidGivenDnfs() {
String[] strings = {"a", "d", "b", "s", "e", "e"};
String[] stringsResult = {"a", "d", "b", "e", "e", "s"};
DutchNationalFlagSort dutchNationalFlagSort = new DutchNationalFlagSort();
@ -102,7 +102,7 @@ public class DutchNationalFlagSortTest {
"e" will be used as intended middle.
Partitions on the result array: [ smaller than e , equal e, greater than e]
*/
void DNFSTestOddStringsMidGiven() {
void testOddStringsMidGivenDnfs() {
String[] strings = {"a", "d", "b", "s", "e"};
String[] stringsResult = {"a", "d", "b", "e", "s"};
DutchNationalFlagSort dutchNationalFlagSort = new DutchNationalFlagSort();

View File

@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test;
public class IntrospectiveSortTest {
@Test
// valid test case
public void StrandSortNonDuplicateTest() {
public void strandSortNonDuplicateTest() {
Integer[] expectedArray = {1, 2, 3, 4, 5};
Integer[] actualList = new IntrospectiveSort().sort(expectedArray);
assertArrayEquals(expectedArray, actualList);
@ -16,7 +16,7 @@ public class IntrospectiveSortTest {
@Test
// valid test case
public void StrandSortDuplicateTest() {
public void strandSortDuplicateTest() {
Integer[] expectedArray = {2, 2, 2, 5, 7};
Integer[] actualList = new IntrospectiveSort().sort(expectedArray);
assertArrayEquals(expectedArray, actualList);
@ -24,7 +24,7 @@ public class IntrospectiveSortTest {
@Test
// valid test case
public void StrandSortEmptyTest() {
public void strandSortEmptyTest() {
Integer[] expectedArray = {};
Integer[] actualList = new IntrospectiveSort().sort(expectedArray);
assertArrayEquals(expectedArray, actualList);
@ -32,14 +32,14 @@ public class IntrospectiveSortTest {
@Test
// valid test case
public void StrandSortNullTest() {
public void strandSortNullTest() {
Integer[] expectedArray = null;
assertThrows(NullPointerException.class, () -> { new IntrospectiveSort().sort(expectedArray); });
}
@Test
// valid test case
public void StrandSortNegativeTest() {
public void strandSortNegativeTest() {
Integer[] expectedArray = {-1, -2, -3, -4, -5};
Integer[] actualList = new IntrospectiveSort().sort(expectedArray);
assertArrayEquals(expectedArray, actualList);
@ -47,7 +47,7 @@ public class IntrospectiveSortTest {
@Test
// valid test case
public void StrandSortNegativeAndPositiveTest() {
public void strandSortNegativeAndPositiveTest() {
Integer[] expectedArray = {-1, -2, -3, 4, 5};
Integer[] actualList = new IntrospectiveSort().sort(expectedArray);
assertArrayEquals(expectedArray, actualList);

View File

@ -8,7 +8,7 @@ class SelectionSortTest {
@Test
// valid test case
void IntegerArrTest() {
void integerArrTest() {
Integer[] arr = {4, 23, 6, 78, 1, 54, 231, 9, 12};
SelectionSort selectionSort = new SelectionSort();
@ -17,7 +17,7 @@ class SelectionSortTest {
@Test
// valid test case
void StringArrTest() {
void stringArrTest() {
String[] arr = {"c", "a", "e", "b", "d"};
SelectionSort selectionSort = new SelectionSort();

View File

@ -9,7 +9,7 @@ public class ShellSortTest {
private ShellSort shellSort = new ShellSort();
@Test
public void ShellSortEmptyArray() {
public void shellSortEmptyArray() {
Integer[] inputArray = {};
Integer[] outputArray = shellSort.sort(inputArray);
Integer[] expectedOutput = {};
@ -17,7 +17,7 @@ public class ShellSortTest {
}
@Test
public void ShellSortSingleIntegerArray() {
public void shellSortSingleIntegerArray() {
Integer[] inputArray = {4};
Integer[] outputArray = shellSort.sort(inputArray);
Integer[] expectedOutput = {4};
@ -25,7 +25,7 @@ public class ShellSortTest {
}
@Test
public void ShellSortSingleStringArray() {
public void shellSortSingleStringArray() {
String[] inputArray = {"s"};
String[] outputArray = shellSort.sort(inputArray);
String[] expectedOutput = {"s"};
@ -33,7 +33,7 @@ public class ShellSortTest {
}
@Test
public void ShellSortNonDuplicateIntegerArray() {
public void shellSortNonDuplicateIntegerArray() {
Integer[] inputArray = {6, -1, 99, 27, -15, 23, -36};
Integer[] outputArray = shellSort.sort(inputArray);
Integer[] expectedOutput = {-36, -15, -1, 6, 23, 27, 99};
@ -41,7 +41,7 @@ public class ShellSortTest {
}
@Test
public void ShellSortDuplicateIntegerArray() {
public void shellSortDuplicateIntegerArray() {
Integer[] inputArray = {6, -1, 27, -15, 23, 27, -36, 23};
Integer[] outputArray = shellSort.sort(inputArray);
Integer[] expectedOutput = {-36, -15, -1, 6, 23, 23, 27, 27};
@ -49,7 +49,7 @@ public class ShellSortTest {
}
@Test
public void ShellSortNonDuplicateStringArray() {
public void shellSortNonDuplicateStringArray() {
String[] inputArray = {"s", "b", "k", "a", "d", "c", "h"};
String[] outputArray = shellSort.sort(inputArray);
String[] expectedOutput = {"a", "b", "c", "d", "h", "k", "s"};
@ -57,7 +57,7 @@ public class ShellSortTest {
}
@Test
public void ShellSortDuplicateStringArray() {
public void shellSortDuplicateStringArray() {
String[] inputArray = {"s", "b", "d", "a", "d", "c", "h", "b"};
String[] outputArray = shellSort.sort(inputArray);
String[] expectedOutput = {"a", "b", "b", "c", "d", "d", "h", "s"};

View File

@ -10,7 +10,7 @@ class StrandSortTest {
@Test
// valid test case
public void StrandSortNonDuplicateTest() {
public void strandSortNonDuplicateTest() {
int[] expectedArray = {1, 2, 3, 4, 5};
LinkedList<Integer> actualList = StrandSort.strandSort(new LinkedList<Integer>(Arrays.asList(3, 1, 2, 4, 5)));
int[] actualArray = new int[actualList.size()];
@ -22,7 +22,7 @@ class StrandSortTest {
@Test
// valid test case
public void StrandSortDuplicateTest() {
public void strandSortDuplicateTest() {
int[] expectedArray = {2, 2, 2, 5, 7};
LinkedList<Integer> actualList = StrandSort.strandSort(new LinkedList<Integer>(Arrays.asList(7, 2, 2, 2, 5)));
int[] actualArray = new int[actualList.size()];

View File

@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test;
public class WiggleSortTest {
@Test
void WiggleTestNumbersEven() {
void wiggleTestNumbersEven() {
WiggleSort wiggleSort = new WiggleSort();
Integer[] values = {1, 2, 3, 4};
Integer[] result = {1, 4, 2, 3};
@ -17,7 +17,7 @@ public class WiggleSortTest {
}
@Test
void WiggleTestNumbersOdd() {
void wiggleTestNumbersOdd() {
WiggleSort wiggleSort = new WiggleSort();
Integer[] values = {1, 2, 3, 4, 5};
Integer[] result = {3, 5, 1, 4, 2};
@ -26,7 +26,7 @@ public class WiggleSortTest {
}
@Test
void WiggleTestNumbersOddDuplicates() {
void wiggleTestNumbersOddDuplicates() {
WiggleSort wiggleSort = new WiggleSort();
Integer[] values = {7, 2, 2, 2, 5};
Integer[] result = {2, 7, 2, 5, 2};
@ -35,7 +35,7 @@ public class WiggleSortTest {
}
@Test
void WiggleTestNumbersOddMultipleDuplicates() {
void wiggleTestNumbersOddMultipleDuplicates() {
WiggleSort wiggleSort = new WiggleSort();
Integer[] values = {1, 1, 2, 2, 5};
Integer[] result = {2, 5, 1, 2, 1};
@ -44,7 +44,7 @@ public class WiggleSortTest {
}
@Test
void WiggleTestNumbersEvenMultipleDuplicates() {
void wiggleTestNumbersEvenMultipleDuplicates() {
WiggleSort wiggleSort = new WiggleSort();
Integer[] values = {1, 1, 2, 2, 2, 5};
Integer[] result = {2, 5, 1, 2, 1, 2};
@ -54,7 +54,7 @@ public class WiggleSortTest {
}
@Test
void WiggleTestNumbersEvenDuplicates() {
void wiggleTestNumbersEvenDuplicates() {
WiggleSort wiggleSort = new WiggleSort();
Integer[] values = {1, 2, 4, 4};
Integer[] result = {1, 4, 2, 4};
@ -63,7 +63,7 @@ public class WiggleSortTest {
}
@Test
void WiggleTestStrings() {
void wiggleTestStrings() {
WiggleSort wiggleSort = new WiggleSort();
String[] values = {"a", "b", "d", "c"};
String[] result = {"a", "d", "b", "c"};

View File

@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test;
public class ReverseStringTest {
@Test
public void ReverseStringTest() {
public void testReverseString() {
String input1 = "Hello World";
String input2 = "helloworld";
String input3 = "123456789";