1 /* 2 * Copyright (c) 2015, 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 package org.graalvm.compiler.jtt.lang; 24 25 import org.junit.Test; 26 27 import org.graalvm.compiler.jtt.JTTTest; 28 29 /* 30 */ 31 public class Math_exact extends JTTTest { 32 33 public static int testIntAddExact(int a, int b) { 34 return Math.addExact(a, b); 35 } 36 37 @Test 38 public void runTestIntAddExact() throws Throwable { 39 runTest("testIntAddExact", 1, 2); 40 runTest("testIntAddExact", 1, Integer.MAX_VALUE); 41 runTest("testIntAddExact", -1, Integer.MIN_VALUE); 42 } 43 44 public static long testLongAddExact(long a, long b) { 45 return Math.addExact(a, b); 46 } 47 48 @Test 49 public void runTestLongAddExact() throws Throwable { 50 runTest("testLongAddExact", 1L, 2L); 51 runTest("testLongAddExact", 1L, Long.MAX_VALUE); 52 runTest("testLongAddExact", -1L, Long.MIN_VALUE); 53 } 54 55 public static int testIntSubExact(int a, int b) { 56 return Math.subtractExact(a, b); 57 } 58 59 @Test 60 public void runTestIntSubExact() throws Throwable { 61 runTest("testIntSubExact", 1, 2); 62 runTest("testIntSubExact", -2, Integer.MAX_VALUE); 63 runTest("testIntSubExact", 2, Integer.MIN_VALUE); 64 } 65 66 public static long testLongSubExact(long a, long b) { 67 return Math.subtractExact(a, b); 68 } 69 70 @Test 71 public void runTestLongSubExact() throws Throwable { 72 runTest("testLongSubExact", 1L, 2L); 73 runTest("testLongSubExact", -2L, Long.MAX_VALUE); 74 runTest("testLongSubExact", 2L, Long.MIN_VALUE); 75 } 76 77 public static int testIntMulExact(int a, int b) { 78 return Math.multiplyExact(a, b); 79 } 80 81 @Test 82 public void runTestIntMulExact() throws Throwable { 83 runTest("testIntMulExact", 1, 2); 84 runTest("testIntMulExact", -2, Integer.MAX_VALUE); 85 runTest("testIntMulExact", 2, Integer.MIN_VALUE); 86 } 87 88 public static long testLongMulExact(long a, long b) { 89 return Math.multiplyExact(a, b); 90 } 91 92 @Test 93 public void runTestLongMulExact() throws Throwable { 94 runTest("testLongMulExact", 1L, 2L); 95 runTest("testLongMulExact", 2L, Long.MAX_VALUE); 96 runTest("testLongMulExact", -2L, Long.MIN_VALUE); 97 } 98 }