Add tests for GenericRoot (#4276)

This commit is contained in:
Piotr Idzik
2023-08-03 22:14:59 +02:00
committed by GitHub
parent 087d523ed0
commit ee23b6c2e5
2 changed files with 43 additions and 19 deletions

View File

@ -0,0 +1,24 @@
package com.thealgorithms.maths;
import static java.util.Map.entry;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Map;
import org.junit.jupiter.api.Test;
public class GenericRootTest {
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));
@Test
public void testGenericRoot() {
for (final var tc : testCases.entrySet()) {
assertEquals(tc.getValue(), GenericRoot.genericRoot(tc.getKey()));
}
}
@Test
public void testGenericRootWithNegativeInputs() {
for (final var tc : testCases.entrySet()) {
assertEquals(tc.getValue(), GenericRoot.genericRoot(-tc.getKey()));
}
}
}