mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 22:43:30 +08:00
Refactor Code Style (#4151)
This commit is contained in:
@ -9,7 +9,7 @@ public class AllPathsFromSourceToTargetTest {
|
||||
@Test
|
||||
void testForFirstCase() {
|
||||
int vertices = 4;
|
||||
int a[][] = {{0,1},{0,2},{0,3},{2,0},{2,1},{1,3}};
|
||||
int[][] a = {{0,1},{0,2},{0,3},{2,0},{2,1},{1,3}};
|
||||
int source = 2;
|
||||
int destination = 3;
|
||||
List<List<Integer>> list2 = List.of(List.of(2, 0, 1, 3),List.of(2, 0, 3),List.of(2, 1, 3));
|
||||
@ -21,7 +21,7 @@ public class AllPathsFromSourceToTargetTest {
|
||||
@Test
|
||||
void testForSecondCase() {
|
||||
int vertices = 5;
|
||||
int a[][] = {{0,1},{0,2},{0,3},{2,0},{2,1},{1,3},{1,4},{3,4},{2,4}};
|
||||
int[][] a = {{0,1},{0,2},{0,3},{2,0},{2,1},{1,3},{1,4},{3,4},{2,4}};
|
||||
int source = 0;
|
||||
int destination = 4;
|
||||
List<List<Integer>> list2 = List.of(List.of(0, 1, 3, 4),List.of(0, 1, 4),List.of(0, 2, 1, 3, 4),List.of(0, 2, 1, 4),List.of(0, 2, 4),List.of(0, 3, 4));
|
||||
@ -33,7 +33,7 @@ public class AllPathsFromSourceToTargetTest {
|
||||
@Test
|
||||
void testForThirdCase() {
|
||||
int vertices = 6;
|
||||
int a[][] = {{1,0},{2,3},{0,4},{1,5},{4,3},{0,2},{0,3},{1,2},{0,5},{3,4},{2,5},{2,4}};
|
||||
int[][] a = {{1,0},{2,3},{0,4},{1,5},{4,3},{0,2},{0,3},{1,2},{0,5},{3,4},{2,5},{2,4}};
|
||||
int source = 1;
|
||||
int destination = 5;
|
||||
List<List<Integer>> list2 = List.of(List.of(1, 0, 2, 5),List.of(1, 0, 5),List.of(1, 5),List.of(1, 2, 5));
|
||||
@ -45,7 +45,7 @@ public class AllPathsFromSourceToTargetTest {
|
||||
@Test
|
||||
void testForFourthcase() {
|
||||
int vertices = 3;
|
||||
int a[][] = {{0,1},{0,2},{1,2}};
|
||||
int[][] a = {{0,1},{0,2},{1,2}};
|
||||
int source = 0;
|
||||
int destination = 2;
|
||||
List<List<Integer>> list2 = List.of(List.of(0, 1, 2),List.of(0, 2));
|
||||
|
@ -8,8 +8,8 @@ class FloodFillTest {
|
||||
|
||||
@Test
|
||||
void testForEmptyImage() {
|
||||
int image[][] = {};
|
||||
int expected[][] = {};
|
||||
int[][] image = {};
|
||||
int[][] expected = {};
|
||||
|
||||
FloodFill.floodFill(image, 4, 5, 3, 2);
|
||||
assertArrayEquals(expected, image);
|
||||
@ -17,8 +17,8 @@ class FloodFillTest {
|
||||
|
||||
@Test
|
||||
void testForSingleElementImage() {
|
||||
int image[][] = { { 1 } };
|
||||
int expected[][] = { { 3 } };
|
||||
int[][] image = { { 1 } };
|
||||
int[][] expected = { { 3 } };
|
||||
|
||||
FloodFill.floodFill(image, 0, 0, 3, 1);
|
||||
assertArrayEquals(expected, image);
|
||||
@ -26,7 +26,7 @@ class FloodFillTest {
|
||||
|
||||
@Test
|
||||
void testForImageOne() {
|
||||
int image[][] = {
|
||||
int[][] image = {
|
||||
{ 0, 0, 0, 0, 0, 0, 0 },
|
||||
{ 0, 3, 3, 3, 3, 0, 0 },
|
||||
{ 0, 3, 1, 1, 5, 0, 0 },
|
||||
@ -36,7 +36,7 @@ class FloodFillTest {
|
||||
{ 0, 0, 0, 3, 3, 3, 3 },
|
||||
};
|
||||
|
||||
int expected[][] = {
|
||||
int[][] expected = {
|
||||
{ 0, 0, 0, 0, 0, 0, 0 },
|
||||
{ 0, 3, 3, 3, 3, 0, 0 },
|
||||
{ 0, 3, 2, 2, 5, 0, 0 },
|
||||
@ -52,7 +52,7 @@ class FloodFillTest {
|
||||
|
||||
@Test
|
||||
void testForImageTwo() {
|
||||
int image[][] = {
|
||||
int[][] image = {
|
||||
{ 0, 0, 1, 1, 0, 0, 0 },
|
||||
{ 1, 1, 3, 3, 3, 0, 0 },
|
||||
{ 1, 3, 1, 1, 5, 0, 0 },
|
||||
@ -62,7 +62,7 @@ class FloodFillTest {
|
||||
{ 0, 0, 0, 1, 3, 1, 3 },
|
||||
};
|
||||
|
||||
int expected[][] = {
|
||||
int[][] expected = {
|
||||
{ 0, 0, 2, 2, 0, 0, 0 },
|
||||
{ 2, 2, 3, 3, 3, 0, 0 },
|
||||
{ 2, 3, 2, 2, 5, 0, 0 },
|
||||
@ -78,13 +78,13 @@ class FloodFillTest {
|
||||
|
||||
@Test
|
||||
void testForImageThree() {
|
||||
int image[][] = {
|
||||
int[][] image = {
|
||||
{ 1, 1, 2, 3, 1, 1, 1 },
|
||||
{ 1, 0, 0, 1, 0, 0, 1 },
|
||||
{ 1, 1, 1, 0, 3, 1, 2 },
|
||||
};
|
||||
|
||||
int expected[][] = {
|
||||
int[][] expected = {
|
||||
{ 4, 4, 2, 3, 4, 4, 4 },
|
||||
{ 4, 0, 0, 4, 0, 0, 4 },
|
||||
{ 4, 4, 4, 0, 3, 4, 2 },
|
||||
|
@ -45,7 +45,7 @@ public class MazeRecursionTest {
|
||||
MazeRecursion.setWay(map, 1, 1);
|
||||
MazeRecursion.setWay2(map2, 1, 1);
|
||||
|
||||
int expectedMap[][] = new int[][] {
|
||||
int[][] expectedMap = new int[][] {
|
||||
{ 1, 1, 1, 1, 1, 1, 1 },
|
||||
{ 1, 2, 0, 0, 0, 0, 1 },
|
||||
{ 1, 2, 2, 2, 0, 0, 1 },
|
||||
@ -56,7 +56,7 @@ public class MazeRecursionTest {
|
||||
{ 1, 1, 1, 1, 1, 1, 1 },
|
||||
};
|
||||
|
||||
int expectedMap2[][] = new int[][] {
|
||||
int[][] expectedMap2 = new int[][] {
|
||||
{ 1, 1, 1, 1, 1, 1, 1 },
|
||||
{ 1, 2, 2, 2, 2, 2, 1 },
|
||||
{ 1, 0, 0, 0, 0, 2, 1 },
|
||||
|
@ -7,8 +7,8 @@ public class AutomorphicNumberTest {
|
||||
|
||||
@Test
|
||||
void testAutomorphicNumber() {
|
||||
int trueTestCases[] = { 0, 1, 25, 625, 12890625};
|
||||
int falseTestCases[] = { -5, 2, 26, 1234 };
|
||||
int[] trueTestCases = { 0, 1, 25, 625, 12890625};
|
||||
int[] falseTestCases = { -5, 2, 26, 1234 };
|
||||
for (Integer n : trueTestCases) {
|
||||
assertTrue(AutomorphicNumber.isAutomorphic(n));
|
||||
assertTrue(AutomorphicNumber.isAutomorphic2(n));
|
||||
|
@ -7,8 +7,8 @@ class PerfectNumberTest {
|
||||
|
||||
@Test
|
||||
public void perfectNumber() {
|
||||
int trueTestCases[] = { 6, 28, 496, 8128, 33550336 };
|
||||
int falseTestCases[] = { -6, 0, 1, 9, 123 };
|
||||
int[] trueTestCases = { 6, 28, 496, 8128, 33550336 };
|
||||
int[] falseTestCases = { -6, 0, 1, 9, 123 };
|
||||
for (Integer n : trueTestCases) {
|
||||
assertTrue(PerfectNumber.isPerfectNumber(n));
|
||||
assertTrue(PerfectNumber.isPerfectNumber2(n));
|
||||
|
@ -9,49 +9,49 @@ public class CalculateMaxOfMinTest {
|
||||
|
||||
@Test
|
||||
void testForOneElement() {
|
||||
int a[] = { 10, 20, 30, 50, 10, 70, 30 };
|
||||
int[] a = { 10, 20, 30, 50, 10, 70, 30 };
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertTrue(k == 70);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForTwoElements() {
|
||||
int a[] = { 5, 3, 2, 6, 3, 2, 6 };
|
||||
int[] a = { 5, 3, 2, 6, 3, 2, 6 };
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertTrue(k == 6);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForThreeElements() {
|
||||
int a[] = { 10, 10, 10, 10, 10, 10, 10 };
|
||||
int[] a = { 10, 10, 10, 10, 10, 10, 10 };
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertTrue(k == 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFourElements() {
|
||||
int a[] = { 70, 60, 50, 40, 30, 20 };
|
||||
int[] a = { 70, 60, 50, 40, 30, 20 };
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertTrue(k == 70);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFiveElements() {
|
||||
int a[] = { 50 };
|
||||
int[] a = { 50 };
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertTrue(k == 50);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSixElements() {
|
||||
int a[] = { 1, 4, 7, 9, 2, 4, 6 };
|
||||
int[] a = { 1, 4, 7, 9, 2, 4, 6 };
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertTrue(k == 9);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSevenElements() {
|
||||
int a[] = { -1, -5, -7, -9, -12, -14 };
|
||||
int[] a = { -1, -5, -7, -9, -12, -14 };
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertTrue(k == -1);
|
||||
}
|
||||
|
@ -9,49 +9,49 @@ public class CountFriendsPairingTest {
|
||||
|
||||
@Test
|
||||
void testForOneElement() {
|
||||
int a[] = { 1, 2, 2 };
|
||||
int[] a = { 1, 2, 2 };
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(3, a));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForTwoElements() {
|
||||
int a[] = { 1, 2, 2, 3 };
|
||||
int[] a = { 1, 2, 2, 3 };
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(4, a));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForThreeElements() {
|
||||
int a[] = { 1, 2, 2, 3, 3 };
|
||||
int[] a = { 1, 2, 2, 3, 3 };
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(5, a));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFourElements() {
|
||||
int a[] = { 1, 2, 2, 3, 3, 4 };
|
||||
int[] a = { 1, 2, 2, 3, 3, 4 };
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(6, a));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFiveElements() {
|
||||
int a[] = { 1, 2, 2, 3, 3, 4, 4 };
|
||||
int[] a = { 1, 2, 2, 3, 3, 4, 4 };
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(7, a));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSixElements() {
|
||||
int a[] = { 1, 2, 2, 3, 3, 4, 4, 4 };
|
||||
int[] a = { 1, 2, 2, 3, 3, 4, 4, 4 };
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(8, a));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSevenElements() {
|
||||
int a[] = { 1, 2, 2, 3, 3, 4, 4, 4, 5 };
|
||||
int[] a = { 1, 2, 2, 3, 3, 4, 4, 4, 5 };
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(9, a));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForEightElements() {
|
||||
int a[] = { 1, 2, 2, 3, 3, 4, 4, 4, 5, 5 };
|
||||
int[] a = { 1, 2, 2, 3, 3, 4, 4, 4, 5, 5 };
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(10, a));
|
||||
}
|
||||
}
|
||||
|
@ -9,49 +9,49 @@ public class KadaneAlogrithmTest {
|
||||
|
||||
@Test
|
||||
void testForOneElement() {
|
||||
int a[] = { -1 };
|
||||
int[] a = { -1 };
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a, -1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForTwoElements() {
|
||||
int a[] = { -2, 1 };
|
||||
int[] a = { -2, 1 };
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForThreeElements() {
|
||||
int a[] = { 5, 3, 12 };
|
||||
int[] a = { 5, 3, 12 };
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a, 20));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFourElements() {
|
||||
int a[] = { -1, -3, -7, -4 };
|
||||
int[] a = { -1, -3, -7, -4 };
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a, -1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFiveElements() {
|
||||
int a[] = { 4, 5, 3, 0, 2 };
|
||||
int[] a = { 4, 5, 3, 0, 2 };
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a, 14));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSixElements() {
|
||||
int a[] = { -43, -45, 47, 12, 87, -13 };
|
||||
int[] a = { -43, -45, 47, 12, 87, -13 };
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a, 146));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSevenElements() {
|
||||
int a[] = { 9, 8, 2, 23, 13, 6, 7 };
|
||||
int[] a = { 9, 8, 2, 23, 13, 6, 7 };
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a, 68));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForEightElements() {
|
||||
int a[] = { 9, -5, -5, -2, 4, 5, 0, 1 };
|
||||
int[] a = { 9, -5, -5, -2, 4, 5, 0, 1 };
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a, 10));
|
||||
}
|
||||
}
|
||||
|
@ -9,49 +9,49 @@ public class LinkListSortTest {
|
||||
|
||||
@Test
|
||||
void testForOneElement() {
|
||||
int a[] = { 56 };
|
||||
int[] a = { 56 };
|
||||
assertTrue(LinkListSort.isSorted(a, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForTwoElements() {
|
||||
int a[] = { 6, 4 };
|
||||
int[] a = { 6, 4 };
|
||||
assertTrue(LinkListSort.isSorted(a, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForThreeElements() {
|
||||
int a[] = { 875, 253, 12 };
|
||||
int[] a = { 875, 253, 12 };
|
||||
assertTrue(LinkListSort.isSorted(a, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFourElements() {
|
||||
int a[] = { 86, 32, 87, 13 };
|
||||
int[] a = { 86, 32, 87, 13 };
|
||||
assertTrue(LinkListSort.isSorted(a, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFiveElements() {
|
||||
int a[] = { 6, 5, 3, 0, 9 };
|
||||
int[] a = { 6, 5, 3, 0, 9 };
|
||||
assertTrue(LinkListSort.isSorted(a, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSixElements() {
|
||||
int a[] = { 9, 65, 432, 32, 47, 327 };
|
||||
int[] a = { 9, 65, 432, 32, 47, 327 };
|
||||
assertTrue(LinkListSort.isSorted(a, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSevenElements() {
|
||||
int a[] = { 6, 4, 2, 1, 3, 6, 7 };
|
||||
int[] a = { 6, 4, 2, 1, 3, 6, 7 };
|
||||
assertTrue(LinkListSort.isSorted(a, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForEightElements() {
|
||||
int a[] = { 123, 234, 145, 764, 322, 367, 768, 34 };
|
||||
int[] a = { 123, 234, 145, 764, 322, 367, 768, 34 };
|
||||
assertTrue(LinkListSort.isSorted(a, 2));
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ public class sortOrderAgnosticBinarySearchTest{
|
||||
|
||||
@Test
|
||||
public void testAscending(){
|
||||
int arr[] = {1,2,3,4,5};// for ascending order.
|
||||
int[] arr = {1,2,3,4,5};// for ascending order.
|
||||
int target = 2;
|
||||
int ans=sortOrderAgnosticBinarySearch.find(arr, target);
|
||||
int excepted = 1;
|
||||
@ -17,7 +17,7 @@ public class sortOrderAgnosticBinarySearchTest{
|
||||
|
||||
@Test
|
||||
public void testDescending(){
|
||||
int arr[] = {5,4,3,2,1};// for descending order.
|
||||
int[] arr = {5,4,3,2,1};// for descending order.
|
||||
int target = 2;
|
||||
int ans=sortOrderAgnosticBinarySearch.find(arr, target);
|
||||
int excepted = 3;
|
||||
|
Reference in New Issue
Block a user