< prev index next >

test/jdk/java/lang/Math/ExactArithTests.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2012, 2016, 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) 2012, 2019, 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.
*** 54,65 **** errors++; System.err.println(message); } /** ! * Test Math.addExact, multiplyExact, subtractExact, toIntValue methods ! * with {@code int} arguments. */ static void testIntegerExact() { testIntegerExact(0, 0); testIntegerExact(1, 1); testIntegerExact(1, -1); --- 54,65 ---- errors++; System.err.println(message); } /** ! * Test Math.addExact, multiplyExact, subtractExact, incrementExact, ! * decrementExact, negateExact methods with {@code int} arguments. */ static void testIntegerExact() { testIntegerExact(0, 0); testIntegerExact(1, 1); testIntegerExact(1, -1);
*** 74,84 **** testIntegerExact(Integer.MAX_VALUE, 2); testIntegerExact(Integer.MIN_VALUE, -1); testIntegerExact(Integer.MAX_VALUE, -1); testIntegerExact(Integer.MIN_VALUE, -2); testIntegerExact(Integer.MAX_VALUE, -2); - } /** * Test exact arithmetic by comparing with the same operations using long * and checking that the result is the same as the integer truncation. --- 74,83 ----
*** 99,109 **** } } catch (ArithmeticException ex) { long sum2 = (long) x + (long) y; if ((int) sum2 == sum2) { fail("FAIL: int Math.addExact(" + x + " + " + y + ")" + "; Unexpected exception: " + ex); - } } try { // Test subtractExact --- 98,107 ----
*** 145,155 **** } } catch (ArithmeticException ex) { long inc2 = (long) x + 1L; if ((int) inc2 == inc2) { fail("FAIL: int Math.incrementExact(" + x + ")" + "; Unexpected exception: " + ex); - } } try { // Test decrementExact --- 143,152 ----
*** 162,172 **** } } catch (ArithmeticException ex) { long dec2 = (long) x - 1L; if ((int) dec2 == dec2) { fail("FAIL: int Math.decrementExact(" + x + ")" + "; Unexpected exception: " + ex); - } } try { // Test negateExact --- 159,168 ----
*** 179,196 **** } } catch (ArithmeticException ex) { long neg2 = (long) x - 1L; if ((int) neg2 == neg2) { fail("FAIL: int Math.negateExact(" + x + ")" + "; Unexpected exception: " + ex); - } } } /** ! * Test Math.addExact, multiplyExact, subtractExact, toIntExact methods ! * with {@code long} arguments. */ static void testLongExact() { testLongExactTwice(0, 0); testLongExactTwice(1, 1); testLongExactTwice(1, -1); --- 175,191 ---- } } catch (ArithmeticException ex) { long neg2 = (long) x - 1L; if ((int) neg2 == neg2) { fail("FAIL: int Math.negateExact(" + x + ")" + "; Unexpected exception: " + ex); } } } /** ! * Test Math.addExact, multiplyExact, subtractExact, incrementExact, ! * decrementExact, negateExact, toIntExact methods with {@code long} arguments. */ static void testLongExact() { testLongExactTwice(0, 0); testLongExactTwice(1, 1); testLongExactTwice(1, -1);
*** 213,223 **** testLongExactTwice(Integer.MAX_VALUE+1, Integer.MAX_VALUE+1); testLongExactTwice(Integer.MAX_VALUE+1, -Integer.MAX_VALUE+1); testLongExactTwice(Integer.MIN_VALUE-1, Integer.MIN_VALUE-1); testLongExactTwice(Integer.MIN_VALUE-1, -Integer.MIN_VALUE-1); testLongExactTwice(Integer.MIN_VALUE/2, 2); - } /** * Test each of the exact operations with the arguments and * with the arguments reversed. --- 208,217 ----
*** 317,327 **** } catch (ArithmeticException ex) { if (resultBig.bitLength() <= 32) { fail("FAIL: long Math.toIntExact(" + x + ")" + "; Unexpected exception: " + ex); } } - } /** * Compare the expected and actual results. * @param message message for the error --- 311,320 ----
< prev index next >