Skip to content

Commit 42637c0

Browse files
authored
Merge branch 'master' into refactor/WordLadder
2 parents 4083875 + 87cf891 commit 42637c0

File tree

10 files changed

+38
-59
lines changed

10 files changed

+38
-59
lines changed

pmd-exclude.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ com.thealgorithms.datastructures.crdt.LWWElementSet=UselessParentheses
1212
com.thealgorithms.datastructures.crdt.Pair=UnusedPrivateField
1313
com.thealgorithms.datastructures.graphs.AStar=UselessParentheses
1414
com.thealgorithms.datastructures.graphs.AdjacencyMatrixGraph=CollapsibleIfStatements,UnnecessaryFullyQualifiedName,UselessParentheses
15-
com.thealgorithms.datastructures.graphs.BipartiteGrapfDFS=CollapsibleIfStatements
15+
com.thealgorithms.datastructures.graphs.BipartiteGraphDFS=CollapsibleIfStatements
1616
com.thealgorithms.datastructures.graphs.Kruskal=UselessParentheses
1717
com.thealgorithms.datastructures.hashmap.hashing.HashMapCuckooHashing=UselessParentheses
1818
com.thealgorithms.datastructures.heaps.FibonacciHeap=UselessParentheses

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<dependency>
5151
<groupId>org.apache.commons</groupId>
5252
<artifactId>commons-lang3</artifactId>
53-
<version>3.16.0</version>
53+
<version>3.17.0</version>
5454
</dependency>
5555
<dependency>
5656
<groupId>org.apache.commons</groupId>

