1 /*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 4347132 4939441
27 * @summary Tests for {Math, StrictMath}.cbrt
28 * @author Joseph D. Darcy
29 * @key randomness
30 */
31
32 public class CubeRootTests {
33 private CubeRootTests(){}
34
35 static final double infinityD = Double.POSITIVE_INFINITY;
36 static final double NaNd = Double.NaN;
37
38 // Initialize shared random number generator
39 static java.util.Random rand = new java.util.Random();
40
41 static int testCubeRootCase(double input, double expected) {
42 int failures=0;
43
44 double minus_input = -input;
45 double minus_expected = -expected;
46
47 failures+=Tests.test("Math.cbrt(double)", input,
48 Math.cbrt(input), expected);
49 failures+=Tests.test("Math.cbrt(double)", minus_input,
50 Math.cbrt(minus_input), minus_expected);
51 failures+=Tests.test("StrictMath.cbrt(double)", input,
52 StrictMath.cbrt(input), expected);
53 failures+=Tests.test("StrictMath.cbrt(double)", minus_input,
54 StrictMath.cbrt(minus_input), minus_expected);
55
56 return failures;
57 }
58
59 static int testCubeRoot() {
|
1 /*
2 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @library /lib/testlibrary/
27 * @build jdk.testlibrary.*
28 * @run main CubeRootTests
29 * @bug 4347132 4939441 8078672
30 * @summary Tests for {Math, StrictMath}.cbrt (use -Dseed=X to set PRNG seed)
31 * @author Joseph D. Darcy
32 * @key randomness
33 */
34
35 public class CubeRootTests {
36 private CubeRootTests(){}
37
38 static final double infinityD = Double.POSITIVE_INFINITY;
39 static final double NaNd = Double.NaN;
40
41 // Initialize shared random number generator
42 static java.util.Random rand = RandomFactory.getRandom();
43
44 static int testCubeRootCase(double input, double expected) {
45 int failures=0;
46
47 double minus_input = -input;
48 double minus_expected = -expected;
49
50 failures+=Tests.test("Math.cbrt(double)", input,
51 Math.cbrt(input), expected);
52 failures+=Tests.test("Math.cbrt(double)", minus_input,
53 Math.cbrt(minus_input), minus_expected);
54 failures+=Tests.test("StrictMath.cbrt(double)", input,
55 StrictMath.cbrt(input), expected);
56 failures+=Tests.test("StrictMath.cbrt(double)", minus_input,
57 StrictMath.cbrt(minus_input), minus_expected);
58
59 return failures;
60 }
61
62 static int testCubeRoot() {
|