Add Tests for DigitalRoot Algorithm (#3186)

This commit is contained in:
Ankush Banik 2022-07-12 11:59:49 +05:30 committed by GitHub
parent 199c85d191
commit b2f6827c36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View File

@ -60,12 +60,6 @@ class DigitalRoot {
} // n / 10 is the number obtainded after removing the digit one by one } // 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 // 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
}
} }
/** /**

View 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));
}
}