Skip to content

Commit 7eb4d88

Browse files
committed
tests: add GenericRootTest
1 parent 087d523 commit 7eb4d88

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static void main(String[] args) {
1515
System.out.println("Generic root of " + number2 + " is: " + result2);
1616
}
1717

18-
private static int genericRoot(int n) {
18+
public static int genericRoot(int n) {
1919
int root = 0;
2020
while (n > 0 || root > 9) {
2121
if (n == 0) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.thealgorithms.maths;
2+
3+
import static java.util.Map.entry;
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
6+
import java.util.Map;
7+
import org.junit.jupiter.api.Test;
8+
9+
public class GenericRootTest {
10+
@Test
11+
public void testGenericRoot() {
12+
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));
13+
for (final var tc : testCases.entrySet()) {
14+
assertEquals(tc.getValue(), GenericRoot.genericRoot(tc.getKey()));
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)