001/* 002 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. 008 * 009 * This code is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 012 * version 2 for more details (a copy is included in the LICENSE file that 013 * accompanied this code). 014 * 015 * You should have received a copy of the GNU General Public License version 016 * 2 along with this work; if not, write to the Free Software Foundation, 017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 018 * 019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 020 * or visit www.oracle.com if you need additional information or have any 021 * questions. 022 */ 023package com.oracle.graal.jtt.lang; 024 025import org.junit.*; 026 027import com.oracle.graal.jtt.*; 028 029/* 030 */ 031public class Math_exact extends JTTTest { 032 033 public static int testIntAddExact(int a, int b) { 034 return Math.addExact(a, b); 035 } 036 037 @Test 038 public void runTestIntAddExact() throws Throwable { 039 runTest("testIntAddExact", 1, 2); 040 runTest("testIntAddExact", 1, Integer.MAX_VALUE); 041 runTest("testIntAddExact", -1, Integer.MIN_VALUE); 042 } 043 044 public static long testLongAddExact(long a, long b) { 045 return Math.addExact(a, b); 046 } 047 048 @Test 049 public void runTestLongAddExact() throws Throwable { 050 runTest("testLongAddExact", 1L, 2L); 051 runTest("testLongAddExact", 1L, Long.MAX_VALUE); 052 runTest("testLongAddExact", -1L, Long.MIN_VALUE); 053 } 054 055 public static int testIntSubExact(int a, int b) { 056 return Math.subtractExact(a, b); 057 } 058 059 @Test 060 public void runTestIntSubExact() throws Throwable { 061 runTest("testIntSubExact", 1, 2); 062 runTest("testIntSubExact", -2, Integer.MAX_VALUE); 063 runTest("testIntSubExact", 2, Integer.MIN_VALUE); 064 } 065 066 public static long testLongSubExact(long a, long b) { 067 return Math.subtractExact(a, b); 068 } 069 070 @Test 071 public void runTestLongSubExact() throws Throwable { 072 runTest("testLongSubExact", 1L, 2L); 073 runTest("testLongSubExact", -2L, Long.MAX_VALUE); 074 runTest("testLongSubExact", 2L, Long.MIN_VALUE); 075 } 076 077 public static int testIntMulExact(int a, int b) { 078 return Math.multiplyExact(a, b); 079 } 080 081 @Test 082 public void runTestIntMulExact() throws Throwable { 083 runTest("testIntMulExact", 1, 2); 084 runTest("testIntMulExact", -2, Integer.MAX_VALUE); 085 runTest("testIntMulExact", 2, Integer.MIN_VALUE); 086 } 087 088 public static long testLongMulExact(long a, long b) { 089 return Math.multiplyExact(a, b); 090 } 091 092 @Test 093 public void runTestLongMulExact() throws Throwable { 094 runTest("testLongMulExact", 1L, 2L); 095 runTest("testLongMulExact", 2L, Long.MAX_VALUE); 096 runTest("testLongMulExact", -2L, Long.MIN_VALUE); 097 } 098}