test/java/lang/Math/Tests.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2003, 2011 Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 336,341 **** --- 336,361 ---- return 0; } else return 0; } + + // For a successful test, the result must be within the upper and + // lower bounds. + public static int testBounds(String testName, double input, double result, + double bound1, double bound2) { + if ((result >= bound1 && result <= bound2) || + (result <= bound1 && result >= bound2)) + return 0; + else { + double lowerBound = Math.min(bound1, bound2); + double upperBound = Math.max(bound1, bound2); + System.err.println("Failure for " + testName + ":\n" + + "\tFor input " + input + "\t(" + toHexString(input) + ")\n" + + "\tgot " + result + "\t(" + toHexString(result) + ");\n" + + "\toutside of range\n" + + "\t[" + lowerBound + "\t(" + toHexString(lowerBound) + "), " + + upperBound + "\t(" + toHexString(upperBound) + ")]"); + return 1; + } + } }