mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +08:00
Added HappyNumber algorithm in maths section (#6571)
* Added HappyNumber algorithm in maths section * Fix Checkstyle: remove trailing spaces in HappyNumber * Fix formatting: remove trailing spaces and apply clang-format * Update HappyNumberTest.java * Removed old HappyNumbersSeq.java as replaced by new HappyNumber.java
This commit is contained in:
32
src/test/java/com/thealgorithms/maths/HappyNumberTest.java
Normal file
32
src/test/java/com/thealgorithms/maths/HappyNumberTest.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package com.thealgorithms.maths;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class HappyNumberTest {
|
||||
|
||||
@Test
|
||||
void testHappyNumbers() {
|
||||
// Known happy numbers
|
||||
assertTrue(HappyNumber.isHappy(1));
|
||||
assertTrue(HappyNumber.isHappy(7));
|
||||
assertTrue(HappyNumber.isHappy(19));
|
||||
assertTrue(HappyNumber.isHappy(100));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUnhappyNumbers() {
|
||||
// Known unhappy numbers
|
||||
assertFalse(HappyNumber.isHappy(2));
|
||||
assertFalse(HappyNumber.isHappy(4));
|
||||
assertFalse(HappyNumber.isHappy(20));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLargeNumber() {
|
||||
// Just to check behavior with larger input
|
||||
assertTrue(HappyNumber.isHappy(1000000)); // reduces to 1 eventually
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user