mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-26 05:59:22 +08:00
refactor: LeastCommonMultiple
(#5435)
* refactor: LeastCommonMultiple * checkstyle: fix formatting --------- Co-authored-by: alxkm <alx@alx.com>
This commit is contained in:
@ -1,27 +1,21 @@
|
||||
package com.thealgorithms.maths;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class LeastCommonMultipleTest {
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/*
|
||||
* Test for first number greater than second number
|
||||
*/
|
||||
@Test
|
||||
public void testForFirst() {
|
||||
int result = LeastCommonMultiple.lcm(6, 8);
|
||||
int expected = 24;
|
||||
Assertions.assertEquals(result, expected);
|
||||
class LeastCommonMultipleTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideTestCases")
|
||||
void testLcm(int num1, int num2, int expected) {
|
||||
assertEquals(expected, LeastCommonMultiple.lcm(num1, num2));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for second number greater than first number
|
||||
*/
|
||||
@Test
|
||||
public void testForSecond() {
|
||||
int result = LeastCommonMultiple.lcm(8, 6);
|
||||
int expected = 24;
|
||||
Assertions.assertEquals(result, expected);
|
||||
private static Stream<Arguments> provideTestCases() {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user