Merge pull request #10312 from abdallahsawan/BAEL-4696
Determine if an Integer's Square Root Is an Integer in Java Article b…
This commit is contained in:
commit
a3fdd3e92b
|
@ -6,22 +6,21 @@ import static org.junit.Assert.assertEquals;
|
||||||
public class PerfectSquareUnitTest {
|
public class PerfectSquareUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test0xFFAssignedToInteger() {
|
public void testIsNumberPerfectSquare() {
|
||||||
long n = 18676209273604L; // 18676209273604 = 43621598 * 43621598
|
long n = 18676209273604L; // 18676209273604 = 43621598 * 43621598
|
||||||
boolean expectedValue = true;
|
boolean expectedValue = true;
|
||||||
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingSqrt(n));
|
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingSqrt(n));
|
||||||
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingBinarySearch(1, Integer.MAX_VALUE, n));
|
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingBinarySearch(1, Integer.MAX_VALUE, n));
|
||||||
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingNewtonMethod(n));
|
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingNewtonMethod(n));
|
||||||
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareWithOptimization(n));
|
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareWithOptimization(n));
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
n = 549790047707L; // prime number
|
||||||
public void test0xFFAssignedToByte() {
|
expectedValue = false;
|
||||||
long n = 549790047707L; // prime number
|
|
||||||
boolean expectedValue = false;
|
|
||||||
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingSqrt(n));
|
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingSqrt(n));
|
||||||
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingBinarySearch(1, Integer.MAX_VALUE, n));
|
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingBinarySearch(1, Integer.MAX_VALUE, n));
|
||||||
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingNewtonMethod(n));
|
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareByUsingNewtonMethod(n));
|
||||||
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareWithOptimization(n));
|
assertEquals(expectedValue, PerfectSquareUtil.isPerfectSquareWithOptimization(n));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue