Martin@439: /** Martin@439: * Back 2 Browser Bytecode Translator Martin@439: * Copyright (C) 2012 Jaroslav Tulach Martin@439: * Martin@439: * This program is free software: you can redistribute it and/or modify Martin@439: * it under the terms of the GNU General Public License as published by Martin@439: * the Free Software Foundation, version 2 of the License. Martin@439: * Martin@439: * This program is distributed in the hope that it will be useful, Martin@439: * but WITHOUT ANY WARRANTY; without even the implied warranty of Martin@439: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Martin@439: * GNU General Public License for more details. Martin@439: * Martin@439: * You should have received a copy of the GNU General Public License Martin@439: * along with this program. Look for COPYING file in the top folder. Martin@439: * If not, see http://opensource.org/licenses/GPL-2.0. Martin@439: */ Martin@439: package org.apidesign.bck2brwsr.tck; Martin@439: Martin@439: import org.apidesign.bck2brwsr.vmtest.Compare; Martin@439: import org.apidesign.bck2brwsr.vmtest.VMTest; Martin@439: import org.testng.annotations.Factory; Martin@439: Martin@439: /** Martin@439: * Martin@439: * @author Jaroslav Tulach Martin@439: */ Martin@439: public class ShortArithmeticTest { Martin@439: Martin@439: private static short add(short x, short y) { Martin@439: return (short)(x + y); Martin@439: } Martin@439: Martin@439: private static short sub(short x, short y) { Martin@439: return (short)(x - y); Martin@439: } Martin@439: Martin@439: private static short mul(short x, short y) { Martin@439: return (short)(x * y); Martin@439: } Martin@439: Martin@439: private static short div(short x, short y) { Martin@439: return (short)(x / y); Martin@439: } Martin@439: Martin@439: private static short mod(short x, short y) { Martin@439: return (short)(x % y); Martin@439: } Martin@439: Martin@439: @Compare public short conversion() { Martin@439: return (short)123456; Martin@439: } Martin@439: Martin@439: @Compare public short addOverflow() { Martin@439: return add(Short.MAX_VALUE, (short)1); Martin@439: } Martin@439: Martin@439: @Compare public short subUnderflow() { Martin@439: return sub(Short.MIN_VALUE, (short)1); Martin@439: } Martin@439: Martin@439: @Compare public short addMaxShortAndMaxShort() { Martin@439: return add(Short.MAX_VALUE, Short.MAX_VALUE); Martin@439: } Martin@439: Martin@439: @Compare public short subMinShortAndMinShort() { Martin@439: return sub(Short.MIN_VALUE, Short.MIN_VALUE); Martin@439: } Martin@439: Martin@439: @Compare public short multiplyMaxShort() { Martin@439: return mul(Short.MAX_VALUE, (short)2); Martin@439: } Martin@439: Martin@439: @Compare public short multiplyMaxShortAndMaxShort() { Martin@439: return mul(Short.MAX_VALUE, Short.MAX_VALUE); Martin@439: } Martin@439: Martin@439: @Compare public short multiplyMinShort() { Martin@439: return mul(Short.MIN_VALUE, (short)2); Martin@439: } Martin@439: Martin@439: @Compare public short multiplyMinShortAndMinShort() { Martin@439: return mul(Short.MIN_VALUE, Short.MIN_VALUE); Martin@439: } Martin@439: Martin@439: @Compare public short multiplyPrecision() { Martin@439: return mul((short)17638, (short)1103); Martin@439: } Martin@439: Martin@439: @Compare public short division() { Martin@439: return div((short)1, (short)2); Martin@439: } Martin@439: Martin@439: @Compare public short divisionReminder() { Martin@439: return mod((short)1, (short)2); Martin@439: } Martin@439: Martin@439: @Factory Martin@439: public static Object[] create() { Martin@439: return VMTest.create(ShortArithmeticTest.class); Martin@439: } Martin@439: }