Determine if an Integer's Square Root Is an Integer in Java Article by Abdallah Sawan

This commit is contained in:
AbdallahSawan 2020-12-12 00:44:55 +02:00
parent 6526ccbf35
commit 18727de7c5
1 changed files with 5 additions and 6 deletions

View File

@ -6,22 +6,21 @@ import static org.junit.Assert.assertEquals;
public class PerfectSquareUnitTest {
@Test
public void test0xFFAssignedToInteger() {
public void testIsNumberPerfectSquare() {
long n = 18676209273604L; // 18676209273604 = 43621598 * 43621598
boolean expectedValue = true;
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingSqrt(n));
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingBinarySearch(1, Integer.MAX_VALUE, n));
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingNewtonMethod(n));
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareWithOptimization(n));
}
@Test
public void test0xFFAssignedToByte() {
long n = 549790047707L; // prime number
boolean expectedValue = false;
n = 549790047707L; // prime number
expectedValue = false;
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingSqrt(n));
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingBinarySearch(1, Integer.MAX_VALUE, n));
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingNewtonMethod(n));
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareWithOptimization(n));
}
}