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

This commit is contained in:
AbdallahSawan 2020-11-22 13:22:45 +02:00
parent 6e54323282
commit 6526ccbf35
2 changed files with 3 additions and 3 deletions

View File

@ -35,7 +35,7 @@ public class PerfectSquareUtil {
return x1 == x2 && n % x1 == 0L;
}
public static boolean isSquareNumberWithOptimization(long n) {
public static boolean isPerfectSquareWithOptimization(long n) {
if (n < 0)
return false;
switch ((int) (n & 0xF)) {

View File

@ -12,7 +12,7 @@ public class PerfectSquareUnitTest {
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingSqrt(n));
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingBinarySearch(1, Integer.MAX_VALUE, n));
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingNewtonMethod(n));
assertEquals(expectedValue, PerfectSquareUtil.isSquareNumberWithOptimization(n));
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareWithOptimization(n));
}
@Test
@ -22,6 +22,6 @@ public class PerfectSquareUnitTest {
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingSqrt(n));
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingBinarySearch(1, Integer.MAX_VALUE, n));
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingNewtonMethod(n));
assertEquals(expectedValue, PerfectSquareUtil.isSquareNumberWithOptimization(n));
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareWithOptimization(n));
}
}