Skip to content

Commit 50b9134

Browse files
authored
Merge branch 'master' into refactor/typo_style
2 parents aa2a7e8 + d189c3a commit 50b9134

File tree

2 files changed

+19
-39
lines changed

2 files changed

+19
-39
lines changed

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

Lines changed: 6 additions & 20 deletions
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;
Lines changed: 13 additions & 19 deletions
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
}

0 commit comments

Comments
 (0)