Skip to content

Commit da265bc

Browse files
committed
Add a few simple test cases for Math.sqrt(..).
These should at least detect incorrect target options (e.g. when the VM is built with hardware SQRT support on a platform that does have it). One example of a processor without hardware SQRT support is the Freescale e500mc.
1 parent 1a0f54c commit da265bc

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

testing/tests/basic/src/test/org/jikesrvm/basic/java/lang/TestMath.expected

+7
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,10 @@ Math.ceil(-Infinity) Expected: -Infinity Actual: -Infinity
2424
Math.ceil(Infinity) Expected: Infinity Actual: Infinity
2525
Math.ceil(0.0) Expected: 0.0 Actual: 0.0
2626
Math.ceil(0.0) Expected: 0.0 Actual: 0.0
27+
Math.sqrt(4.0) Expected: 2.0 Actual: 2.0
28+
Math.sqrt(Infinity) Expected: Infinity Actual: Infinity
29+
Math.sqrt(NaN) Expected: NaN Actual: NaN
30+
Math.sqrt(-Infinity) Expected: NaN Actual: NaN
31+
Math.sqrt(-1.0) Expected: NaN Actual: NaN
32+
Math.sqrt(-0.0) Expected: -0.0 Actual: -0.0
33+
Math.sqrt(0.0) Expected: 0.0 Actual: 0.0

testing/tests/basic/src/test/org/jikesrvm/basic/java/lang/TestMath.java

+13
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ public static void main(String[] args) {
4747
runCeilTest(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
4848
runCeilTest(-0, -0);
4949
runCeilTest(0, 0);
50+
51+
runSQRTTest(4d, 2d);
52+
53+
runSQRTTest(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
54+
runSQRTTest(Double.NaN, Double.NaN);
55+
runSQRTTest(Double.NEGATIVE_INFINITY, Double.NaN);
56+
runSQRTTest(-1d, Double.NaN);
57+
runSQRTTest(-0.0d, -0.0d);
58+
runSQRTTest(0.0d, 0.0d);
5059
}
5160

5261
private static void runCeilTest(final double value, final double expected) {
@@ -56,4 +65,8 @@ private static void runCeilTest(final double value, final double expected) {
5665
private static void runFloorTest(final double value, final double expected) {
5766
System.out.println("Math.floor(" + value + ") Expected: " + expected + " Actual: " + Math.floor(value));
5867
}
68+
69+
private static void runSQRTTest(final double value, final double expected) {
70+
System.out.println("Math.sqrt(" + value + ") Expected: " + expected + " Actual: " + Math.sqrt(value));
71+
}
5972
}

0 commit comments

Comments
 (0)