Skip to content

Commit b2f6827

Browse files
authored
Add Tests for DigitalRoot Algorithm (TheAlgorithms#3186)
1 parent 199c85d commit b2f6827

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ public static int single(int n) {
6060
} // n / 10 is the number obtainded after removing the digit one by one
6161
// Sum of digits is stored in the Stack memory and then finally returned
6262

63-
public static void main(String[] args) {
64-
Scanner sc = new Scanner(System.in);
65-
System.out.println("Enter the number : ");
66-
int n = sc.nextInt(); // Taking a number as input from the user
67-
System.out.println("Digital Root : " + digitalRoot(n)); // Printing the value returned by digitalRoot() method
68-
}
6963
}
7064

7165
/**
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.thealgorithms.maths;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
public class DigitalRootTest {
8+
9+
@Test
10+
void testDigitalroot() {
11+
12+
assertEquals(4, DigitalRoot.digitalRoot(4));
13+
assertEquals(9, DigitalRoot.digitalRoot(9));
14+
assertEquals(4, DigitalRoot.digitalRoot(49));
15+
assertEquals(6, DigitalRoot.digitalRoot(78));
16+
assertEquals(4, DigitalRoot.digitalRoot(1228));
17+
assertEquals(5, DigitalRoot.digitalRoot(71348));
18+
19+
}
20+
}

0 commit comments

Comments
 (0)