1 /* 2 * Copyright (c) 2014, 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.replacements.test; 24 25 import org.junit.Test; 26 27 import org.graalvm.compiler.core.common.calc.UnsignedMath; 28 import org.graalvm.compiler.core.test.GraalCompilerTest; 29 30 /** 31 * Tests the substitutions for the {@link UnsignedMath} class. 32 */ 33 public class UnsignedMathTest extends GraalCompilerTest { 34 35 public static boolean aboveThanInt(int a, int b) { 36 return UnsignedMath.aboveThan(a, b); 37 } 38 39 public static boolean aboveOrEqualInt(int a, int b) { 40 return UnsignedMath.aboveOrEqual(a, b); 41 } 42 43 public static boolean belowThanInt(int a, int b) { 44 return UnsignedMath.belowThan(a, b); 45 } 46 47 public static boolean belowOrEqualInt(int a, int b) { 48 return UnsignedMath.belowOrEqual(a, b); 49 } 50 51 public static int divideInt(int a, int b) { 52 return Integer.divideUnsigned(a, b); 53 } 54 55 public static int remainderInt(int a, int b) { 56 return Integer.remainderUnsigned(a, b); 57 } 58 59 public static boolean aboveThanLong(long a, long b) { 60 return UnsignedMath.aboveThan(a, b); 61 } 62 63 public static boolean aboveOrEqualLong(long a, long b) { 64 return UnsignedMath.aboveOrEqual(a, b); 65 } 66 67 public static boolean belowThanLong(long a, long b) { 68 return UnsignedMath.belowThan(a, b); 69 } 70 71 public static boolean belowOrEqualLong(long a, long b) { 72 return UnsignedMath.belowOrEqual(a, b); 73 } 74 75 public static long divideLong(long a, long b) { 76 return Long.divideUnsigned(a, b); 77 } 78 79 public static long remainderLong(long a, long b) { 80 return Long.remainderUnsigned(a, b); 81 } 82 83 private void testInt(int a, int b) { 84 test("aboveThanInt", a, b); 85 test("aboveOrEqualInt", a, b); 86 test("belowThanInt", a, b); 87 test("belowOrEqualInt", a, b); 88 test("divideInt", a, b); 89 test("remainderInt", a, b); 90 } 91 92 private void testLong(long a, long b) { 93 test("aboveThanLong", a, b); 94 test("aboveOrEqualLong", a, b); 95 test("belowThanLong", a, b); 96 test("belowOrEqualLong", a, b); 97 test("divideLong", a, b); 98 test("remainderLong", a, b); 99 } 100 101 @Test 102 public void testInt() { 103 testInt(5, 7); 104 testInt(-3, -7); 105 testInt(-3, 7); 106 testInt(42, -5); 107 } 108 109 @Test 110 public void testLong() { 111 testLong(5, 7); 112 testLong(-3, -7); 113 testLong(-3, 7); 114 testLong(42, -5); 115 } 116 }