|
1 | 1 | package com.thealgorithms.maths;
|
2 | 2 |
|
3 |
| -import static java.util.Map.entry; |
4 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
5 | 4 |
|
6 |
| -import java.util.Map; |
7 |
| -import org.junit.jupiter.api.Test; |
| 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; |
8 | 9 |
|
9 | 10 | public class GenericRootTest {
|
10 |
| - private final Map<Integer, Integer> testCases = Map.ofEntries(entry(0, 0), entry(1, 1), entry(12345, 6), entry(123, 6), entry(15937, 7), entry(222222, 3), entry(99999, 9)); |
11 |
| - @Test |
12 |
| - public void testGenericRoot() { |
13 |
| - for (final var tc : testCases.entrySet()) { |
14 |
| - assertEquals(tc.getValue(), GenericRoot.genericRoot(tc.getKey())); |
15 |
| - } |
| 11 | + @ParameterizedTest |
| 12 | + @MethodSource("tcStream") |
| 13 | + public void testGenericRoot(final int input, final int expected) { |
| 14 | + assertEquals(expected, GenericRoot.genericRoot(input)); |
16 | 15 | }
|
17 | 16 |
|
18 |
| - @Test |
19 |
| - public void testGenericRootWithNegativeInputs() { |
20 |
| - for (final var tc : testCases.entrySet()) { |
21 |
| - assertEquals(tc.getValue(), GenericRoot.genericRoot(-tc.getKey())); |
22 |
| - } |
| 17 | + @ParameterizedTest |
| 18 | + @MethodSource("tcStream") |
| 19 | + public void testGenericRootWithNegativeInputs(final int input, final int expected) { |
| 20 | + assertEquals(expected, GenericRoot.genericRoot(-input)); |
| 21 | + } |
| 22 | + |
| 23 | + private static Stream<Arguments> tcStream() { |
| 24 | + return Stream.of(Arguments.of(0, 0), Arguments.of(1, 1), Arguments.of(12345, 6), Arguments.of(123, 6), Arguments.of(15937, 7), Arguments.of(222222, 3), Arguments.of(99999, 9)); |
23 | 25 | }
|
24 | 26 | }
|
0 commit comments