mirror of
https://github.com/TheAlgorithms/Java.git
synced 2026-03-13 08:40:43 +08:00
Add recursive factorial implementation with tests (#7178)
* Add recursive factorial implementation with tests * [STYLE] Apply clang-format * Move recursive factorial to recursion package and remove duplicate * Move recursive factorial to recursion package and remove duplicate * Apply clang-format to factorial recursion tests * Apply clang-format to factorial recursion tests --------- Co-authored-by: Koushik Sai <nyamathabadkoushik@gmail.com> Co-authored-by: Deniz Altunkapan <deniz.altunkapan@outlook.com>
This commit is contained in:
committed by
GitHub
parent
1eb0d61730
commit
2707da25e3
@@ -1,27 +0,0 @@
|
||||
package com.thealgorithms.maths;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
public class FactorialRecursionTest {
|
||||
@ParameterizedTest
|
||||
@MethodSource("inputStream")
|
||||
void testFactorialRecursion(long expected, int number) {
|
||||
assertEquals(expected, FactorialRecursion.factorial(number));
|
||||
}
|
||||
|
||||
private static Stream<Arguments> inputStream() {
|
||||
return Stream.of(Arguments.of(1, 0), Arguments.of(1, 1), Arguments.of(2, 2), Arguments.of(6, 3), Arguments.of(120, 5));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testThrowsForNegativeInput() {
|
||||
assertThrows(IllegalArgumentException.class, () -> FactorialRecursion.factorial(-1));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user