src/main/java/com/thealgorithms/datastructures/graphs/BipartiteGrapfDFS.java renamed to src/main/java/com/thealgorithms/datastructures/graphs/BipartiteGraphDFS.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
*
1515
* Output : YES
1616
*/
17-
public final class BipartiteGrapfDFS {
18-
private BipartiteGrapfDFS() {
17+
public final class BipartiteGraphDFS {
18+
private BipartiteGraphDFS() {
1919
}
2020

2121
private static boolean bipartite(int v, ArrayList<ArrayList<Integer>> adj, int[] color, int node) {

src/main/java/com/thealgorithms/datastructures/lists/MergeKSortedLinkedlist.java renamed to src/main/java/com/thealgorithms/datastructures/lists/MergeKSortedLinkedList.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* @author Arun Pandey (https://github.com/pandeyarun709)
99
*/
10-
public class MergeKSortedLinkedlist {
10+
public class MergeKSortedLinkedList {
1111

1212
/**
1313
* This function merge K sorted LinkedList

src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java

+6-20
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,27 @@
11
package com.thealgorithms.maths;
22

3-
import java.util.Scanner;
4-
53
/**
64
* Is a common mathematics concept to find the smallest value number
75
* that can be divide using either number without having the remainder.
86
* https://maticschool.blogspot.com/2013/11/find-least-common-multiple-lcm.html
97
* @author LauKinHoong
108
*/
11-
129
public final class LeastCommonMultiple {
1310
private LeastCommonMultiple() {
1411
}
1512

1613
/**
17-
* Driver Code
18-
*/
19-
public static void main(String[] args) {
20-
Scanner input = new Scanner(System.in);
21-
System.out.println("Please enter first number >> ");
22-
int num1 = input.nextInt();
23-
System.out.println("Please enter second number >> ");
24-
int num2 = input.nextInt();
25-
System.out.println("The least common multiple of two numbers is >> " + lcm(num1, num2));
26-
input.close();
27-
}
28-
29-
/*
30-
* get least common multiple from two number
14+
* Finds the least common multiple of two numbers.
15+
*
16+
* @param num1 The first number.
17+
* @param num2 The second number.
18+
* @return The least common multiple of num1 and num2.
3119
*/
3220
public static int lcm(int num1, int num2) {
3321
int high;
3422
int num3;
3523
int cmv = 0;
36-
/*
37-
* value selection for the numerator
38-
*/
24+
3925
if (num1 > num2) {
4026
high = num1;
4127
num3 = num1;

src/main/java/com/thealgorithms/stacks/LargestRectangle.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public final class LargestRectangle {
1111
private LargestRectangle() {
1212
}
1313

14-
public static String largestRectanglehistogram(int[] heights) {
14+
public static String largestRectangleHistogram(int[] heights) {
1515
int n = heights.length;
1616
int maxArea = 0;
1717
Stack<int[]> st = new Stack<>();
@@ -32,7 +32,7 @@ public static String largestRectanglehistogram(int[] heights) {
3232
}
3333

3434
public static void main(String[] args) {
35-
assert largestRectanglehistogram(new int[] {2, 1, 5, 6, 2, 3}).equals("10");
36-
assert largestRectanglehistogram(new int[] {2, 4}).equals("4");
35+
assert largestRectangleHistogram(new int[] {2, 1, 5, 6, 2, 3}).equals("10");
36+
assert largestRectangleHistogram(new int[] {2, 4}).equals("4");
3737
}
3838
}

src/main/java/com/thealgorithms/strings/ReverseWordsInString.java

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ private ReverseWordsInString() {
1313
* @param s the input string
1414
* @return A string created by reversing the order of the words in {@code s}
1515
*/
16-
1716
public static String reverseWordsInString(final String s) {
1817
var words = s.trim().split("\\s+");
1918
Collections.reverse(Arrays.asList(words));

src/main/java/com/thealgorithms/strings/Upper.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ public static void main(String[] args) {
1515
}
1616

1717
/**
18-
* Converts all of the characters in this {@code String} to upper case
18+
* Converts all the characters in this {@code String} to upper case
1919
*
2020
* @param s the string to convert
2121
* @return the {@code String}, converted to uppercase.
2222
*/
2323
public static String toUpperCase(String s) {
24-
if (s == null || "".equals(s)) {
24+
if (s == null || s.isEmpty()) {
2525
return s;
2626
}
2727
char[] values = s.toCharArray();
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
package com.thealgorithms.maths;
22

3-
import org.junit.jupiter.api.Assertions;
4-
import org.junit.jupiter.api.Test;
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
54

6-
public class LeastCommonMultipleTest {
5+
import java.util.stream.Stream;
6+
import org.junit.jupiter.params.ParameterizedTest;
7+
import org.junit.jupiter.params.provider.Arguments;
8+
import org.junit.jupiter.params.provider.MethodSource;
79

8-
/*
9-
* Test for first number greater than second number
10-
*/
11-
@Test
12-
public void testForFirst() {
13-
int result = LeastCommonMultiple.lcm(6, 8);
14-
int expected = 24;
15-
Assertions.assertEquals(result, expected);
10+
class LeastCommonMultipleTest {
11+
12+
@ParameterizedTest
13+
@MethodSource("provideTestCases")
14+
void testLcm(int num1, int num2, int expected) {
15+
assertEquals(expected, LeastCommonMultiple.lcm(num1, num2));
1616
}
1717

18-
/*
19-
* Test for second number greater than first number
20-
*/
21-
@Test
22-
public void testForSecond() {
23-
int result = LeastCommonMultiple.lcm(8, 6);
24-
int expected = 24;
25-
Assertions.assertEquals(result, expected);
18+
private static Stream<Arguments> provideTestCases() {
19+
return Stream.of(Arguments.of(12, 18, 36), Arguments.of(5, 10, 10), Arguments.of(7, 3, 21), Arguments.of(21, 6, 42), Arguments.of(1, 1, 1), Arguments.of(8, 12, 24), Arguments.of(14, 35, 70), Arguments.of(15, 25, 75), Arguments.of(100, 25, 100), Arguments.of(0, 10, 0));
2620
}
2721
}

src/test/java/com/thealgorithms/stacks/LargestRectangleTest.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ void testLargestRectangleHistogramWithTypicalCases() {
1111
// Typical case with mixed heights
1212
int[] heights = {2, 1, 5, 6, 2, 3};
1313
String expected = "10";
14-
String result = LargestRectangle.largestRectanglehistogram(heights);
14+
String result = LargestRectangle.largestRectangleHistogram(heights);
1515
assertEquals(expected, result);
1616

1717
// Another typical case with increasing heights
1818
heights = new int[] {2, 4};
1919
expected = "4";
20-
result = LargestRectangle.largestRectanglehistogram(heights);
20+
result = LargestRectangle.largestRectangleHistogram(heights);
2121
assertEquals(expected, result);
2222

2323
// Case with multiple bars of the same height
2424
heights = new int[] {4, 4, 4, 4};
2525
expected = "16";
26-
result = LargestRectangle.largestRectanglehistogram(heights);
26+
result = LargestRectangle.largestRectangleHistogram(heights);
2727
assertEquals(expected, result);
2828
}
2929

@@ -32,19 +32,19 @@ void testLargestRectangleHistogramWithEdgeCases() {
3232
// Edge case with an empty array
3333
int[] heights = {};
3434
String expected = "0";
35-
String result = LargestRectangle.largestRectanglehistogram(heights);
35+
String result = LargestRectangle.largestRectangleHistogram(heights);
3636
assertEquals(expected, result);
3737

3838
// Edge case with a single bar
3939
heights = new int[] {5};
4040
expected = "5";
41-
result = LargestRectangle.largestRectanglehistogram(heights);
41+
result = LargestRectangle.largestRectangleHistogram(heights);
4242
assertEquals(expected, result);
4343

4444
// Edge case with all bars of height 0
4545
heights = new int[] {0, 0, 0};
4646
expected = "0";
47-
result = LargestRectangle.largestRectanglehistogram(heights);
47+
result = LargestRectangle.largestRectangleHistogram(heights);
4848
assertEquals(expected, result);
4949
}
5050

@@ -56,7 +56,7 @@ void testLargestRectangleHistogramWithLargeInput() {
5656
heights[i] = 1;
5757
}
5858
String expected = "10000";
59-
String result = LargestRectangle.largestRectanglehistogram(heights);
59+
String result = LargestRectangle.largestRectangleHistogram(heights);
6060
assertEquals(expected, result);
6161
}
6262

@@ -65,13 +65,13 @@ void testLargestRectangleHistogramWithComplexCases() {
6565
// Complex case with a mix of heights
6666
int[] heights = {6, 2, 5, 4, 5, 1, 6};
6767
String expected = "12";
68-
String result = LargestRectangle.largestRectanglehistogram(heights);
68+
String result = LargestRectangle.largestRectangleHistogram(heights);
6969
assertEquals(expected, result);
7070

7171
// Case with a peak in the middle
7272
heights = new int[] {2, 1, 5, 6, 2, 3, 1};
7373
expected = "10";
74-
result = LargestRectangle.largestRectanglehistogram(heights);
74+
result = LargestRectangle.largestRectangleHistogram(heights);
7575
assertEquals(expected, result);
7676
}
7777
}

0 commit comments

Comments
 (0)