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