mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 14:34:05 +08:00
Add AutomorphicNumber (#3735)
This commit is contained in:

committed by
GitHub

parent
dfe733f777
commit
37db41fd6b
@ -1,16 +1,25 @@
|
||||
package com.thealgorithms.maths;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class AutomorphicNumberTest {
|
||||
|
||||
@Test
|
||||
void testAutomorphicNumber() {
|
||||
assertThat(AutomorphicNumber.isAutomorphic(625)).isTrue();
|
||||
assertThat(AutomorphicNumber.isAutomorphic(144)).isFalse();
|
||||
assertThat(AutomorphicNumber.isAutomorphic(9376)).isTrue();
|
||||
assertThat(AutomorphicNumber.isAutomorphic(169)).isFalse();
|
||||
int trueTestCases[] = { 0, 1, 25, 625, 12890625};
|
||||
int falseTestCases[] = { -5, 2, 26, 1234 };
|
||||
for (Integer n : trueTestCases) {
|
||||
assertTrue(AutomorphicNumber.isAutomorphic(n));
|
||||
assertTrue(AutomorphicNumber.isAutomorphic2(n));
|
||||
assertTrue(AutomorphicNumber.isAutomorphic3(String.valueOf(n)));
|
||||
}
|
||||
for (Integer n : falseTestCases) {
|
||||
assertFalse(AutomorphicNumber.isAutomorphic(n));
|
||||
assertFalse(AutomorphicNumber.isAutomorphic2(n));
|
||||
assertFalse(AutomorphicNumber.isAutomorphic3(String.valueOf(n)));
|
||||
}
|
||||
assertTrue(AutomorphicNumber.isAutomorphic3("59918212890625")); // Special case for BigInteger
|
||||
assertFalse(AutomorphicNumber.isAutomorphic3("12345678912345")); // Special case for BigInteger
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user