mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-28 15:02:46 +08:00
style: enable MethodName
in CheckStyle (#5182)
enabled: MethodName in CheckStyle
This commit is contained in:

committed by
GitHub

parent
ea4dc15a24
commit
295e7436b1
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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},
|
||||
|
Reference in New Issue
Block a user