Add Tests for DigitalRoot Algorithm (#3186)
This commit is contained in:
parent
199c85d191
commit
b2f6827c36
@ -60,12 +60,6 @@ class DigitalRoot {
|
||||
} // n / 10 is the number obtainded after removing the digit one by one
|
||||
// Sum of digits is stored in the Stack memory and then finally returned
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.println("Enter the number : ");
|
||||
int n = sc.nextInt(); // Taking a number as input from the user
|
||||
System.out.println("Digital Root : " + digitalRoot(n)); // Printing the value returned by digitalRoot() method
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
20
src/test/java/com/thealgorithms/maths/DigitalRootTest.java
Normal file
20
src/test/java/com/thealgorithms/maths/DigitalRootTest.java
Normal file
@ -0,0 +1,20 @@
|
||||
package com.thealgorithms.maths;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class DigitalRootTest {
|
||||
|
||||
@Test
|
||||
void testDigitalroot() {
|
||||
|
||||
assertEquals(4, DigitalRoot.digitalRoot(4));
|
||||
assertEquals(9, DigitalRoot.digitalRoot(9));
|
||||
assertEquals(4, DigitalRoot.digitalRoot(49));
|
||||
assertEquals(6, DigitalRoot.digitalRoot(78));
|
||||
assertEquals(4, DigitalRoot.digitalRoot(1228));
|
||||
assertEquals(5, DigitalRoot.digitalRoot(71348));
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user